private void Stamp( Document document ) { // 1. Instantiate the stamper! /* NOTE: The PageStamper is optimized for dealing with pages. */ PageStamper stamper = new PageStamper(); // 2. Numbering each page... StandardType1Font font = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); DeviceRGBColor redColor = DeviceRGBColor.Get(SKColors.Red); int margin = 32; foreach (Page page in document.Pages) { // 2.1. Associate the page to the stamper! stamper.Page = page; // 2.2. Stamping the page number on the foreground... { PrimitiveComposer foreground = stamper.Foreground; foreground.SetFont(font, 16); foreground.SetFillColor(redColor); SKSize pageSize = page.Size; int pageNumber = page.Number; bool pageIsEven = (pageNumber % 2 == 0); foreground.ShowText( pageNumber.ToString(), new SKPoint( (pageIsEven ? margin : pageSize.Width - margin), pageSize.Height - margin ), (pageIsEven ? XAlignmentEnum.Left : XAlignmentEnum.Right), YAlignmentEnum.Bottom, 0 ); } // 2.3. End the stamping! stamper.Flush(); } }
public DanfeService(DanfeViewModel viewModel) { ViewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel)); Blocos = new List <BlocoBase>(); _file = new File(); PdfDocument = _file.Document; // De acordo com o item 7.7, a fonte deve ser Times New Roman ou Courier New. var fonteFamilia = StandardType1Font.FamilyEnum.Times; _fonteRegular = new StandardType1Font(PdfDocument, fonteFamilia, false, false); _fonteNegrito = new StandardType1Font(PdfDocument, fonteFamilia, true, false); _fonteItalico = new StandardType1Font(PdfDocument, fonteFamilia, false, true); EstiloPadrao = CriarEstilo(); Paginas = new List <DanfePagina>(); Canhoto = CriarBloco <BlocoCanhoto>(); _identificacaoEmitente = AdicionarBloco <BlocoIdentificacaoEmitente>(); AdicionarBloco <BlocoDestinatarioRemetente>(); if (ViewModel.LocalRetirada != null && ViewModel.ExibirBlocoLocalRetirada) { AdicionarBloco <BlocoLocalRetirada>(); } if (ViewModel.LocalEntrega != null && ViewModel.ExibirBlocoLocalEntrega) { AdicionarBloco <BlocoLocalEntrega>(); } if (ViewModel.Duplicatas.Count > 0) { AdicionarBloco <BlocoDuplicataFatura>(); } AdicionarBloco <BlocoCalculoImposto>(ViewModel.Orientacao == Orientacao.Paisagem ? EstiloPadrao : CriarEstilo(4.75F)); AdicionarBloco <BlocoTransportador>(); AdicionarBloco <BlocoDadosAdicionais>(CriarEstilo(tFonteCampoConteudo: 8)); if (ViewModel.CalculoIssqn.Mostrar) { AdicionarBloco <BlocoCalculoIssqn>(); } AdicionarMetadata(); _FoiGerado = false; }
private void Populate( Document document ) { Page page = new Page(document); document.Pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Hyphenation = true; blockComposer.Begin( new RectangleF( Margin, Margin, (float)pageSize.Width - Margin * 2, (float)pageSize.Height - Margin * 2 ), XAlignmentEnum.Justify, YAlignmentEnum.Top ); StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(bodyFont, 32); blockComposer.ShowText("Inline image sample"); blockComposer.ShowBreak(); composer.SetFont(bodyFont, 16); blockComposer.ShowText("Showing the GNU logo as an inline image within the page content stream."); blockComposer.End(); } // Showing the 'GNU' image... { // Instantiate a jpeg image object! entities::Image image = entities::Image.Get(GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg")); // Abstract image (entity). // Set the position of the image in the page! composer.ApplyMatrix(200, 0, 0, 200, (pageSize.Width - 200) / 2, (pageSize.Height - 200) / 2); // Show the image! image.ToInlineObject(composer); // Transforms the image entity into an inline image within the page. } composer.Flush(); }
private void Populate( Document document ) { StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); Pages pages = document.Pages; PageFormat.SizeEnum[] pageFormats = (PageFormat.SizeEnum[])Enum.GetValues(typeof(PageFormat.SizeEnum)); PageFormat.OrientationEnum[] pageOrientations = (PageFormat.OrientationEnum[])Enum.GetValues(typeof(PageFormat.OrientationEnum)); foreach (PageFormat.SizeEnum pageFormat in pageFormats) { foreach (PageFormat.OrientationEnum pageOrientation in pageOrientations) { // Add a page to the document! Page page = new Page( document, PageFormat.GetSize( pageFormat, pageOrientation ) ); // Instantiates the page inside the document context. pages.Add(page); // Puts the page in the pages collection. // Drawing the text label on the page... SKSize pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); composer.SetFont(bodyFont, 32); composer.ShowText( pageFormat + " (" + pageOrientation + ")", // Text. new SKPoint( pageSize.Width / 2, pageSize.Height / 2 ), // Location: page center. XAlignmentEnum.Center, // Places the text on horizontal center of the location. YAlignmentEnum.Middle, // Places the text on vertical middle of the location. 45 // Rotates the text 45 degrees counterclockwise. ); composer.Flush(); } } }
public DanfeDocumento(DanfeViewModel model, float margem) { Margem = margem; _File = new org.pdfclown.files.File(); Document = _File.Document; Model = model; Size = new SizeF(Utils.Mm2Pu(A4Tamanho.Width), Utils.Mm2Pu(A4Tamanho.Height)); Font = new StandardType1Font(Document, StandardType1Font.FamilyEnum.Times, false, false); FontBold = new StandardType1Font(Document, StandardType1Font.FamilyEnum.Times, true, false); InnerRect = new RectangleF(0, 0, Utils.Mm2Pu(A4Tamanho.Width), Utils.Mm2Pu(A4Tamanho.Height)).GetPaddedRectangleMm(5); Paginas = new List <DanfePagina>(); AdicionarMetadata(); FoiGerado = false; }
public DanfeEventoService(DanfeEventoViewModel viewModel) { ViewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel)); _file = new File(); Blocos = new List <BlocoEventoBase>(); PdfDocument = _file.Document; // De acordo com o item 7.7, a fonte deve ser Times New Roman ou Courier New. var fonteFamilia = StandardType1Font.FamilyEnum.Times; _fonteRegular = new StandardType1Font(PdfDocument, fonteFamilia, false, false); _fonteNegrito = new StandardType1Font(PdfDocument, fonteFamilia, true, false); _fonteItalico = new StandardType1Font(PdfDocument, fonteFamilia, false, true); EstiloPadrao = CriarEstilo(); EstiloPadrao.FonteBlocoCabecalho.Tamanho = 10; var estiloInformacao = CriarEstilo(tFonteCampoConteudo: 12f); estiloInformacao.FonteBlocoCabecalho.Tamanho = 10; Paginas = new List <DanfeEventoPagina>(); AdicionarBloco <BlocoEventoCabecalho>(); AdicionarBloco <BlocoEventoIdentificacao>(); AdicionarBloco <BlocoEventoDados>(); switch (viewModel.TipoEvento) { case NFeTipoEvento.CartaCorrecao: AdicionarBloco <BlocoEventoCartaCorrecaoCondicao>(); AdicionarBloco <BlocoEventoCartaCorrecao>(estiloInformacao); break; case NFeTipoEvento.Cancelamento: case NFeTipoEvento.CancelamentoST: AdicionarBloco <BlocoEventoCancelamento>(estiloInformacao); break; } AdicionarMetadata(); _FoiGerado = false; }
public Danfe(DanfeViewModel viewModel, string creditos = null, string metadataCriador = null) { _creditos = creditos ?? "Impresso com DanfeSharp"; _metadataCriador = metadataCriador ?? String.Format("{0} {1} - {2}", "DanfeSharp", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version, "https://github.com/SilverCard/DanfeSharp"); ViewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel)); _Blocos = new List <BlocoBase>(); File = new File(); PdfDocument = File.Document; // De acordo com o item 7.7, a fonte deve ser Times New Roman ou Courier New. _FonteFamilia = StandardType1Font.FamilyEnum.Times; _FonteRegular = new StandardType1Font(PdfDocument, _FonteFamilia, false, false); _FonteNegrito = new StandardType1Font(PdfDocument, _FonteFamilia, true, false); _FonteItalico = new StandardType1Font(PdfDocument, _FonteFamilia, false, true); EstiloPadrao = CriarEstilo(); Paginas = new List <DanfePagina>(); Canhoto = CriarBloco <BlocoCanhoto>(); IdentificacaoEmitente = AdicionarBloco <BlocoIdentificacaoEmitente>(); AdicionarBloco <BlocoDestinatarioRemetente>(); if (ViewModel.Duplicatas.Count > 0) { AdicionarBloco <BlocoDuplicataFatura>(); } AdicionarBloco <BlocoCalculoImposto>(ViewModel.Orientacao == Orientacao.Paisagem ? EstiloPadrao : CriarEstilo(4.75F)); AdicionarBloco <BlocoTransportador>(); AdicionarBloco <BlocoDadosAdicionais>(CriarEstilo(tFonteCampoConteudo: 8)); if (ViewModel.CalculoIssqn.Mostrar) { AdicionarBloco <BlocoCalculoIssqn>(); } AdicionarMetadata(); _FoiGerado = false; }
public DanfeNFC(DanfeViewModel viewModel, string creditos = null, string metadataCriador = null) { ViewModel = viewModel ?? throw new ArgumentNullException(nameof(viewModel)); File = new File(); PdfDocument = File.Document; if (viewModel.Produtos.Count <= 20) { _size = new SizeF(280, viewModel.Produtos.Count * 30 + 600); } else if (viewModel.Produtos.Count <= 40) { _size = new SizeF(280, viewModel.Produtos.Count * 14 + 600); } else if (viewModel.Produtos.Count <= 75) { _size = new SizeF(280, viewModel.Produtos.Count * 12 + 600); } else if (viewModel.Produtos.Count <= 150) { _size = new SizeF(280, viewModel.Produtos.Count * 11 + 600); } else if (viewModel.Produtos.Count <= 250) { _size = new SizeF(280, viewModel.Produtos.Count * 10.5F + 600); } else if (viewModel.Produtos.Count <= 400) { _size = new SizeF(280, viewModel.Produtos.Count * 10.2F + 600); } else if (viewModel.Produtos.Count <= 480) { _size = new SizeF(280, viewModel.Produtos.Count * 10.1F + 600); } else if (viewModel.Produtos.Count <= 700) { _size = new SizeF(280, viewModel.Produtos.Count * 9.8F + 600); } // 1. Add the page to the document! _page = new Page(PdfDocument, _size); // Instantiates the page inside the document context. PdfDocument.Pages.Add(_page); // Puts the page in the pages collection. // 2. Create a content composer for the page! _primitiveComposer = new PrimitiveComposer(_page); _creditos = creditos ?? "Impresso com DanfeSharp"; _metadataCriador = metadataCriador ?? String.Format("{0} {1} - {2}", "DanfeSharp", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version, "https://github.com/SilverCard/DanfeSharp"); // De acordo com o item 7.7, a fonte deve ser Times New Roman ou Courier New. _FonteFamilia = StandardType1Font.FamilyEnum.Helvetica; _FonteRegular = new StandardType1Font(PdfDocument, _FonteFamilia, false, false); _FonteNegrito = new StandardType1Font(PdfDocument, _FonteFamilia, true, false); _FonteItalico = new StandardType1Font(PdfDocument, _FonteFamilia, false, true); EstiloPadrao = CriarEstilo(); AdicionarMetadata(); _FoiGerado = false; }
private void Populate( Document document ) { Page page = new Page(document); document.Pages.Add(page); SizeF pageSize = page.Size; /* * NOTE: Default fallback behavior on text encoding mismatch is substitution with default * character; in this case, we want to force an exception to be thrown so we can explicitly * handle the issue. */ document.Configuration.EncodingFallback = EncodingFallbackEnum.Exception; PrimitiveComposer composer = new PrimitiveComposer(page); int x = Margin, y = Margin; StandardType1Font titleFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Times, true, true ); StandardType1Font font = null; // Iterating through the standard Type 1 fonts... foreach (StandardType1Font.FamilyEnum fontFamily in (StandardType1Font.FamilyEnum[])Enum.GetValues(typeof(StandardType1Font.FamilyEnum))) { // Iterating through the font styles... for (int styleIndex = 0; styleIndex < 4; styleIndex++) { /* * NOTE: Symbol and Zapf Dingbats are available just as regular fonts (no italic or bold variant). */ if (styleIndex > 0 && (fontFamily == StandardType1Font.FamilyEnum.Symbol || fontFamily == StandardType1Font.FamilyEnum.ZapfDingbats)) { break; } bool bold = (styleIndex & 1) > 0; bool italic = (styleIndex & 2) > 0; // Define the font used to show its character set! font = new StandardType1Font(document, fontFamily, bold, italic); if (y > pageSize.Height - Margin) { composer.Flush(); page = new Page(document); document.Pages.Add(page); pageSize = page.Size; composer = new PrimitiveComposer(page); x = Margin; y = Margin; } if (styleIndex == 0) { composer.DrawLine( new PointF(x, y), new PointF(pageSize.Width - Margin, y) ); composer.Stroke(); y += 5; } composer.SetFont( titleFont, FontBaseSize * (styleIndex == 0 ? 1.5f : 1) ); composer.ShowText( fontFamily.ToString() + (bold ? " bold" : "") + (italic ? " italic" : ""), new PointF(x, y) ); y += 40; // Set the font used to show its character set! composer.SetFont(font, FontBaseSize); // Iterating through the font characters... foreach (int charCode in font.CodePoints.OrderBy(codePoint => codePoint)) { if (y > pageSize.Height - Margin) { composer.Flush(); page = new Page(document); document.Pages.Add(page); pageSize = page.Size; composer = new PrimitiveComposer(page); x = Margin; y = Margin; composer.SetFont(titleFont, FontBaseSize); composer.ShowText( fontFamily.ToString() + " (continued)", new PointF(pageSize.Width - Margin, y), XAlignmentEnum.Right, YAlignmentEnum.Top, 0 ); composer.SetFont(font, FontBaseSize); y += FontBaseSize * 2; } try { // Show the character! composer.ShowText( new String((char)charCode, 1), new PointF(x, y) ); x += FontBaseSize; if (x > pageSize.Width - Margin) { x = Margin; y += 30; } } catch (EncodeException) { /* * NOOP -- NOTE: document.Configuration.EncodingFallback allows to customize the * behavior in case of missing character: we can alternatively catch an exception, have * the character substituted by a default one (typically '?' symbol) or have the * character silently excluded. */ } } x = Margin; y += Margin; } } composer.Flush(); }
/** * <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document, XObject form ) { // 1. Add a page to the document! Page page = new Page(document); // Instantiates the page inside the document context. document.Pages.Add(page); // Puts the page in the pages collection. // 2. Create a content composer for the content stream! PrimitiveComposer composer = new PrimitiveComposer(page); // 3. Inserting contents... SizeF pageSize = page.Size; // 3.1. Showing the form on the page... { SizeF formSize = form.Size; // Form 1. composer.ShowXObject( form, new PointF(pageSize.Width / 2, pageSize.Height / 2), GeomUtils.Scale(formSize, new SizeF(300, 0)), XAlignmentEnum.Center, YAlignmentEnum.Middle, 45 ); // Form 2. composer.ShowXObject( form, new PointF(0, pageSize.Height), GeomUtils.Scale(formSize, new SizeF(0, 300)), XAlignmentEnum.Left, YAlignmentEnum.Bottom, 0 ); // Form 3. composer.ShowXObject( form, new PointF(pageSize.Width, pageSize.Height), new SizeF(80, 200), XAlignmentEnum.Right, YAlignmentEnum.Bottom, 0 ); } // 3.2. Showing the comments on the page... { BlockComposer blockComposer = new BlockComposer(composer); RectangleF frame = new RectangleF( 18, 18, pageSize.Width * .5f, pageSize.Height * .5f ); blockComposer.Begin(frame, XAlignmentEnum.Justify, YAlignmentEnum.Top); StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(bodyFont, 24); blockComposer.ShowText("Page-to-form sample"); SizeF breakSize = new SizeF(0, 8); blockComposer.ShowBreak(breakSize); composer.SetFont(bodyFont, 8); blockComposer.ShowText("This sample shows how to convert a page to a reusable form that can be placed multiple times on other pages scaling, rotating, anchoring and aligning it."); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("On this page you can see some of the above-mentioned transformations:"); breakSize.Width = 8; blockComposer.ShowBreak(breakSize); blockComposer.ShowText("1. anchored to the center of the page, rotated by 45 degrees counterclockwise, 300 point wide (preserved proportions);"); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("2. anchored to the bottom-left corner of the page, 300 point high (preserved proportions);"); blockComposer.ShowBreak(breakSize); blockComposer.ShowText("3. anchored to the bottom-right of the page, 80 point wide and 200 point high (altered proportions)."); blockComposer.End(); } // 4. Flush the contents into the content stream! composer.Flush(); }
private void BuildLinks(Document document) { Pages pages = document.Pages; Page page = new Page(document); pages.Add(page); PrimitiveComposer composer = new PrimitiveComposer(page); BlockComposer blockComposer = new BlockComposer(composer); StandardType1Font font = new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false); /* * 2.1. Goto-URI link. */ { blockComposer.Begin(SKRect.Create(30, 100, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle); composer.SetFont(font, 12); blockComposer.ShowText("Go-to-URI link"); composer.SetFont(font, 8); blockComposer.ShowText("\nIt allows you to navigate to a network resource."); composer.SetFont(font, 5); blockComposer.ShowText("\n\nClick on the box to go to the project's SourceForge.net repository."); blockComposer.End(); /* * NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked. */ new Link(page, SKRect.Create(240, 100, 100, 50), "Link annotation", new GoToURI(document, new Uri("http://www.sourceforge.net/projects/clown"))) { Border = new Border(3, Border.StyleEnum.Beveled) }; } /* * 2.2. Embedded-goto link. */ { string filePath = PromptFileChoice("Please select a PDF file to attach"); /* * NOTE: These statements instruct PDF Clown to attach a PDF file to the current document. * This is necessary in order to test the embedded-goto functionality, * as you can see in the following link creation (see below). */ int fileAttachmentPageIndex = page.Index; string fileAttachmentName = "attachedSamplePDF"; string fileName = System.IO.Path.GetFileName(filePath); new FileAttachment( page, SKRect.Create(0, -20, 10, 10), "File attachment annotation", FileSpecification.Get(EmbeddedFile.Get(document, filePath), fileName ) ) { Name = fileAttachmentName, IconType = FileAttachment.IconTypeEnum.PaperClip }; blockComposer.Begin(SKRect.Create(30, 170, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle); composer.SetFont(font, 12); blockComposer.ShowText("Go-to-embedded link"); composer.SetFont(font, 8); blockComposer.ShowText("\nIt allows you to navigate to a destination within an embedded PDF file."); composer.SetFont(font, 5); blockComposer.ShowText("\n\nClick on the button to go to the 2nd page of the attached PDF file (" + fileName + ")."); blockComposer.End(); /* * NOTE: This statement instructs the PDF viewer to navigate to the page 2 of a PDF file * attached inside the current document as described by the FileAttachment annotation on page 1 of the current document. */ new Link( page, SKRect.Create(240, 170, 100, 50), "Link annotation", new GoToEmbedded( document, new GoToEmbedded.PathElement( document, fileAttachmentPageIndex, // Page of the current document containing the file attachment annotation of the target document. fileAttachmentName, // Name of the file attachment annotation corresponding to the target document. null // No sub-target. ), // Target represents the document to go to. new RemoteDestination( document, 1, // Show the page 2 of the target document. Destination.ModeEnum.Fit, // Show the target document page entirely on the screen. null, null ) // The destination must be within the target document. ) ) { Border = new Border(1, new LineDash(new double[] { 8, 5, 2, 5 })) }; } /* * 2.3. Textual link. */ { blockComposer.Begin(SKRect.Create(30, 240, 200, 50), XAlignmentEnum.Left, YAlignmentEnum.Middle); composer.SetFont(font, 12); blockComposer.ShowText("Textual link"); composer.SetFont(font, 8); blockComposer.ShowText("\nIt allows you to expose any kind of link (including the above-mentioned types) as text."); composer.SetFont(font, 5); blockComposer.ShowText("\n\nClick on the text links to go either to the project's SourceForge.net repository or to the project's home page."); blockComposer.End(); composer.BeginLocalState(); composer.SetFont(font, 10); composer.SetFillColor(DeviceRGBColor.Get(SKColors.Blue)); composer.ShowText( "PDF Clown Project's repository at SourceForge.net", new SKPoint(240, 265), XAlignmentEnum.Left, YAlignmentEnum.Middle, 0, new GoToURI( document, new Uri("http://www.sourceforge.net/projects/clown") ) ); composer.ShowText( "PDF Clown Project's home page", new SKPoint(240, 285), XAlignmentEnum.Left, YAlignmentEnum.Bottom, -90, new GoToURI( document, new Uri("http://www.pdfclown.org") ) ); composer.End(); } composer.Flush(); }
/** * <summary>Populates a PDF file with contents.</summary> */ private void Populate( Document document ) { // Get the abstract barcode entity! EAN13Barcode barcode = new EAN13Barcode("8012345678901"); // Create the reusable barcode within the document! XObject barcodeXObject = barcode.ToXObject(document); Pages pages = document.Pages; // Page 1. { Page page = new Page(document); pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); { BlockComposer blockComposer = new BlockComposer(composer); blockComposer.Hyphenation = true; blockComposer.Begin( new RectangleF( Margin, Margin, pageSize.Width - Margin * 2, pageSize.Height - Margin * 2 ), XAlignmentEnum.Left, YAlignmentEnum.Top ); StandardType1Font bodyFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(bodyFont, 32); blockComposer.ShowText("Barcode sample"); blockComposer.ShowBreak(); composer.SetFont(bodyFont, 16); blockComposer.ShowText("Showing the EAN-13 Bar Code on different compositions:"); blockComposer.ShowBreak(); blockComposer.ShowText("- page 1: on the lower right corner of the page, 100pt wide;"); blockComposer.ShowBreak(); blockComposer.ShowText("- page 2: on the middle of the page, 1/3-page wide, 25 degree counterclockwise rotated;"); blockComposer.ShowBreak(); blockComposer.ShowText("- page 3: filled page, 90 degree clockwise rotated."); blockComposer.ShowBreak(); blockComposer.End(); } // Show the barcode! composer.ShowXObject( barcodeXObject, new PointF(pageSize.Width - Margin, pageSize.Height - Margin), GeomUtils.Scale(barcodeXObject.Size, new SizeF(100, 0)), XAlignmentEnum.Right, YAlignmentEnum.Bottom, 0 ); composer.Flush(); } // Page 2. { Page page = new Page(document); pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); // Show the barcode! composer.ShowXObject( barcodeXObject, new PointF(pageSize.Width / 2, pageSize.Height / 2), GeomUtils.Scale(barcodeXObject.Size, new SizeF(pageSize.Width / 3, 0)), XAlignmentEnum.Center, YAlignmentEnum.Middle, 25 ); composer.Flush(); } // Page 3. { Page page = new Page(document); pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); // Show the barcode! composer.ShowXObject( barcodeXObject, new PointF(pageSize.Width / 2, pageSize.Height / 2), new SizeF(pageSize.Height, pageSize.Width), XAlignmentEnum.Center, YAlignmentEnum.Middle, -90 ); composer.Flush(); } }
private void Populate( Document document ) { Page page = new Page(document); document.Pages.Add(page); SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); int x = Margin, y = Margin; StandardType1Font titleFont = new StandardType1Font( document, StandardType1Font.FamilyEnum.Times, true, true ); StandardType1Font font = null; // Iterating through the standard Type 1 fonts... foreach (StandardType1Font.FamilyEnum fontFamily in (StandardType1Font.FamilyEnum[])Enum.GetValues(typeof(StandardType1Font.FamilyEnum))) { // Iterating through the font styles... for (int styleIndex = 0; styleIndex < 4; styleIndex++) { /* * NOTE: Symbol and Zapf Dingbats are available just as regular fonts (no italic or bold variant). */ if (styleIndex > 0 && (fontFamily == StandardType1Font.FamilyEnum.Symbol || fontFamily == StandardType1Font.FamilyEnum.ZapfDingbats)) { break; } bool bold, italic; switch (styleIndex) { case 0: // Regular. bold = false; italic = false; break; case 1: // Bold. bold = true; italic = false; break; case 2: // Italic. bold = false; italic = true; break; case 3: // Bold italic. bold = true; italic = true; break; default: throw new Exception("styleIndex " + styleIndex + " not supported."); } // Define the font used to show its character set! font = new StandardType1Font( document, fontFamily, bold, italic ); if (y > pageSize.Height - Margin) { composer.Flush(); page = new Page(document); document.Pages.Add(page); pageSize = page.Size; composer = new PrimitiveComposer(page); x = Margin; y = Margin; } if (styleIndex == 0) { composer.DrawLine( new PointF(x, y), new PointF(pageSize.Width - Margin, y) ); composer.Stroke(); y += 5; } composer.SetFont( titleFont, FontBaseSize * (styleIndex == 0 ? 1.5f : 1) ); composer.ShowText( fontFamily.ToString() + (bold ? " bold" : "") + (italic ? " italic" : ""), new PointF(x, y) ); y += 40; // Set the font used to show its character set! composer.SetFont(font, FontBaseSize); // Iterating through the font characters... for (int charCode = 32; charCode < 256; charCode++) { if (y > pageSize.Height - Margin) { composer.Flush(); page = new Page(document); document.Pages.Add(page); pageSize = page.Size; composer = new PrimitiveComposer(page); x = Margin; y = Margin; composer.SetFont(titleFont, FontBaseSize); composer.ShowText( fontFamily.ToString() + " (continued)", new PointF(pageSize.Width - Margin, y), XAlignmentEnum.Right, YAlignmentEnum.Top, 0 ); composer.SetFont(font, FontBaseSize); y += FontBaseSize * 2; } try { // Show the current character (using the current standard Type 1 font)! composer.ShowText( new String(new char[] { (char)charCode }), new PointF(x, y) ); x += FontBaseSize; if (x > pageSize.Width - Margin) { x = Margin; y += 30; } } catch { /* Ignore */ } } x = Margin; y += Margin; } } composer.Flush(); }
private void Populate( Document document ) { Page page = new Page(document); document.Pages.Add(page); PrimitiveComposer composer = new PrimitiveComposer(page); StandardType1Font font = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); composer.SetFont(font, 12); // Note. composer.ShowText("Note annotation:", new Point(35, 35)); annotations::Note note = new annotations::Note( page, new Point(50, 50), "Note annotation" ); note.IconType = annotations::Note.IconTypeEnum.Help; note.ModificationDate = new DateTime(); note.IsOpen = true; // Callout. composer.ShowText("Callout note annotation:", new Point(35, 85)); annotations::CalloutNote calloutNote = new annotations::CalloutNote( page, new Rectangle(50, 100, 200, 24), "Callout note annotation" ); calloutNote.Justification = JustificationEnum.Right; calloutNote.Line = new annotations::CalloutNote.LineObject( page, new Point(150, 650), new Point(100, 600), new Point(50, 100) ); // File attachment. composer.ShowText("File attachment annotation:", new Point(35, 135)); annotations::FileAttachment attachment = new annotations::FileAttachment( page, new Rectangle(50, 150, 12, 12), "File attachment annotation", FileSpecification.Get( EmbeddedFile.Get( document, GetResourcePath("images" + Path.DirectorySeparatorChar + "gnu.jpg") ), "happyGNU.jpg" ) ); attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip; composer.BeginLocalState(); // Arrow line. composer.ShowText("Line annotation:", new Point(35, 185)); composer.SetFont(font, 10); composer.ShowText("Arrow:", new Point(50, 200)); annotations::Line line = new annotations::Line( page, new Point(50, 260), new Point(200, 210), "Arrow line annotation" ); line.FillColor = new DeviceRGBColor(1, 0, 0); line.StartStyle = annotations::Line.LineEndStyleEnum.Circle; line.EndStyle = annotations::Line.LineEndStyleEnum.ClosedArrow; line.CaptionVisible = true; // Dimension line. composer.ShowText("Dimension:", new Point(300, 200)); line = new annotations::Line( page, new Point(300, 220), new Point(500, 220), "Dimension line annotation" ); line.LeaderLineLength = 20; line.LeaderLineExtensionLength = 10; line.CaptionVisible = true; composer.End(); // Scribble. composer.ShowText("Scribble annotation:", new Point(35, 285)); new annotations::Scribble( page, new RectangleF(50, 300, 100, 30), "Scribble annotation", new List <IList <PointF> >( new List <PointF>[] { new List <PointF>( new PointF[] { new PointF(50, 300), new PointF(70, 310), new PointF(100, 320) } ) } ) ); // Rectangle. composer.ShowText("Rectangle annotation:", new Point(35, 335)); annotations::Rectangle rectangle = new annotations::Rectangle( page, new Rectangle(50, 350, 100, 30), "Rectangle annotation" ); rectangle.FillColor = new DeviceRGBColor(1, 0, 0); // Ellipse. composer.ShowText("Ellipse annotation:", new Point(35, 385)); annotations::Ellipse ellipse = new annotations::Ellipse( page, new Rectangle(50, 400, 100, 30), "Ellipse annotation" ); ellipse.FillColor = new DeviceRGBColor(0, 0, 1); // Rubber stamp. composer.ShowText("Rubber stamp annotation:", new Point(35, 435)); new annotations::RubberStamp( page, new Rectangle(50, 450, 100, 30), "Rubber stamp annotation", annotations::RubberStamp.IconTypeEnum.Approved ); // Caret. composer.ShowText("Caret annotation:", new Point(35, 485)); annotations::Caret caret = new annotations::Caret( page, new Rectangle(50, 500, 100, 30), "Caret annotation" ); caret.SymbolType = annotations::Caret.SymbolTypeEnum.NewParagraph; composer.Flush(); }
/// <summary> /// Set annotation's font from <see cref="StandardType1Font"/>. /// </summary> public void SetFont(StandardType1Font font) { _da.SetFont(font); Elements.SetString(Keys.DA, _da.ToString()); }
public void SetFont(StandardType1Font font) { fontName = stdAnnotFontNames[font]; }