/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream verdanaFontStream, Stream verdanaBoldFontStream, Stream logoImageStream) { PDFAnsiTrueTypeFont verdana = new PDFAnsiTrueTypeFont(verdanaFontStream, 10, true); PDFAnsiTrueTypeFont verdanaBold = new PDFAnsiTrueTypeFont(verdanaBoldFontStream, 10, true); PDFPngImage logoImage = new PDFPngImage(logoImageStream); PDFFlowDocument document = new PDFFlowDocument(); PDFFlowContent header = BuildHeader(verdana, logoImage); document.AddContent(header); PDFFlowContent sellerSection = BuildSellerSection(verdana, verdanaBold); document.AddContent(sellerSection); PDFFlowContent invoiceInfoSection = BuildInvoiceInfoSection(verdana, verdanaBold); document.AddContent(invoiceInfoSection); PDFFlowContent buyerSection = BuildBuyerSection(verdana, verdanaBold); document.AddContent(buyerSection); PDFFlowContent invoiceItemsSection = BuildInvoiceItemsSection(verdana, verdanaBold); document.AddContent(invoiceItemsSection); PDFFlowContent endSection = BuildEndSection(verdana); document.AddContent(endSection); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "invoice.pdf") }; return(output); }
private static void DrawImageMasks(PDFPage page, Stream imageStream, Stream softMaskStream, Stream stencilMaskStream, PDFFont titleFont, PDFFont sectionFont) { PDFBrush brush = new PDFBrush(); page.Canvas.DrawString("Images Masks", titleFont, brush, 20, 50); page.Canvas.DrawString("Soft mask:", sectionFont, brush, 20, 70); PDFPngImage softMaskImage = new PDFPngImage(softMaskStream); PDFSoftMask softMask = new PDFSoftMask(softMaskImage); imageStream.Position = 0; PDFJpegImage softMaskJpeg = new PDFJpegImage(imageStream); softMaskJpeg.Mask = softMask; // Draw the image with a soft mask. page.Canvas.DrawImage(softMaskJpeg, 20, 90, 280, 0); page.Canvas.DrawString("Stencil mask:", sectionFont, brush, 320, 70); PDFPngImage stencilMaskImage = new PDFPngImage(stencilMaskStream); PDFStencilMask stencilMask = new PDFStencilMask(stencilMaskImage); imageStream.Position = 0; PDFJpegImage stencilMaskJpeg = new PDFJpegImage(imageStream); stencilMaskJpeg.Mask = stencilMask; // Draw the image with a stencil mask. page.Canvas.DrawImage(stencilMaskJpeg, 320, 90, 280, 0); page.Canvas.DrawString("Stencil mask painting:", sectionFont, brush, 20, 320); PDFBrush redBrush = new PDFBrush(PDFRgbColor.DarkRed); page.Canvas.DrawStencilMask(stencilMask, redBrush, 20, 340, 280, 0); PDFBrush blueBrush = new PDFBrush(PDFRgbColor.DarkBlue); page.Canvas.DrawStencilMask(stencilMask, blueBrush, 320, 340, 280, 0); PDFBrush greenBrush = new PDFBrush(PDFRgbColor.DarkGreen); page.Canvas.DrawStencilMask(stencilMask, greenBrush, 20, 550, 280, 0); PDFBrush yellowBrush = new PDFBrush(PDFRgbColor.YellowGreen); page.Canvas.DrawStencilMask(stencilMask, yellowBrush, 320, 550, 280, 0); page.Canvas.CompressAndClose(); }
/// <summary> /// Main method for running the sample. /// </summary> public static void Main(string[] args) { string supportPath = "..\\..\\..\\..\\..\\SupportFiles\\"; X509Certificate2 certificate = new X509Certificate2(supportPath + "O2SolutionsDemoCertificate.pfx", "P@ssw0rd!", X509KeyStorageFlags.Exportable); FileStream input = File.OpenRead(supportPath + "formfill.pdf"); PDFFixedDocument document = new PDFFixedDocument(input); input.Close(); // Sign the document PDFSignatureField signField = document.Form.Fields["signhere"] as PDFSignatureField; PDFCmsDigitalSignature signature = new PDFCmsDigitalSignature(); signature.SignatureDigestAlgorithm = PDFDigitalSignatureDigestAlgorithm.Sha256; signature.Certificate = certificate; signature.ContactInfo = "*****@*****.**"; signature.Location = "Cluj Napoca"; signature.Name = "O2 Solutions Support"; signature.Reason = "Simple signature"; signField.Signature = signature; // Load the signature image FileStream signatureImageStream = File.OpenRead(supportPath + "signature.png"); PDFPngImage signatureImage = new PDFPngImage(signatureImageStream); signatureImageStream.Close(); // Create the signature custom appearance PDFAnnotationAppearance aa = new PDFAnnotationAppearance(signField.Widgets[0].VisualRectangle.Width, signField.Widgets[0].VisualRectangle.Height); aa.Canvas.DrawImage(signatureImage, 0, 0, aa.Width, aa.Height); // Set the custom appearance on the signature field signField.Widgets[0].NormalAppearance = aa; using (FileStream output = File.Create("DigitalSignatureWithCustomAppearance.pdf")) { document.Save(output); } }
private static void SimpleText(PDFFixedDocument document, PDFStructureElement seParent, PDFAnsiTrueTypeFont font, Stream imageStream) { PDFAnsiTrueTypeFont headingFont = new PDFAnsiTrueTypeFont(font, 16); PDFAnsiTrueTypeFont textFont = new PDFAnsiTrueTypeFont(font, 10); PDFBrush blackBrush = new PDFBrush(PDFRgbColor.Black); PDFPen blackPen = new PDFPen(PDFRgbColor.Black, 1); PDFPage page = document.Pages.Add(); PDFStructureElement seSection = new PDFStructureElement(PDFStandardStructureTypes.Section); seSection.Title = "Simple text"; seParent.AppendChild(seSection); PDFStructureElement seHeading = new PDFStructureElement(PDFStandardStructureTypes.Heading); seSection.AppendChild(seHeading); page.Graphics.BeginStructureElement(seHeading); page.Graphics.DrawString("Page heading", headingFont, blackBrush, 30, 50); page.Graphics.EndStructureElement(); PDFStructureElement seParagraph1 = new PDFStructureElement(PDFStandardStructureTypes.Paragraph); seSection.AppendChild(seParagraph1); page.Graphics.BeginStructureElement(seParagraph1); page.Graphics.DrawString("Sample paragraph. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris in sodales ligula at lobortis.", textFont, blackBrush, 30, 70); page.Graphics.EndStructureElement(); PDFStructureElement seFigure = new PDFStructureElement(PDFStandardStructureTypes.Figure); seFigure.ActualText = "PDF4NET"; seFigure.AlternateDescription = "PDF4NET Logo"; seSection.AppendChild(seFigure); page.Graphics.BeginStructureElement(seFigure); PDFPngImage logoImage = new PDFPngImage(imageStream); page.Graphics.DrawImage(logoImage, 30, 90, 256, 128); page.Graphics.EndStructureElement(); // A structure element with 2 content items and an artifact between them. PDFStructureElement seParagraph2 = new PDFStructureElement(PDFStandardStructureTypes.Paragraph); seSection.AppendChild(seParagraph2); page.Graphics.BeginStructureElement(seParagraph2); page.Graphics.DrawString("First line of text.", textFont, blackBrush, 30, 230); page.Graphics.EndStructureElement(); page.Graphics.BeginArtifactMarkedContent(); page.Graphics.DrawLine(blackPen, 30, 242, 100, 242); page.Graphics.EndMarkedContent(); page.Graphics.BeginStructureElement(seParagraph2); page.Graphics.DrawString("Second line of text.", textFont, blackBrush, 30, 245); page.Graphics.EndStructureElement(); PDFStructureElement seParagraph3 = new PDFStructureElement(PDFStandardStructureTypes.Paragraph); seSection.AppendChild(seParagraph3); string text = "Paragraph with underlined text. The structure element is passed as parameter to DrawString method in order to properly tag graphic artifacts such as underlines. " + "Morbi pulvinar eros sit amet diam lacinia, ut feugiat ligula bibendum. Suspendisse ultrices cursus condimentum. " + "Pellentesque semper iaculis luctus. Sed ac maximus urna. Aliquam erat volutpat. Vivamus vel sollicitudin dui. Aenean efficitur " + "fringilla dui, at varius lacus luctus ac. Quisque tellus dui, lacinia non lectus nec, semper faucibus erat."; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Brush = blackBrush; sao.Font = textFont; sao.Font.Underline = true; PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.X = 30; slo.Y = 260; slo.Width = 550; page.Graphics.DrawString(text, sao, slo, seParagraph3); // A custom structure element that will be mapped to standard Pargraph structure. PDFStructureElement seSpecialParagraph = new PDFStructureElement("SpecialParagraph"); // The structure element specifies an ID that needs to be added to document's IDMap. seSpecialParagraph.ID = "specialpara"; seSection.AppendChild(seSpecialParagraph); page.Graphics.BeginStructureElement(seSpecialParagraph); textFont.Underline = false; textFont.Size = 18; page.Graphics.DrawString("A special paragraph with custom structure element type.", textFont, blackBrush, 30, 350); page.Graphics.EndStructureElement(); // Map the custom structure type to a known structure type. document.StructureTree.RoleMap = new PDFRoleMap(); document.StructureTree.RoleMap["SpecialParagraph"] = PDFStandardStructureTypes.Paragraph; // Include the ID of the structure element in the document's identifiers map. document.StructureTree.IdentifierMap = new PDFIdMap(); document.StructureTree.IdentifierMap["specialpara"] = seSpecialParagraph; }