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(System.Drawing.Color.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); SizeF pageSize = page.Size; int pageNumber = page.Index + 1; bool pageIsEven = (pageNumber % 2 == 0); foreground.ShowText( pageNumber.ToString(), new PointF( (pageIsEven ? margin : pageSize.Width - margin), pageSize.Height - margin ), (pageIsEven ? XAlignmentEnum.Left : XAlignmentEnum.Right), YAlignmentEnum.Bottom, 0 ); } // 2.3. End the stamping! stamper.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... SizeF pageSize = page.Size; PrimitiveComposer composer = new PrimitiveComposer(page); composer.SetFont(bodyFont,32); composer.ShowText( pageFormat + " (" + pageOrientation + ")", // Text. new PointF( 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(); } } }
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(); }
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; }
private void BuildLinks( Document document ) { Pages pages = document.Pages; Page page = new Page(document); pages.Add(page); StandardType1Font font = new StandardType1Font( document, StandardType1Font.FamilyEnum.Courier, true, false ); PrimitiveComposer composer = new PrimitiveComposer(page); BlockComposer blockComposer = new BlockComposer(composer); /* 2.1. Goto-URI link. */ { blockComposer.Begin(new RectangleF(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(); try { /* NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked. */ annotations::Link link = new annotations::Link( page, new Rectangle(240,100,100,50), "Link annotation", new GoToURI( document, new Uri("http://www.sourceforge.net/projects/clown") ) ); link.Border = new annotations::Border( document, 3, annotations::Border.StyleEnum.Beveled, null ); } catch(Exception exception) {throw new Exception("",exception);} } /* 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); annotations::FileAttachment attachment = new annotations::FileAttachment( page, new Rectangle(0, -20, 10, 10), "File attachment annotation", FileSpecification.Get( EmbeddedFile.Get( document, filePath ), fileName ) ); attachment.Name = fileAttachmentName; attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip; blockComposer.Begin(new RectangleF(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. */ annotations::Link link = new annotations::Link( page, new Rectangle(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. ) ); link.Border = new annotations::Border( document, 1, annotations::Border.StyleEnum.Dashed, new LineDash(new double[]{8,5,2,5}) ); } /* 2.3. Textual link. */ { blockComposer.Begin(new RectangleF(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(); try { composer.BeginLocalState(); composer.SetFont(font,10); composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Blue)); composer.ShowText( "PDF Clown Project's repository at SourceForge.net", new PointF(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 PointF(240,285), XAlignmentEnum.Left, YAlignmentEnum.Bottom, -90, new GoToURI( document, new Uri("http://www.pdfclown.org") ) ); composer.End(); } catch {} } 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(); } }
/** <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 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); rectangle.Alpha = .25; // 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(); }