static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); // Create a blank page //PDF4NET v5: PDFPage page = doc.AddPage(); PDFPage page = doc.Pages.Add(); // Create the signature field. PDFSignatureField sign = new PDFSignatureField("Signature"); //PDF4NET v5: sign.Widgets[0].DisplayRectangle = new DisplayRectangle(50, 100, 200, 40); sign.Widgets[0].DisplayRectangle = new PDFDisplayRectangle(50, 100, 200, 40); // Create the digital signature. //PDF4NET v5: sign.Signature = new PDFDigitalSignature(); PDFCmsDigitalSignature ds = new PDFCmsDigitalSignature(); // The certificate is loaded from disk, but it also can be loaded from a certificate store. ds.Certificate = new X509Certificate2("..\\..\\..\\..\\..\\SupportFiles\\O2SolutionsDemoCertificate.pfx", "P@ssw0rd!", X509KeyStorageFlags.Exportable); ds.Location = "Romania"; ds.Reason = "For demo"; ds.ContactInfo = "*****@*****.**"; sign.Signature = ds; page.Fields.Add(sign); doc.Save("Sample_DigitalSign.pdf"); }
public static void Main(string[] args) { PDFFixedDocument document = new PDFFixedDocument(); PDFPage page = document.Pages.Add(); PDFPen pen = new PDFPen(PDFRgbColor.Black, 1); PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16); PDFPoint[] points = new PDFPoint[] { new PDFPoint(50, 150), new PDFPoint(100, 200), new PDFPoint(150, 50), new PDFPoint(200, 150), new PDFPoint(250, 50) }; DrawBezierConnectedLines(page, points, pen, 0, helvetica); page.Canvas.TranslateTransform(0, 200); DrawBezierConnectedLines(page, points, pen, 0.1, helvetica); page.Canvas.TranslateTransform(0, 200); DrawBezierConnectedLines(page, points, pen, 0.3, helvetica); page.Canvas.TranslateTransform(0, 200); DrawBezierConnectedLines(page, points, pen, 0.5, helvetica); using (FileStream output = File.Create("BezierConnectedLines.pdf")) { document.Save(output); } }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream input) { PDFDocumentFeatures df = new PDFDocumentFeatures(); // Do not load file attachments, new file attachments cannot be added. df.EnableDocumentFileAttachments = false; // Do not load form fields, form fields cannot be filled and new form fields cannot be added. df.EnableDocumentFormFields = false; // Do not load embedded JavaScript code, new JavaScript code at document level cannot be added. df.EnableDocumentJavaScriptFragments = false; // Do not load the named destinations, new named destinations cannot be created. df.EnableDocumentNamedDestinations = false; // Do not load the document outlines, new outlines cannot be created. df.EnableDocumentOutline = false; // Do not load annotations, new annotations cannot be added to existing pages. df.EnablePageAnnotations = false; // Do not load the page graphics, new graphics cannot be added to existing pages. df.EnablePageGraphics = false; PDFFixedDocument document = new PDFFixedDocument(input, df); PDFStandardFont helvetica = new PDFStandardFont(PDFStandardFontFace.HelveticaBold, 24); PDFBrush brush = new PDFBrush(); // Add a new page with some content on it. PDFPage page = document.Pages.Add(); page.Canvas.DrawString("New page added to an existing document.", helvetica, brush, 20, 50); // When document features have been specified at load time the document is automatically saved in incremental update mode. document.Save(input); return(null); }
public static void Main(string[] args) { // Extract the page content from the source file. FileStream stream = File.OpenRead("input.pdf"); PDFFile source = new PDFFile(stream); PDFPageContent pageContent = source.ExtractPageContent(0); stream.Close(); PDFFixedDocument document = new PDFFixedDocument(); document.OptionalContentProperties = new PDFOptionalContentProperties(); PDFPage page = document.Pages.Add(); // Create an optional content group (layer) for the extracted page content. PDFOptionalContentGroup ocg = new PDFOptionalContentGroup(); ocg.Name = "Embedded page"; ocg.VisibilityState = PDFOptionalContentGroupVisibilityState.AlwaysVisible; ocg.PrintState = PDFOptionalContentGroupPrintState.NeverPrint; // Draw the extracted page content in the layer page.Canvas.BeginOptionalContentGroup(ocg); page.Canvas.DrawFormXObject(pageContent, 0, 0, page.Width, page.Height); page.Canvas.EndOptionalContentGroup(); // Build the display tree for the optional content PDFOptionalContentDisplayTreeNode ocgNode = new PDFOptionalContentDisplayTreeNode(ocg); document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgNode); using (FileStream output = File.Create("EmbedPageAsLayer.pdf")) { document.Save(output); } }
public static void Main(string[] args) { string supportPath = "..\\..\\..\\..\\..\\SupportFiles\\"; FileStream input = File.OpenRead(supportPath + "content.pdf"); PDFFixedDocument document = new PDFFixedDocument(input); input.Close(); PDFContentExtractor ce = new PDFContentExtractor(document.Pages[0]); PDFTextSearchResultCollection searchResults = ce.SearchText("lorem"); if (searchResults.Count > 0) { PDFContentRedactor cr = new PDFContentRedactor(document.Pages[0]); cr.BeginRedaction(); for (int i = 0; i < searchResults.Count; i++) { cr.RedactArea(searchResults[i].VisualBounds); } cr.ApplyRedaction(); } using (FileStream output = File.Create("RedactedSearchResults.pdf")) { document.Save(output); } }
// For this sample to work, the following file // needs to exist: multicolumntextandimages.pdf. // Compile the corresponding sample to get this file public static void MultiPage() { //PDF4NET v5: PDFFile mctiFile = PDFFile.FromFile("Sample_MultiColumnTextAndImages-Secure.pdf", Encoding.ASCII.GetBytes("userpass")); FileStream stm = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\content.pdf"); PDFFile file = new PDFFile(stm); // extract the content of first 4 pages //PDF4NET v5: PDFImportedContent[] ic = mctiFile.ExtractPagesContent("0-3"); PDFPageContent[] pc = file.ExtractPageContent(0, 3); // create the new document //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); // add a page to it //PDF4NET v5: PDFPage page = doc.AddPage(); PDFPage page = doc.Pages.Add(); // draw the imported content (4 pages) on the new page //PDF4NET v5: page.Canvas.DrawImportedContent(ic[0], 0, 0, page.Width / 2, page.Height / 2); page.Canvas.DrawFormXObject(pc[0], 0, 0, page.Width / 2, page.Height / 2); //PDF4NET v5: page.Canvas.DrawImportedContent(ic[1], page.Width / 2, 0, page.Width / 2, page.Height / 2); page.Canvas.DrawFormXObject(pc[1], page.Width / 2, 0, page.Width / 2, page.Height / 2); //PDF4NET v5: page.Canvas.DrawImportedContent(ic[2], 0, page.Height / 2, page.Width / 2, page.Height / 2); page.Canvas.DrawFormXObject(pc[2], 0, page.Height / 2, page.Width / 2, page.Height / 2); //PDF4NET v5: page.Canvas.DrawImportedContent(ic[3], page.Width / 2, page.Height / 2, page.Width / 2, page.Height / 2); page.Canvas.DrawFormXObject(pc[3], page.Width / 2, page.Height / 2, page.Width / 2, page.Height / 2); // save the mixed document doc.Save("Sample_Imposition.pdf"); //PDF4NET v5: mctiFile.Close(); stm.Close(); }
// For this sample to work, the following file // need to exist: unicode.pdf. // Compile the corresponding sample to get this file public static void SplitFile() { //PDF4NET v5: PDFFile.SplitFile("Sample_Unicode.pdf", "Sample_Unicode-page.pdf"); FileStream stm = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\content.pdf"); PDFFile file = new PDFFile(stm); for (int i = 0; i < file.PageCount; i++) { PDFFixedDocument document = new PDFFixedDocument(); document.Pages.Add(file.ExtractPage(i)); document.Save(i + ".pdf"); } }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument(); PDFFixedDocument pdfDoc = new PDFFixedDocument(); DrawFirstPage(pdfDoc); DrawSecondPage(pdfDoc); DrawThirdPage(pdfDoc); // Save the document to disk pdfDoc.Save("Sample_CharacterMap.pdf"); }
/// <summary> /// Creates a PDF file that contains 2 file attachments. /// </summary> private static void CreateAttachments() { // Create the pdf document //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); // Create a blank page //PDF4NET v5: PDFPage page = doc.AddPage(); PDFPage page = doc.Pages.Add(); // Print instructions about how to view the attachments in the PDF file. PDFBrush brush = new PDFBrush(new PDFRgbColor(0, 0, 0)); //PDF4NET v5: PDFFont font = new PDFFont(); PDFStandardFont font = new PDFStandardFont(); //PDF4NET v5: page.Canvas.DrawText("This document contains 2 file attachments.", font, null, brush, 50, 50); page.Canvas.DrawString("This document contains 2 file attachments.", font, brush, 50, 50); //PDF4NET v5: page.Canvas.DrawText("In the Acrobat/Reader menu click on View > " + //PDF4NET v5: "Navigation tabs > Attachments to view them.", font, null, brush, 50, 60); page.Canvas.DrawString("In the Acrobat/Reader menu click on View > " + "Navigation tabs > Attachments to view them.", font, brush, 50, 60); // Create an attachment for 'xfasampleform.pdf' file //PDF4NET v5: PDFDocumentAttachment attachment = new PDFDocumentAttachment(); PDFDocumentFileAttachment attachment = new PDFDocumentFileAttachment(); //PDF4NET v5: attachment.FileName = "..\\SupportFiles\\xfasampleform.pdf"; attachment.FileName = "sample.pdf"; attachment.Payload = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf"); attachment.MimeType = "application/pdf"; attachment.Description = "Sample PDF file"; // Add the attachment to document. //PDF4NET v5: doc.Attachments.Add(attachment); doc.FileAttachments.Add(attachment); // Create an attachment for 'auto1.jpg' file //PDF4NET v5: attachment = new PDFDocumentAttachment(); attachment = new PDFDocumentFileAttachment(); //PDF4NET v5: attachment.FileName = "..\\SupportFiles\\auto1.jpg"; attachment.FileName = "auto1.jpg"; attachment.Payload = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\auto1.jpg"); attachment.MimeType = "image/jpg"; attachment.Description = "Lexus - Minority Report"; // Add the attachment to document. doc.FileAttachments.Add(attachment); // Save the document to disk doc.Save("Sample_Attachments.pdf"); }
private static void SplitPagesNoUnusedResourcesRemoval() { using (FileStream fs = File.OpenRead("PDF4NET.Features.pdf")) { PDFFile sourceFile = new PDFFile(fs); for (int i = 0; i < sourceFile.PageCount; i++) { PDFFixedDocument document = new PDFFixedDocument(); PDFPage page = sourceFile.ExtractPage(i); document.Pages.Add(page); document.Save($"UnusedResourcesKept.Page.{i}.pdf"); } } }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument(); PDFFixedDocument pdfDoc = new PDFFixedDocument(); // Create first page //PDF4NET v5: PDFPage pdfPage1 = pdfDoc.AddPage(); PDFPage pdfPage1 = pdfDoc.Pages.Add(); // Create the graphic objects //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 12); PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12); PDFBrush blackBrush = new PDFBrush(new PDFRgbColor()); Random rnd = new Random(); for (int i = 0; i < 50; i++) { // Create random colors for drawing the spline PDFColor penColor = new PDFRgbColor((byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256)); // Create the pen to draw the border PDFPen randomPen = new PDFPen(penColor, 1); // Generate random control points float x1 = rnd.Next((int)pdfPage1.Width); float y1 = rnd.Next((int)pdfPage1.Height); float x2 = rnd.Next((int)pdfPage1.Width); float y2 = rnd.Next((int)pdfPage1.Height); float x3 = rnd.Next((int)pdfPage1.Width); float y3 = rnd.Next((int)pdfPage1.Height); float x4 = rnd.Next((int)pdfPage1.Width); float y4 = rnd.Next((int)pdfPage1.Height); // Draw the Bezier spline pdfPage1.Canvas.DrawBezier(randomPen, x1, y1, x2, y2, x3, y3, x4, y4); } // Draw a label //PDF4NET v5: pdfPage1.Canvas.DrawText("Random Bezier splines", fontText, null, blackBrush, 20, 20, 0, PDFTextAlign.TopLeft); pdfPage1.Canvas.DrawString("Random Bezier splines", fontText, blackBrush, 20, 20); // Save the document to disk pdfDoc.Save("Sample_Bezier.pdf"); }
private void PerformSeparation(string outputPdfFile, bool keepSeparation) { FileStream input = File.OpenRead(pdfFile); PDFFixedDocument document = new PDFFixedDocument(input); input.Close(); PDFPageTransformer pageTransformer = new PDFPageTransformer(document.Pages[0]); PDFSeparateContentTransform sct = new PDFSeparateContentTransform(separationName, keepSeparation); pageTransformer.ApplyTransform(sct); using (FileStream output = File.Create(outputPdfFile)) { document.Save(output); output.Flush(); } }
// For this sample to work, the following file // need to exist: multicolumntextandimages.pdf. // Compile the corresponding sample to get this file public static void EncryptFile() { //PDF4NET v5: //PDFSecurityManager securityManager = new PDFSecurityManager(); //securityManager.KeySize = EncryptionKeySize.Use128BitKey; //securityManager.UserPassword = Encoding.ASCII.GetBytes("userpass"); //securityManager.OwnerPassword = Encoding.ASCII.GetBytes("ownerpass"); //securityManager.AllowPrint = false; //securityManager.FullQualityPrint = true; //securityManager.AllowModifyDocument = false; //securityManager.AllowExtractContent = false; //securityManager.AllowInteractiveEdit = false; //securityManager.AllowFormsFill = true; //securityManager.AllowAccessibilityExtractContent = true; //securityManager.AllowAssembleDocument = false; //PDFFile.EncryptFile(securityManager, // "Sample_MultiColumnTextAndImages.pdf", "Sample_MultiColumnTextAndImages-Secure.pdf"); PDFFixedDocument document = new PDFFixedDocument("..\\..\\..\\..\\..\\SupportFiles\\content.pdf"); PDFAesSecurityHandler aesSecurityHandler = new PDFAesSecurityHandler(); aesSecurityHandler.KeySize = 256; aesSecurityHandler.UserPassword = "******"; aesSecurityHandler.OwnerPassword = "******"; aesSecurityHandler.EnablePrint = false; aesSecurityHandler.HighQualityPrint = true; aesSecurityHandler.EnableDocumentChange = false; aesSecurityHandler.EnableContentExtraction = false; aesSecurityHandler.EnableAnnotationsAndFieldsEdit = false; aesSecurityHandler.EnableFormsFill = true; aesSecurityHandler.EnableContentExtractionForAccessibility = true; aesSecurityHandler.EnableDocumentAssembly = false; document.Save("content-secure.pdf", aesSecurityHandler); // or //PDFDocument doc = // PDFFile.EncryptFile( securityManager, "multicolumntextandimages-secure.pdf" ); ////Serial number goes here //doc.SerialNumber = "serial number goes here"; //doc.Save( stream ); }
private static void SplitPagesWithUnusedResourcesRemoval() { using (FileStream fs = File.OpenRead("PDF4NET.Features.pdf")) { PDFFile sourceFile = new PDFFile(fs); for (int i = 0; i < sourceFile.PageCount; i++) { PDFFixedDocument document = new PDFFixedDocument(); PDFPage page = sourceFile.ExtractPage(i); RemoveUnusedResourcesTransform transform = new RemoveUnusedResourcesTransform(); PDFPageTransformer pageTransformer = new PDFPageTransformer(page); pageTransformer.ApplyTransform(transform); document.Pages.Add(page); document.Save($"UnusedResourcesRemoved.Page.{i}.pdf"); } } }
/// <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); } }
// For this sample to work, the following files // need to exist: unicode.pdf and multicolumntextandimages.pdf. // Compile the corresponding samples to get these files public static void MixFiles() { //PDF4NET v5: PDFFile unicodeFile = PDFFile.FromFile("Sample_Unicode.pdf"); FileStream stm1 = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\content.pdf"); PDFFile file1 = new PDFFile(stm1); //PDF4NET v5: PDFFile mctiFile = PDFFile.FromFile("Sample_MultiColumnTextAndImages.pdf"); FileStream stm2 = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf"); PDFFile file2 = new PDFFile(stm2); //PDF4NET v5: PDFImportedPage ip = null; PDFPage ip = null; //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); for (int i = 0; i < 4; i++) { // extract the page ip = file1.ExtractPage(i); // add the page to new document doc.Pages.Add(ip); // extract the page ip = file2.ExtractPage(i); // add the page to new document doc.Pages.Add(ip); } // save the mixed document doc.Save("Sample_Mix.pdf"); //PDF4NET v5: unicodeFile.Close(); stm1.Close(); //PDF4NET v5: mctiFile.Close(); stm2.Close(); }
static void Main(string[] args) { //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); //PDF4NET v5: PDFPage page = doc.AddPage(); PDFPage page = doc.Pages.Add(); DrawDeviceColorSpace(page); //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); DrawIndexedColorSpace(page); //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); DrawCalGrayColorSpace(page); //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); DrawCalRgbColorSpace(page); //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); DrawLabColorSpace(page); //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); DrawICCColorSpace(page); //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); DrawSeparationColorSpace(page); doc.Save("Sample_ColorSpaces.pdf"); }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); // Create one page //PDF4NET v5: PDFPage page = doc.AddPage(); PDFPage page = doc.Pages.Add(); PDFBrush blackBrush = new PDFBrush(new PDFRgbColor(0, 0, 0)); //PDF4NET v5: PDFFont fontSection = new PDFFont(PDFFontFace.Helvetica, 10); PDFStandardFont fontSection = new PDFStandardFont(PDFStandardFontFace.Helvetica, 10); fontSection.Bold = true; //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 8); PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 8); //PDF4NET v5: page.Canvas.DrawText("Text annotations", fontSection, null, blackBrush, 20, 45, 0, PDFTextAlign.BottomLeft); PDFStringLayoutOptions slo = new PDFStringLayoutOptions() { X = 20, Y = 45, VerticalAlign = PDFStringVerticalAlign.Bottom }; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions() { Font = fontSection, Brush = blackBrush }; page.Canvas.DrawString("Text annotations", sao, slo); // Create all available text annotations //PDF4NET v5: PDFTextAnnotation ta = new PDFTextAnnotation("Comment", "Comment annotation"); PDFTextAnnotation ta = new PDFTextAnnotation() { Author = "Comment", Contents = "Comment annotation" }; page.Annotations.Add(ta); ta.Icon = PDFTextAnnotationIcon.Comment; //PDF4NET v5: ta.Rectangle = new RectangleF(20, 60, 20, 20); ta.Location = new PDFPoint(20, 60); //PDF4NET v5: page.Canvas.DrawText("Comment", fontText, null, blackBrush, 20, 80, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Comment", fontText, blackBrush, 20, 80); //PDF4NET v5: ta = new PDFTextAnnotation("Help", "Help annotation"); ta = new PDFTextAnnotation() { Author = "Help", Contents = "Help annotation" }; page.Annotations.Add(ta); ta.Icon = PDFTextAnnotationIcon.Help; //PDF4NET v5: ta.Rectangle = new RectangleF(100, 60, 20, 20); ta.Location = new PDFPoint(100, 60); //PDF4NET v5: page.Canvas.DrawText("Help", fontText, null, blackBrush, 100, 80, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Help", fontText, blackBrush, 100, 80); //PDF4NET v5: ta = new PDFTextAnnotation("Insert", "Insert annotation"); ta = new PDFTextAnnotation() { Author = "Insert", Contents = "Insert annotation" }; page.Annotations.Add(ta); ta.Icon = PDFTextAnnotationIcon.Insert; //PDF4NET v5: ta.Rectangle = new RectangleF(180, 60, 20, 20); ta.Location = new PDFPoint(180, 60); //PDF4NET v5: page.Canvas.DrawText("Insert", fontText, null, blackBrush, 180, 80, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Insert", fontText, blackBrush, 180, 80); //PDF4NET v5: ta = new PDFTextAnnotation("Key", "Key annotation"); ta = new PDFTextAnnotation() { Author = "Key", Contents = "Key annotation" }; page.Annotations.Add(ta); ta.Icon = PDFTextAnnotationIcon.Key; //PDF4NET v5: ta.Rectangle = new RectangleF(260, 60, 20, 20); ta.Location = new PDFPoint(260, 60); //PDF4NET v5: page.Canvas.DrawText("Key", fontText, null, blackBrush, 260, 80, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Key", fontText, blackBrush, 260, 80); //PDF4NET v5: ta = new PDFTextAnnotation("New paragraph", "New paragraph annotation"); ta = new PDFTextAnnotation() { Author = "New paragraph", Contents = "New paragraph annotation" }; page.Annotations.Add(ta); ta.Icon = PDFTextAnnotationIcon.NewParagraph; //PDF4NET v5: ta.Rectangle = new RectangleF(340, 60, 20, 20); ta.Location = new PDFPoint(340, 60); //PDF4NET v5: page.Canvas.DrawText("New paragraph", fontText, null, blackBrush, 340, 80, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("New paragraph", fontText, blackBrush, 340, 80); //PDF4NET v5: ta = new PDFTextAnnotation("Note", "Note annotation"); ta = new PDFTextAnnotation() { Author = "Note", Contents = "Note annotation" }; page.Annotations.Add(ta); ta.Icon = PDFTextAnnotationIcon.Note; //PDF4NET v5: ta.Rectangle = new RectangleF(420, 60, 20, 20); ta.Location = new PDFPoint(420, 60); //PDF4NET v5: page.Canvas.DrawText("Note", fontText, null, blackBrush, 420, 80, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Note", fontText, blackBrush, 420, 80); //PDF4NET v5: ta = new PDFTextAnnotation("Paragraph", "Paragraph annotation"); ta = new PDFTextAnnotation() { Author = "Paragraph", Contents = "Paragraph annotation" }; page.Annotations.Add(ta); ta.Icon = PDFTextAnnotationIcon.Paragraph; //PDF4NET v5: ta.Rectangle = new RectangleF(500, 60, 20, 20); ta.Location = new PDFPoint(500, 60); //PDF4NET v5: page.Canvas.DrawText("Paragraph", fontText, null, blackBrush, 500, 80, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Paragraph", fontText, blackBrush, 500, 80); // Rubber stamp annotations //PDF4NET v5: page.Canvas.DrawText("Rubber stamp annotations", fontSection, null, blackBrush, 20, 120, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Rubber stamp annotations", fontSection, blackBrush, 20, 120); // Create all available rubber stamp annotations //PDF4NET v5: PDFRubberStampAnnotation rsa = new PDFRubberStampAnnotation("Approved", "Approved annotation"); PDFRubberStampAnnotation rsa = new PDFRubberStampAnnotation() { Author = "Approved", Contents = "Approved annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Approved; rsa.StampName = PDFRubberStampAnnotationName.Approved; //PDF4NET v5: rsa.Rectangle = new RectangleF(20, 140, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(20, 140, 100, 30); rsa.Opacity = 50; //PDF4NET v5: page.Canvas.DrawText("Approved", fontText, null, blackBrush, 20, 180, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Approved", fontText, blackBrush, 20, 180); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("As Is", "As Is annotation"); rsa = new PDFRubberStampAnnotation() { Author = "As Is", Contents = "As Is annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.AsIs; rsa.StampName = PDFRubberStampAnnotationName.AsIs; //PDF4NET v5: rsa.Rectangle = new RectangleF(120, 140, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(120, 140, 100, 30); //PDF4NET v5: page.Canvas.DrawText("As Is", fontText, null, blackBrush, 120, 180, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("As Is", fontText, blackBrush, 120, 180); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Confidential", "Confidential annotation"); rsa = new PDFRubberStampAnnotation() { Author = "Confidential", Contents = "Confidential annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Confidential; rsa.StampName = PDFRubberStampAnnotationName.Confidential; //PDF4NET v5: rsa.Rectangle = new RectangleF(220, 140, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(220, 140, 100, 30); //PDF4NET v5: page.Canvas.DrawText("Confidential", fontText, null, blackBrush, 220, 180, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Confidential", fontText, blackBrush, 220, 180); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Departmental", "Departmental annotation"); rsa = new PDFRubberStampAnnotation() { Author = "Departmental", Contents = "Departmental annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Departmental; rsa.StampName = PDFRubberStampAnnotationName.Departmental; //PDF4NET v5: rsa.Rectangle = new RectangleF(320, 140, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(320, 140, 100, 30); //PDF4NET v5: page.Canvas.DrawText("Departmental", fontText, null, blackBrush, 320, 180, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Departmental", fontText, blackBrush, 320, 180); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Draft", "Draft annotation"); rsa = new PDFRubberStampAnnotation() { Author = "Draft", Contents = "Draft annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Draft; rsa.StampName = PDFRubberStampAnnotationName.Draft; //PDF4NET v5: rsa.Rectangle = new RectangleF(420, 140, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(420, 140, 100, 30); //PDF4NET v5: page.Canvas.DrawText("Draft", fontText, null, blackBrush, 420, 180, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Draft", fontText, blackBrush, 420, 180); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Experimental", "Experimental annotation"); rsa = new PDFRubberStampAnnotation() { Author = "Experimental", Contents = "Experimental annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Experimental; rsa.StampName = PDFRubberStampAnnotationName.Experimental; //PDF4NET v5: rsa.Rectangle = new RectangleF(520, 140, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(520, 140, 100, 30); //PDF4NET v5: page.Canvas.DrawText("Experimental", fontText, null, blackBrush, 520, 180, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Experimental", fontText, blackBrush, 520, 180); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Expired", "Expired annotation"); rsa = new PDFRubberStampAnnotation() { Author = "Expired", Contents = "Expired annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Expired; rsa.StampName = PDFRubberStampAnnotationName.Expired; //PDF4NET v5: rsa.Rectangle = new RectangleF(20, 200, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(20, 200, 100, 30); //PDF4NET v5: page.Canvas.DrawText("Expired", fontText, null, blackBrush, 20, 240, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Expired", fontText, blackBrush, 20, 240); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Final", "Final annotation"); rsa = new PDFRubberStampAnnotation() { Author = "Final", Contents = "Final annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Final; rsa.StampName = PDFRubberStampAnnotationName.Final; //PDF4NET v5: rsa.Rectangle = new RectangleF(120, 200, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(120, 200, 100, 30); //PDF4NET v5: page.Canvas.DrawText("Final", fontText, null, blackBrush, 120, 240, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Final", fontText, blackBrush, 120, 240); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("ForComment", "ForComment annotation"); rsa = new PDFRubberStampAnnotation() { Author = "ForComment", Contents = "ForComment annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.ForComment; rsa.StampName = PDFRubberStampAnnotationName.ForComment; //PDF4NET v5: rsa.Rectangle = new RectangleF(220, 200, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(220, 200, 100, 30); //PDF4NET v5: page.Canvas.DrawText("ForComment", fontText, null, blackBrush, 220, 240, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("ForComment", fontText, blackBrush, 220, 240); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("ForPublicRelease", "ForPublicRelease annotation"); rsa = new PDFRubberStampAnnotation() { Author = "ForPublicRelease", Contents = "ForPublicRelease annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.ForPublicRelease; rsa.StampName = PDFRubberStampAnnotationName.ForPublicRelease; //PDF4NET v5: rsa.Rectangle = new RectangleF(320, 200, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(320, 200, 100, 30); //PDF4NET v5: page.Canvas.DrawText("ForPublicRelease", fontText, null, blackBrush, 320, 240, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("ForPublicRelease", fontText, blackBrush, 320, 240); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("NotApproved", "NotApproved annotation"); rsa = new PDFRubberStampAnnotation() { Author = "NotApproved", Contents = "NotApproved annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.NotApproved; rsa.StampName = PDFRubberStampAnnotationName.NotApproved; //PDF4NET v5: rsa.Rectangle = new RectangleF(420, 200, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(420, 200, 100, 30); //PDF4NET v5: page.Canvas.DrawText("NotApproved", fontText, null, blackBrush, 420, 240, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("NotApproved", fontText, blackBrush, 420, 240); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("NotForPublicRelease", "NotForPublicRelease annotation"); rsa = new PDFRubberStampAnnotation() { Author = "NotForPublicRelease", Contents = "NotForPublicRelease annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.NotForPublicRelease; rsa.StampName = PDFRubberStampAnnotationName.NotForPublicRelease; //PDF4NET v5: rsa.Rectangle = new RectangleF(520, 200, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(520, 200, 100, 30); //PDF4NET v5: page.Canvas.DrawText("NotForPublicRelease", fontText, null, blackBrush, 520, 240, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("NotForPublicRelease", fontText, blackBrush, 520, 240); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("Sold", "Sold annotation"); rsa = new PDFRubberStampAnnotation() { Author = "Sold", Contents = "Sold annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.Sold; rsa.StampName = PDFRubberStampAnnotationName.Sold; //PDF4NET v5: rsa.Rectangle = new RectangleF(20, 260, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(20, 260, 100, 30); //PDF4NET v5: page.Canvas.DrawText("Sold", fontText, null, blackBrush, 20, 300, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Sold", fontText, blackBrush, 20, 300); //PDF4NET v5: rsa = new PDFRubberStampAnnotation("TopSecret", "TopSecret annotation"); rsa = new PDFRubberStampAnnotation() { Author = "TopSecret", Contents = "TopSecret annotation" }; page.Annotations.Add(rsa); //PDF4NET v5: rsa.Icon = PDFRubberStampAnnotationIcon.TopSecret; rsa.StampName = PDFRubberStampAnnotationName.TopSecret; //PDF4NET v5: rsa.Rectangle = new RectangleF(120, 260, 100, 30); rsa.DisplayRectangle = new PDFDisplayRectangle(120, 260, 100, 30); //PDF4NET v5: page.Canvas.DrawText("TopSecret", fontText, null, blackBrush, 120, 300, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("TopSecret", fontText, blackBrush, 120, 300); // Line annotations //PDF4NET v5: page.Canvas.DrawText("Line annotations", fontSection, null, blackBrush, 20, 350, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Line annotations", fontSection, blackBrush, 20, 350); //PDF4NET v5: PDFLineAnnotation la = new PDFLineAnnotation("Line", "Line annotation"); PDFLineAnnotation la = new PDFLineAnnotation() { Author = "Line", Contents = "Line annotation" }; page.Annotations.Add(la); //PDF4NET v5: la.BeginLineStyle = PDFLineEndingStyle.Circle; la.StartLineSymbol = PDFLineEndingStyle.Circle; //PDF4NET v5: la.EndLineStyle = PDFLineEndingStyle.OpenArrow; la.EndLineSymbol = PDFLineEndingStyle.OpenArrow; //PDF4NET v5: la.LineDirection = PDFLineDirection.TopLeftToBottomRight; //PDF4NET v5: la.Rectangle = new RectangleF(20, 370, 150, 30); la.StartPoint = new PDFPoint(20, 370); la.EndPoint = new PDFPoint(170, 400); //PDF4NET v5: la.Border = new PDFAnnotationBorder(1, PDFBorderStyle.Solid); la.LineWidth = 1; //PDF4NET v5: la.Color = new PDFRgbColor(Color.Red); la.LineColor = PDFRgbColor.Red; //PDF4NET v5: la.InteriorColor = new PDFRgbColor(Color.CornflowerBlue); la.InteriorColor = PDFRgbColor.CornflowerBlue; //PDF4NET v5: page.Canvas.DrawText("Line annotation with a circle and open arrow", fontText, null, blackBrush, 20, 420, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Line annotation with a circle and open arrow", fontText, blackBrush, 20, 420); // File attachment annotations //PDF4NET v5: page.Canvas.DrawText("File attachment annotations", fontSection, null, blackBrush, 20, 450, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("File attachment annotations", fontSection, blackBrush, 20, 450); // Create all available file attachment annotations //PDF4NET v5: PDFFileAttachmentAnnotation faa = new PDFFileAttachmentAnnotation("Graph", "Graph icon"); PDFFileAttachmentAnnotation faa = new PDFFileAttachmentAnnotation() { Author = "Graph", Contents = "Graph icon" }; page.Annotations.Add(faa); faa.Icon = PDFFileAttachmentAnnotationIcon.Graph; //PDF4NET v5: faa.Rectangle = new RectangleF(20, 470, 20, 20); faa.Location = new PDFPoint(20, 470); faa.FileName = "sample.pdf"; faa.Payload = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf"); //PDF4NET v5: page.Canvas.DrawText("Graph", fontText, null, blackBrush, 20, 500, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Graph", fontText, blackBrush, 20, 500); //PDF4NET v5: faa = new PDFFileAttachmentAnnotation("Paperclip", "Paperclip icon"); faa = new PDFFileAttachmentAnnotation() { Author = "Paperclip", Contents = "Paperclip icon" }; page.Annotations.Add(faa); faa.Icon = PDFFileAttachmentAnnotationIcon.Paperclip; //PDF4NET v5: faa.Rectangle = new RectangleF(100, 470, 20, 20); faa.Location = new PDFPoint(100, 470); faa.FileName = "sample.pdf"; faa.Payload = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf"); //PDF4NET v5: page.Canvas.DrawText("Paperclip", fontText, null, blackBrush, 100, 500, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Paperclip", fontText, blackBrush, 100, 500); //PDF4NET v5: faa = new PDFFileAttachmentAnnotation("PushPin", "PushPin icon"); faa = new PDFFileAttachmentAnnotation() { Author = "PushPin", Contents = "PushPin icon" }; page.Annotations.Add(faa); faa.Icon = PDFFileAttachmentAnnotationIcon.PushPin; //PDF4NET v5: faa.Rectangle = new RectangleF(180, 470, 20, 20); faa.Location = new PDFPoint(180, 470); faa.FileName = "sample.pdf"; faa.Payload = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf"); //PDF4NET v5: page.Canvas.DrawText("PushPin", fontText, null, blackBrush, 180, 500, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("PushPin", fontText, blackBrush, 180, 500); //PDF4NET v5: faa = new PDFFileAttachmentAnnotation("Tag", "Tag icon"); faa = new PDFFileAttachmentAnnotation() { Author = "Tag", Contents = "Tag icon" }; page.Annotations.Add(faa); faa.Icon = PDFFileAttachmentAnnotationIcon.Tag; //PDF4NET v5: faa.Rectangle = new RectangleF(260, 470, 20, 20); faa.Location = new PDFPoint(260, 470); faa.FileName = "sample.pdf"; faa.Payload = File.ReadAllBytes("..\\..\\..\\..\\..\\SupportFiles\\sample.pdf"); //PDF4NET v5: page.Canvas.DrawText("Graph", fontText, null, blackBrush, 260, 500, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Graph", fontText, blackBrush, 260, 500); // Highlight annotation //PDF4NET v5: page.Canvas.DrawText("Markup annotation - this text will be highlighted", fontSection, null, blackBrush, 20, 610); page.Canvas.DrawString("Markup annotation - this text will be highlighted", fontSection, blackBrush, 20, 610); //PDF4NET v5: PDFHighlightAnnotation ha = new PDFHighlightAnnotation("Markup annotation", "Markup annotation with highlight style"); PDFTextMarkupAnnotation tma = new PDFTextMarkupAnnotation() { Author = "Markup annotation", Contents = "Markup annotation with highlight style" }; tma.TextMarkupType = PDFTextMarkupAnnotationType.Highlight; page.Annotations.Add(tma); //PDF4NET v5: ha.Rectangle = new RectangleF(100, 610, 100, 10); tma.DisplayRectangle = new PDFDisplayRectangle(100, 610, 100, 10); tma.TextMarkupColor = new PDFRgbColor(255, 255, 0); // Square and circle annotations //PDF4NET v5: page.Canvas.DrawText("Square and circle annotations", fontSection, null, blackBrush, 20, 650); page.Canvas.DrawString("Square and circle annotations", fontSection, blackBrush, 20, 650); //PDF4NET v5: PDFEllipseAnnotation ea = new PDFEllipseAnnotation("Ellipse annotation", "An ellipse annotation"); PDFCircleAnnotation ca = new PDFCircleAnnotation() { Author = "Ellipse annotation", Contents = "An ellipse annotation" }; page.Annotations.Add(ca); //PDF4NET v5: ea.Rectangle = new RectangleF(20, 670, 150, 75); ca.DisplayRectangle = new PDFDisplayRectangle(20, 670, 150, 75); //PDF4NET v5: ea.Color = new PDFRgbColor(255, 255, 0); ca.BorderColor = new PDFRgbColor(255, 255, 0); ca.InteriorColor = new PDFRgbColor(0, 255, 0); //PDF4NET v5: PDFRectangleAnnotation ra = new PDFRectangleAnnotation("Rectangle annotation", "A rectangle annotation"); PDFSquareAnnotation sa = new PDFSquareAnnotation() { Author = "Rectangle annotation", Contents = "A rectangle annotation" }; page.Annotations.Add(sa); //PDF4NET v5: ra.Rectangle = new RectangleF(200, 670, 150, 75); sa.DisplayRectangle = new PDFDisplayRectangle(200, 670, 150, 75); //PDF4NET v5: ra.Color = new PDFRgbColor(255, 64, 0); sa.BorderColor = new PDFRgbColor(255, 64, 0); sa.InteriorColor = new PDFRgbColor(64, 0, 255); // Create 2nd page //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); //PDF4NET v5: page.Canvas.DrawText("Annotations with custom appearance", fontSection, null, blackBrush, 20, 45, 0, PDFTextAlign.BottomLeft); slo.Y = 45; page.Canvas.DrawString("Annotations with custom appearance", sao, slo); //PDF4NET v5: page.Canvas.DrawText("a. Annotations with image appearance", fontSection, null, blackBrush, 20, 60, 0, PDFTextAlign.BottomLeft); slo.Y = 60; page.Canvas.DrawString("a. Annotations with image appearance", sao, slo); //PDF4NET v5: PDFRubberStampAnnotation isa = new PDFRubberStampAnnotation("ImageAppearance", "Annotation with image appearance."); PDFRubberStampAnnotation isa = new PDFRubberStampAnnotation() { Author = "ImageAppearance", Contents = "Annotation with image appearance." }; page.Annotations.Add(isa); //PDF4NET v5: isa.Rectangle = new RectangleF(20, 70, 200, 100); isa.DisplayRectangle = new PDFDisplayRectangle(20, 70, 200, 100); //PDF4NET v5: Bitmap img = new Bitmap("..\\SupportFiles\\auto1.jpg"); //PDF4NET v5: isa.Appearance = new PDFImageAppearance(img); //PDF4NET v5: img.Dispose(); FileStream imgStream = File.OpenRead("..\\..\\..\\..\\..\\SupportFiles\\auto1.jpg"); PDFJpegImage img = new PDFJpegImage(imgStream); imgStream.Dispose(); PDFAnnotationAppearance ia = new PDFAnnotationAppearance(isa.DisplayRectangle.Width, isa.DisplayRectangle.Height); ia.Canvas.DrawImage(img, 0, 0, ia.Width, ia.Height); isa.NormalAppearance = ia; //PDF4NET v5: page.Canvas.DrawText("Image appearance", fontText, null, blackBrush, 20, 175, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Image appearance", fontText, blackBrush, 20, 175); //PDF4NET v5: page.Canvas.DrawText("b. Annotations with owner draw appearance", fontSection, null, blackBrush, 20, 200, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("b. Annotations with owner draw appearance", fontSection, blackBrush, 20, 200); //PDF4NET v5: PDFRubberStampAnnotation odsa = new PDFRubberStampAnnotation("OwnerDrawAppearance", "Annotation with owner draw appearance."); PDFRubberStampAnnotation odsa = new PDFRubberStampAnnotation() { Author = "OwnerDrawAppearance", Contents = "Annotation with owner draw appearance." }; page.Annotations.Add(odsa); //PDF4NET v5: odsa.Rectangle = new RectangleF(20, 220, 200, 100); odsa.DisplayRectangle = new PDFDisplayRectangle(20, 220, 200, 100); //PDF4NET v5: odsa.Appearance = new PDFAnnotationAppearance(); //PDF4NET v5: odsa.Appearance.Width = odsa.Rectangle.Width; //PDF4NET v5: odsa.Appearance.Height = odsa.Rectangle.Height; odsa.NormalAppearance = new PDFAnnotationAppearance(odsa.DisplayRectangle.Width, odsa.DisplayRectangle.Height); PDFBrush redBrush = new PDFBrush(new PDFRgbColor(192, 0, 0)); //PDF4NET v5: odsa.Appearance.Canvas.DrawRoundRectangle(redBrush, 0, 0, odsa.Rectangle.Width, odsa.Rectangle.Height, 40, 40); odsa.NormalAppearance.Canvas.DrawRoundRectangle(redBrush, 0, 0, odsa.DisplayRectangle.Width, odsa.DisplayRectangle.Height, 40, 40); PDFBrush blueBrush = new PDFBrush(new PDFRgbColor(0, 0, 128)); //PDF4NET v5: odsa.Appearance.Canvas.DrawEllipse(blueBrush, (odsa.Rectangle.Width - odsa.Rectangle.Height) / 2, 0, odsa.Rectangle.Height, odsa.Rectangle.Height); odsa.NormalAppearance.Canvas.DrawEllipse(blueBrush, (odsa.DisplayRectangle.Width - odsa.DisplayRectangle.Height) / 2, 0, odsa.DisplayRectangle.Height, odsa.DisplayRectangle.Height); //PDF4NET v5: page.Canvas.DrawText("Owner draw appearance", fontText, null, blackBrush, 20, 325, 0, PDFTextAlign.TopLeft); page.Canvas.DrawString("Owner draw appearance", fontText, blackBrush, 20, 325); // Save the document to disk doc.Save("Sample_Annotations.pdf"); }
/// <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; using (FileStream output = File.Create("MultipleDigitalSignatures.pdf")) { document.Save(output); } // For the second signature the document must be opened in incremental update mode // by passing the PDFDocumentFeatures object to PDFFixedDocument constructor PDFDocumentFeatures df = new PDFDocumentFeatures(); // Do not load file attachments, new file attachments cannot be added. df.EnableDocumentFileAttachments = false; // Load form fields to support signing. df.EnableDocumentFormFields = true; // Do not load embedded JavaScript code, new JavaScript code at document level cannot be added. df.EnableDocumentJavaScriptFragments = false; // Do not load the named destinations, new named destinations cannot be created. df.EnableDocumentNamedDestinations = false; // Do not load the document outlines, new outlines cannot be created. df.EnableDocumentOutline = false; // Do not load annotations, new annotations cannot be added to existing pages. df.EnablePageAnnotations = true; // Do not load the page graphics, new graphics cannot be added to existing pages. df.EnablePageGraphics = false; // Incremental update mode requires the changes to be added to the input file input = File.OpenRead("MultipleDigitalSignatures.pdf"); document = new PDFFixedDocument(input, df); input.Close(); signField = new PDFSignatureField("sign2"); document.Pages[0].Fields.Add(signField); signField.Widgets[0].VisualRectangle = new PDFDisplayRectangle(150, 350, 200, 60); 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; // The same file used as input must also be used as output as the Save method saves only the changes and not the entire file. using (FileStream output = File.Open("MultipleDigitalSignatures.pdf", FileMode.Open)) { document.Save(output); } }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument(); PDFFixedDocument pdfDoc = new PDFFixedDocument(); // Create the graphic objects //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 12); PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12); //PDF4NET v5: PDFBrush blackBrush = new PDFBrush(new PDFRgbColor(Color.Black)); PDFBrush blackBrush = new PDFBrush(PDFRgbColor.Black); Random rnd = new Random(); // Create first page //PDF4NET v5: PDFPage pdfPage1 = pdfDoc.AddPage(); PDFPage pdfPage1 = pdfDoc.Pages.Add(); byte[] rgb = new byte[3]; // Draw 50 arcs for (int i = 0; i < 50; i++) { // Create random colors for the border and the interior //PDF4NET v5: Color penColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); // Create the pen to draw the border //PDF4NET v5: PDFPen randomPen = new PDFPen(new PDFRgbColor(penColor), 1); rnd.NextBytes(rgb); PDFPen randomPen = new PDFPen(new PDFRgbColor(rgb[0], rgb[1], rgb[2]), 1); // Generate random positions float left = rnd.Next((int)pdfPage1.Width); float top = rnd.Next((int)pdfPage1.Height); // Generate random sizes float width = rnd.Next((int)(pdfPage1.Width - left)); // try to keep the arc within the page float height = rnd.Next((int)(pdfPage1.Height - top)); // try to keep the arc within the page float startAngle = rnd.Next(360); float sweepAngle = rnd.Next(360); // Draw the ellipse pdfPage1.Canvas.DrawArc(randomPen, top, left, width, height, startAngle, sweepAngle); } // Draw a label //PDF4NET v5: pdfPage1.Canvas.DrawText("Random arcs", fontText, null, blackBrush, 20, 20); pdfPage1.Canvas.DrawString("Random arcs", fontText, blackBrush, 20, 20); // Create the second page //PDF4NET v5: PDFPage pdfPage2 = pdfDoc.AddPage(); PDFPage pdfPage2 = pdfDoc.Pages.Add(); // Draw 50 pies for (int i = 0; i < 50; i++) { // Create random colors for the border and the interior //PDF4NET v5: Color brushColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); //PDF4NET v5: Color penColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); // Create the brush to fill the interior //PDF4NET v5: PDFBrush randomBrush = new PDFBrush(new PDFRgbColor(brushColor)); rnd.NextBytes(rgb); PDFBrush randomBrush = new PDFBrush(new PDFRgbColor(rgb[0], rgb[1], rgb[2])); // Create the pen to draw the border //PDF4NET v5: PDFPen randomPen = new PDFPen(new PDFRgbColor(penColor), 1); rnd.NextBytes(rgb); PDFPen randomPen = new PDFPen(new PDFRgbColor(rgb[0], rgb[1], rgb[2]), 1); // Generate random positions float left = rnd.Next((int)pdfPage2.Width); float top = rnd.Next((int)pdfPage2.Height); // Generate random sizes float width = rnd.Next((int)(pdfPage2.Width - left)); // try to keep the pie within the page float height = rnd.Next((int)(pdfPage2.Height - top)); // try to keep the pie within the page float startAngle = rnd.Next(360); float sweepAngle = rnd.Next(360); // Draw the ellipse pdfPage2.Canvas.DrawPie(randomPen, randomBrush, top, left, width, height, startAngle, sweepAngle); } // Draw a label //PDF4NET v5: pdfPage2.Canvas.DrawText("Random pies", fontText, null, blackBrush, 20, 20); pdfPage2.Canvas.DrawString("Random pies", fontText, blackBrush, 20, 20); // Save the document to disk pdfDoc.Save("Sample_ArcsPies.pdf"); }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument(); PDFFixedDocument pdfDoc = new PDFFixedDocument(); // Set the document information pdfDoc.DocumentInformation = new PDFDocumentInformation(); pdfDoc.DocumentInformation.Author = "O2 Solutions (http://www.o2sol.com)"; pdfDoc.DocumentInformation.Title = "Sample document"; pdfDoc.DocumentInformation.Subject = "The abilities of the PDF4NET library"; pdfDoc.DocumentInformation.Keywords = "pdf4net, pdf, .net, sample"; pdfDoc.DocumentInformation.Creator = "DocAndViewer"; // Set viewer preferences // Change HideMenubar to false in order to // access the Preferences menu item. pdfDoc.ViewerPreferences = new PDFViewerPreferences(); pdfDoc.ViewerPreferences.HideMenubar = false; pdfDoc.ViewerPreferences.HideToolbar = true; pdfDoc.ViewerPreferences.HideWindowUI = true; //PDF4NET v5: pdfDoc.ViewerPreferences.DisplayDocTitle = true; pdfDoc.ViewerPreferences.DisplayDocumentTitle = true; // Set up custom properties //PDF4NET v5: PDFMetadataSchema is no longer supported in PDF4NET 10 //PDFMetadataSchema ms = new PDFMetadataSchema(); //ms["Company"] = "O2 Solutions"; //ms["Website"] = "http://www.o2sol.com/"; //ms["Product"] = "PDF4NET Library"; //ms.StoreSchemaInDocInfo = true; //// Add schema to document //pdfDoc.Metadata = new PDFXMPMetadata(); //pdfDoc.Metadata.MetadataSchemas.Add(ms); // Store custom properties pdfDoc.DocumentInformation.CosDictionary["/Company"] = new PDFCosString("O2 Solutions"); pdfDoc.DocumentInformation.CosDictionary["/Website"] = new PDFCosString("https://o2sol.com/"); pdfDoc.DocumentInformation.CosDictionary["/Product"] = new PDFCosString("PDF4NET"); // Store custom XMP metadata pdfDoc.XmpMetadata = new PDFXmpMetadata(); pdfDoc.XmpMetadata.Metadata = "<custommetadata>Custom metadata</custommetadata>"; // Create one page //PDF4NET v5: PDFPage pdfPage = pdfDoc.AddPage(); PDFPage pdfPage = pdfDoc.Pages.Add(); // Create the graphic objects //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 12); PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12); //PDF4NET v5: PDFFont fontTitle = new PDFFont(PDFFontFace.Helvetica, 12); PDFStandardFont fontTitle = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12); fontTitle.Bold = true; PDFBrush brush = new PDFBrush(new PDFRgbColor()); // Write on the page the current settings //PDF4NET v5: pdfPage.Canvas.DrawText("Document information", fontTitle, null, brush, 20, 20, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Document information", fontTitle, brush, 20, 20); //PDF4NET v5: pdfPage.Canvas.DrawText("Author: " + pdfDoc.DocumentInformation.Author, fontText, null, brush, 20, 35, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Author: " + pdfDoc.DocumentInformation.Author, fontText, brush, 20, 35); //PDF4NET v5: pdfPage.Canvas.DrawText("Title: " + pdfDoc.DocumentInformation.Title, fontText, null, brush, 20, 50, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Title: " + pdfDoc.DocumentInformation.Title, fontText, brush, 20, 50); //PDF4NET v5: pdfPage.Canvas.DrawText("Subject: " + pdfDoc.DocumentInformation.Subject, fontText, null, brush, 20, 65, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Subject: " + pdfDoc.DocumentInformation.Subject, fontText, brush, 20, 65); //PDF4NET v5: pdfPage.Canvas.DrawText("Keywords: " + pdfDoc.DocumentInformation.Keywords, fontText, null, brush, 20, 80, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Keywords: " + pdfDoc.DocumentInformation.Keywords, fontText, brush, 20, 80); //PDF4NET v5: pdfPage.Canvas.DrawText("Creator: " + pdfDoc.DocumentInformation.Creator, fontText, null, brush, 20, 95, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Creator: " + pdfDoc.DocumentInformation.Creator, fontText, brush, 20, 95); //PDF4NET v5: pdfPage.Canvas.DrawText("Viewer preferences", fontTitle, null, brush, 20, 120, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Viewer preferences", fontTitle, brush, 20, 120); //PDF4NET v5: pdfPage.Canvas.DrawText("HideMenubar: " + pdfDoc.ViewerPreferences.HideMenubar, fontText, null, brush, 20, 135, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("HideMenubar: " + pdfDoc.ViewerPreferences.HideMenubar, fontText, brush, 20, 135); //PDF4NET v5: pdfPage.Canvas.DrawText("HideToolbar: " + pdfDoc.ViewerPreferences.HideToolbar, fontText, null, brush, 20, 150, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("HideToolbar: " + pdfDoc.ViewerPreferences.HideToolbar, fontText, brush, 20, 150); //PDF4NET v5: pdfPage.Canvas.DrawText("HideWindowUI: " + pdfDoc.ViewerPreferences.HideWindowUI, fontText, null, brush, 20, 165, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("HideWindowUI: " + pdfDoc.ViewerPreferences.HideWindowUI, fontText, brush, 20, 165); //PDF4NET v5: pdfPage.Canvas.DrawText("DisplayDocTitle: " + pdfDoc.ViewerPreferences.DisplayDocTitle, fontText, null, brush, 20, 180, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("DisplayDocTitle: " + pdfDoc.ViewerPreferences.DisplayDocumentTitle, fontText, brush, 20, 180); // Save the document to disk pdfDoc.Save("Sample_DocAndViewer.pdf"); }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); // Create the graphic objects //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 12); PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12); PDFBrush blackBrush = new PDFBrush(new PDFRgbColor()); // Create 3 pages //PDF4NET v5: PDFPage page = doc.AddPage(); PDFPage page = doc.Pages.Add(); //PDF4NET v5: page.Canvas.DrawText("Page 1", fontText, null, blackBrush, 20, 30); page.Canvas.DrawString("Page 1", fontText, blackBrush, 20, 30); //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); //PDF4NET v5: page.Canvas.DrawText("Page 2", fontText, null, blackBrush, 20, 30); page.Canvas.DrawString("Page 2", fontText, blackBrush, 20, 30); //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); //PDF4NET v5: page.Canvas.DrawText("Page 3", fontText, null, blackBrush, 20, 30); page.Canvas.DrawString("Page 3", fontText, blackBrush, 20, 30); /// URI Action // create a web action //PDF4NET v5: PDFURIAction uriAction = new PDFURIAction(); PDFUriAction uriAction = new PDFUriAction(); uriAction.URI = "http://www.o2sol.com/"; // create a bookmark to point to the url above //PDF4NET v5: PDFBookmark url = new PDFBookmark(); PDFOutlineItem url = new PDFOutlineItem(); url.Title = "www.o2sol.com"; url.Color = new PDFRgbColor(); url.Action = uriAction; // add the bookmark to the document //PDF4NET v5: doc.Bookmarks.Add(url); doc.Outline.Add(url); /// URI Action /// Javascript Action // create a javascript action to print the document PDFJavaScriptAction jsAction = new PDFJavaScriptAction(); jsAction.Script = "this.print(true);\n"; // create a bookmark to point to execute the action //PDF4NET v5: PDFBookmark js = new PDFBookmark(); PDFOutlineItem js = new PDFOutlineItem(); js.Title = "Print me from JavaScript"; js.Color = new PDFRgbColor(); js.Action = jsAction; // add the bookmark to the document //PDF4NET v5: doc.Bookmarks.Add(url); doc.Outline.Add(js); /// Javascript Action /// OpenDocument action // Create an action to be executed when the document is opened // The action will open the document at the // second page of the document using a 800% zoom //PDF4NET v5: PDFPageDestination pageDestination = new PDFPageDestination(); PDFPageDirectDestination pageDestination = new PDFPageDirectDestination(); pageDestination.Page = doc.Pages[1]; //PDF4NET v5: pageDestination.MagnificationMode = PDFMagnificationMode.XYZ; pageDestination.ZoomMode = PDFDestinationZoomMode.XYZ; pageDestination.Left = 0; pageDestination.Top = 0; pageDestination.Zoom = 800; PDFGoToAction goToAction = new PDFGoToAction(); goToAction.Destination = pageDestination; // set the action on the document doc.OpenAction = goToAction; /// OpenDocument action // Save the document to disk doc.Save("Sample_Actions.pdf"); }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); // Create a blank page //PDF4NET v5: PDFPage page = doc.AddPage(); PDFPage page = doc.Pages.Add(); // Create the annotation that will display the 3D artwork. PDF3DAnnotation annot3d = new PDF3DAnnotation(); // Add the annotation to the page. page.Annotations.Add(annot3d); //PDF4NET v5: annot3d.Rectangle = new RectangleF(50, 50, 400, 400); annot3d.DisplayRectangle = new PDFDisplayRectangle(50, 50, 400, 400); annot3d.Stream = Create3DStream(); //PDF4NET v5: annot3d.Appearance = new PDFAnnotationAppearance(); annot3d.NormalAppearance = new PDFAnnotationAppearance(annot3d.DisplayRectangle.Width, annot3d.DisplayRectangle.Height); //PDF4NET v5: annot3d.Appearance.Canvas.DrawText("Click to activate", new PDFFont(), // null, new PDFBrush(new PDFRgbColor()), 200, 200, 0, PDFTextAlign.MiddleCenter); PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.X = 200; slo.Y = 200; slo.HorizontalAlign = PDFStringHorizontalAlign.Center; slo.VerticalAlign = PDFStringVerticalAlign.Middle; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Font = new PDFStandardFont(PDFStandardFontFace.Helvetica, 10); sao.Brush = new PDFBrush(PDFRgbColor.Black); annot3d.NormalAppearance.Canvas.DrawString("Click to activate", sao, slo); // Create the default view. //PDF4NET v5: PDF3DProjection projection1 = new PDF3DProjection(PDF3DProjectionType.Perspective); PDF3DProjection projection1 = new PDF3DProjection() { Type = PDF3DProjectionType.Perspective }; projection1.FieldOfView = 30; PDF3DLightingScheme lightScheme1 = null; //PDF4NET v5: PDF3DRenderMode renderMode1 = new PDF3DRenderMode(PDF3DRenderStyle.Solid); PDF3DRenderMode renderMode1 = new PDF3DRenderMode() { Mode = PDF3DRenderModeType.Solid }; //PDF4NET v5: PDF3DBackground background1 = new PDF3DBackground(new PDFRgbColor(255, 255, 255)); PDF3DBackground background1 = new PDF3DBackground() { Color = PDFRgbColor.White }; PDF3DView defaultView = CreateView("Default view", new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f }, 131.695f, background1, projection1, renderMode1, lightScheme1); // Create a wireframe view. //PDF4NET v5: PDF3DRenderMode renderMode2 = new PDF3DRenderMode(PDF3DRenderStyle.Wireframe); PDF3DRenderMode renderMode2 = new PDF3DRenderMode() { Mode = PDF3DRenderModeType.Wireframe }; PDF3DView wireframeView = CreateView("Wireframe view", new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f }, 131.695f, background1, projection1, renderMode2, lightScheme1); // Create a transparent wireframe view. //PDF4NET v5: PDF3DRenderMode renderMode3 = new PDF3DRenderMode(PDF3DRenderStyle.TransparentWireframe); PDF3DRenderMode renderMode3 = new PDF3DRenderMode() { Mode = PDF3DRenderModeType.TransparentWireframe }; renderMode3.AuxiliaryColor = new PDFRgbColor(0, 192, 0); PDF3DView transparentWireframeView = CreateView("Transparent wireframe view", new double[] { -0.382684f, 0.92388f, -0.0000000766026f, 0.18024f, 0.0746579f, 0.980785f, 0.906127f, 0.37533f, -0.19509f, -122.669f, -112.432f, 45.6829f }, 131.695f, background1, projection1, renderMode3, lightScheme1); annot3d.Stream.Views.Add(defaultView); annot3d.Stream.Views.Add(wireframeView); annot3d.Stream.Views.Add(transparentWireframeView); //PDF4NET v5: annot3d.Stream.DefaultView = 0; annot3d.Stream.DefaultView = defaultView; doc.Save("Sample_3D.pdf"); }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument(); PDFFixedDocument pdfDoc = new PDFFixedDocument(); // set the security options //PDF4NET v5: pdfDoc.SecurityManager = new PDFSecurityManager(); PDFAesSecurityHandler aesSecurityHandler = new PDFAesSecurityHandler(); // use 128 bit encryption //PDF4NET v5: pdfDoc.SecurityManager.KeySize = EncryptionKeySize.Use128BitKey; aesSecurityHandler.KeySize = 256; // set user password to "userpass" //PDF4NET v5: pdfDoc.SecurityManager.UserPassword = Encoding.ASCII.GetBytes("userpass"); aesSecurityHandler.UserPassword = "******"; // set owner password to "ownerpass" //PDF4NET v5: pdfDoc.SecurityManager.OwnerPassword = Encoding.ASCII.GetBytes("ownerpass"); aesSecurityHandler.OwnerPassword = "******"; // allow to print the pdf document //PDF4NET v5: pdfDoc.SecurityManager.AllowPrint = true; aesSecurityHandler.EnablePrint = true; // do not allow high quality print //PDF4NET v5: pdfDoc.SecurityManager.FullQualityPrint = false; aesSecurityHandler.HighQualityPrint = false; // do not alow to modify the document //PDF4NET v5: pdfDoc.SecurityManager.AllowModifyDocument = false; aesSecurityHandler.EnableDocumentChange = false; // do not allow to extract content (text and images) from the document //PDF4NET v5: pdfDoc.SecurityManager.AllowExtractContent = false; aesSecurityHandler.EnableContentExtraction = false; // do not allow to fill forms or to create annotations //PDF4NET v5: pdfDoc.SecurityManager.AllowInteractiveEdit = false; aesSecurityHandler.EnableAnnotationsAndFieldsEdit = false; // do not allow forms fill //PDF4NET v5: pdfDoc.SecurityManager.AllowFormsFill = false; aesSecurityHandler.EnableFormsFill = false; // allow to extract content in support for accessibility //PDF4NET v5: pdfDoc.SecurityManager.AllowAccessibilityExtractContent = true; aesSecurityHandler.EnableContentExtractionForAccessibility = true; // do not allow to assemble document //PDF4NET v5: pdfDoc.SecurityManager.AllowAssembleDocument = false; aesSecurityHandler.EnableDocumentAssembly = false; // Create one page //PDF4NET v5: PDFPage pdfPage = pdfDoc.AddPage(); PDFPage pdfPage = pdfDoc.Pages.Add(); // Draw "Encrypted Hello world" in the center of the page //PDF4NET v5: //pdfPage.Canvas.DrawText("Encrypted", // new PDFFont(PDFFontFace.Helvetica, 100), new PDFPen(new PDFRgbColor(255, 0, 0), 1), // new PDFBrush(new PDFRgbColor(0, 0, 255)), pdfPage.Width / 2, pdfPage.Height / 2 - 3, // 0, PDFTextAlign.BottomCenter); PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.X = pdfPage.Width / 2; slo.Y = pdfPage.Height / 2 - 3; slo.HorizontalAlign = PDFStringHorizontalAlign.Center; slo.VerticalAlign = PDFStringVerticalAlign.Bottom; PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Font = new PDFStandardFont(PDFStandardFontFace.Helvetica, 100); sao.Pen = new PDFPen(new PDFRgbColor(255, 0, 0), 1); sao.Brush = new PDFBrush(new PDFRgbColor(0, 0, 255)); pdfPage.Canvas.DrawString("Encrypted", sao, slo); slo.Y = pdfPage.Height / 2 + 3; slo.VerticalAlign = PDFStringVerticalAlign.Top; pdfPage.Canvas.DrawString("Hello world !", sao, slo); // Save the document to disk //PDF4NET v5:pdfDoc.Save("Sample_Encryption.pdf"); pdfDoc.Save("Sample_Encryption.pdf", aesSecurityHandler); }
static void Main(string[] args) { // Create the graphic objects //PDF4NET v5: PDFFont fontChapter = new PDFFont(PDFFontFace.Helvetica, 20); PDFStandardFont fontChapter = new PDFStandardFont(PDFStandardFontFace.Helvetica, 20); fontChapter.Bold = true; //PDF4NET v5: PDFFont fontSection = new PDFFont(PDFFontFace.Helvetica, 16); PDFStandardFont fontSection = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16); fontSection.Italic = true; //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 12); PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12); PDFBrush blackBrush = new PDFBrush(new PDFRgbColor()); // Create the pdf document //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument(); PDFFixedDocument pdfDoc = new PDFFixedDocument(); // Display the outlines when opening the document pdfDoc.DisplayMode = PDFDisplayMode.UseOutlines; // Create 10 pages for (int i = 0; i < 10; i++) { //PDF4NET v5: PDFPage pdfPage = pdfDoc.AddPage(); PDFPage pdfPage = pdfDoc.Pages.Add(); //PDF4NET v5: pdfPage.Canvas.DrawText("Chapter " + (i + 1).ToString(), fontChapter, null, blackBrush, 10, 10, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Chapter " + (i + 1).ToString(), fontChapter, blackBrush, 10, 10); //PDF4NET v5: pdfPage.Canvas.DrawText("Section " + (i + 1).ToString() + ".1", fontSection, null, blackBrush, 20, 32, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Section " + (i + 1).ToString() + ".1", fontSection, blackBrush, 20, 32); //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".1.1", fontText, null, blackBrush, 30, 50, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".1.1", fontText, blackBrush, 30, 50); //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".1.2", fontText, null, blackBrush, 30, 200, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".1.2", fontText, blackBrush, 30, 200); //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".1.3", fontText, null, blackBrush, 30, 300, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".1.3", fontText, blackBrush, 30, 300); //PDF4NET v5: pdfPage.Canvas.DrawText("Section " + (i + 1).ToString() + ".2", fontSection, null, blackBrush, 20, 400, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Section " + (i + 1).ToString() + ".2", fontSection, blackBrush, 20, 400); //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".2.1", fontText, null, blackBrush, 30, 420, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".2.1", fontText, blackBrush, 30, 420); //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".2.2", fontText, null, blackBrush, 30, 570, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".2.2", fontText, blackBrush, 30, 570); //PDF4NET v5: pdfPage.Canvas.DrawText("Paragraph " + (i + 1).ToString() + ".2.3", fontText, null, blackBrush, 30, 650, 0, PDFTextAlign.TopLeft); pdfPage.Canvas.DrawString("Paragraph " + (i + 1).ToString() + ".2.3", fontText, blackBrush, 30, 650); } // Create the bookmarks tree // Create a root outline //PDF4NET v5: PDFBookmark root = CreateBookmark("Bookmarks", new PDFRgbColor(Color.Black), PDFBookmarkDisplayStyle.Bold, pdfDoc.Pages[0]); PDFOutlineItem root = CreateBookmark("Bookmarks", PDFRgbColor.Black, PDFOutlineItemVisualStyle.Bold, pdfDoc.Pages[0]); //PDF4NET v5: pdfDoc.Bookmarks.Add(root); pdfDoc.Outline.Add(root); // Create document bookmarks for (int i = 0; i < pdfDoc.Pages.Count; i++) { // Create chapter bookmark //PDF4NET v5: PDFBookmark chapter = CreateBookmark("Chapter " + (i + 1).ToString(), new PDFRgbColor(Color.Blue), PDFBookmarkDisplayStyle.Italic, pdfDoc.Pages[i]); PDFOutlineItem chapter = CreateBookmark("Chapter " + (i + 1).ToString(), PDFRgbColor.Blue, PDFOutlineItemVisualStyle.Italic, pdfDoc.Pages[i]); //PDF4NET v5: root.Bookmarks.Add(chapter); root.Items.Add(chapter); // Create section 1 bookmark //PDF4NET v5: PDFBookmark section1 = CreateBookmark("Section " + (i + 1).ToString() + ".1", new PDFRgbColor(Color.Green), PDFBookmarkDisplayStyle.Italic, pdfDoc.Pages[i]); PDFOutlineItem section1 = CreateBookmark("Section " + (i + 1).ToString() + ".1", PDFRgbColor.Green, PDFOutlineItemVisualStyle.Italic, pdfDoc.Pages[i]); //PDF4NET v5: chapter.Bookmarks.Add(section1); chapter.Items.Add(section1); // Create paragraph bookmarks //PDF4NET v5: PDFBookmark paragraph11 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.1", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]); PDFOutlineItem paragraph11 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.1", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]); //PDF4NET v5: section1.Bookmarks.Add(paragraph11); section1.Items.Add(paragraph11); //PDF4NET v5: PDFBookmark paragraph12 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.2", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]); PDFOutlineItem paragraph12 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.2", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]); //PDF4NET v5: section1.Bookmarks.Add(paragraph12); section1.Items.Add(paragraph12); //PDF4NET v5: PDFBookmark paragraph13 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.3", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]); PDFOutlineItem paragraph13 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".1.3", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]); //PDF4NET v5: section1.Bookmarks.Add(paragraph13); section1.Items.Add(paragraph13); section1.Expanded = true; // Create section 2 bookmark //PDF4NET v5: PDFBookmark section2 = CreateBookmark("Section " + (i + 1).ToString() + ".2", new PDFRgbColor(Color.Green), PDFBookmarkDisplayStyle.Italic, pdfDoc.Pages[i]); PDFOutlineItem section2 = CreateBookmark("Section " + (i + 1).ToString() + ".2", PDFRgbColor.Green, PDFOutlineItemVisualStyle.Italic, pdfDoc.Pages[i]); //PDF4NET v5: chapter.Bookmarks.Add(section2); chapter.Items.Add(section2); // Create paragraph bookmarks //PDF4NET v5: PDFBookmark paragraph21 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.1", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]); PDFOutlineItem paragraph21 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.1", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]); //PDF4NET v5: section2.Bookmarks.Add(paragraph21); section2.Items.Add(paragraph21); //PDF4NET v5: PDFBookmark paragraph22 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.2", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]); PDFOutlineItem paragraph22 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.2", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]); //PDF4NET v5: section2.Bookmarks.Add(paragraph22); section2.Items.Add(paragraph22); //PDF4NET v5: PDFBookmark paragraph23 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.3", new PDFRgbColor(Color.Red), PDFBookmarkDisplayStyle.Regular, pdfDoc.Pages[i]); PDFOutlineItem paragraph23 = CreateBookmark("Paragraph " + (i + 1).ToString() + ".2.3", PDFRgbColor.Red, PDFOutlineItemVisualStyle.Regular, pdfDoc.Pages[i]); //PDF4NET v5: section2.Bookmarks.Add(paragraph23); section2.Items.Add(paragraph23); section2.Expanded = true; chapter.Expanded = true; } root.Expanded = true; // Save the document to disk pdfDoc.Save("Sample_Bookmarks.pdf"); }
static void Main(string[] args) { // Create the pdf document //PDF4NET v5: PDFDocument pdfDoc = new PDFDocument(); PDFFixedDocument pdfDoc = new PDFFixedDocument(); // Create first page //PDF4NET v5: PDFPage pdfPage1 = pdfDoc.AddPage(); PDFPage pdfPage1 = pdfDoc.Pages.Add(); // Create the graphic objects //PDF4NET v5: PDFFont fontText = new PDFFont(PDFFontFace.Helvetica, 12); PDFStandardFont fontText = new PDFStandardFont(PDFStandardFontFace.Helvetica, 12); PDFBrush blackBrush = new PDFBrush(new PDFRgbColor()); PDFBrush greenBrush = new PDFBrush(new PDFRgbColor(0, 255, 0)); PDFPen pen = new PDFPen(PDFRgbColor.Orange, 1); // Draw an ellipse that has a border //PDF4NET v5: pdfPage1.Canvas.DrawText("This ellipse is drawn by drawing its border", fontText, null, blackBrush, 20, 20, 0, PDFTextAlign.TopLeft); pdfPage1.Canvas.DrawString("This ellipse is drawn by drawing its border", fontText, blackBrush, 20, 20); pdfPage1.Canvas.DrawEllipse(pen, null, 20, 35, 200, 100); // Draw an ellipse that has no border and its interior is filled //PDF4NET v5: pdfPage1.Canvas.DrawText("This ellipse is drawn by filling its interior", fontText, null, blackBrush, 300, 20, 0, PDFTextAlign.TopLeft); pdfPage1.Canvas.DrawString("This ellipse is drawn by filling its interior", fontText, blackBrush, 300, 20); pdfPage1.Canvas.DrawEllipse(null, greenBrush, 300, 35, 300, 150); // Draw an ellipse that has a border and its interior is filled //PDF4NET v5: pdfPage1.Canvas.DrawText("This ellipse has a border and a filled interior", fontText, null, blackBrush, 20, 200, 0, PDFTextAlign.TopLeft); pdfPage1.Canvas.DrawString("This ellipse has a border and a filled interior", fontText, blackBrush, 20, 200); pdfPage1.Canvas.DrawEllipse(pen, greenBrush, 20, 215, 200, 150); // Draw a circle //PDF4NET v5: pdfPage1.Canvas.DrawText("This is a circle", fontText, null, blackBrush, 300, 200, 0, PDFTextAlign.TopLeft); pdfPage1.Canvas.DrawString("This is a circle", fontText, blackBrush, 300, 200); pdfPage1.Canvas.DrawEllipse(pen, greenBrush, 300, 215, 200, 200); // Create the second page //PDF4NET v5: PDFPage pdfPage2 = pdfDoc.AddPage(); PDFPage pdfPage2 = pdfDoc.Pages.Add(); Random rnd = new Random(); for (int i = 0; i < 50; i++) { // Create random colors for the border and the interior PDFRgbColor brushColor = new PDFRgbColor((byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256)); PDFRgbColor penColor = new PDFRgbColor((byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256)); // Create the brush to fill the interior PDFBrush randomBrush = new PDFBrush(brushColor); // Create the pen to draw the border PDFPen randomPen = new PDFPen(penColor, 1); // Generate random positions float left = rnd.Next((int)pdfPage2.Width); float top = rnd.Next((int)pdfPage2.Height); // Generate random sizes float width = rnd.Next((int)(pdfPage2.Width - left)); // try to keep the rectangle float height = rnd.Next((int)(pdfPage2.Height - top)); // within the page // Draw the ellipse pdfPage2.Canvas.DrawEllipse(randomPen, randomBrush, left, top, width, height); } // Draw a label //PDF4NET v5: pdfPage2.Canvas.DrawText("Random ellipses", fontText, null, blackBrush, 20, 350, 0, PDFTextAlign.TopLeft); pdfPage2.Canvas.DrawString("Random ellipses", fontText, blackBrush, 20, 350); // Save the document to disk pdfDoc.Save("Sample_Ellipses.pdf"); }
static void Main(string[] args) { // Create the PDF document //PDF4NET v5: PDFDocument doc = new PDFDocument(); PDFFixedDocument doc = new PDFFixedDocument(); // Create the helper graphic objects. //PDF4NET v5: PDFFont titleFont = new PDFFont(PDFFontFace.Helvetica, 10); PDFStandardFont titleFont = new PDFStandardFont(PDFStandardFontFace.Helvetica, 10); titleFont.Bold = true; //PDF4NET v5: PDFFont textFont = new PDFFont(PDFFontFace.Helvetica, 8); PDFStandardFont textFont = new PDFStandardFont(PDFStandardFontFace.Helvetica, 8); //PDF4NET v5: PDFBrush brush = new PDFBrush(new PDFRgbColor(Color.Black)); PDFBrush brush = new PDFBrush(PDFRgbColor.Black); // First page for linear barcodes. //PDF4NET v5: PDFPage page = doc.AddPage(); PDFPage page = doc.Pages.Add(); //PDF4NET v5: page.Canvas.DrawText("1D/Linear barcodes", titleFont, null, brush, 20, 50); page.Canvas.DrawString("1D/Linear barcodes", titleFont, brush, 20, 50); //PDF4NET v5: page.Canvas.DrawText("1. Codabar", textFont, null, brush, 20, 70); page.Canvas.DrawString("1. Codabar", textFont, brush, 20, 70); PDFCodabarBarcode cb = new PDFCodabarBarcode("0123456789"); page.Canvas.DrawBarcode(cb, 20, 80); //PDF4NET v5: page.Canvas.DrawText("2. Code 11", textFont, null, brush, 20, 140); page.Canvas.DrawString("2. Code 11", textFont, brush, 20, 140); PDFCode11Barcode c11 = new PDFCode11Barcode("0123456789"); page.Canvas.DrawBarcode(c11, 20, 150); //PDF4NET v5: page.Canvas.DrawText("3. Code 128A", textFont, null, brush, 20, 210); page.Canvas.DrawString("3. Code 128A", textFont, brush, 20, 210); PDFCode128ABarcode c128a = new PDFCode128ABarcode("CODE128A"); page.Canvas.DrawBarcode(c128a, 20, 220); //PDF4NET v5: page.Canvas.DrawText("4. Code 128B", textFont, null, brush, 20, 280); page.Canvas.DrawString("4. Code 128B", textFont, brush, 20, 280); PDFCode128BBarcode c128b = new PDFCode128BBarcode("CODE128B"); page.Canvas.DrawBarcode(c128b, 20, 290); //PDF4NET v5: page.Canvas.DrawText("5. Code 128C", textFont, null, brush, 20, 350); page.Canvas.DrawString("5. Code 128C", textFont, brush, 20, 350); PDFCode128CBarcode c128c = new PDFCode128CBarcode("0123456789"); page.Canvas.DrawBarcode(c128c, 20, 360); //PDF4NET v5: page.Canvas.DrawText("6. Code 25", textFont, null, brush, 20, 420); page.Canvas.DrawString("6. Code 25", textFont, brush, 20, 420); PDFCode25Barcode c25 = new PDFCode25Barcode("0123456789"); page.Canvas.DrawBarcode(c25, 20, 430); //PDF4NET v5: page.Canvas.DrawText("7. Code 25 Interleaved", textFont, null, brush, 20, 490); page.Canvas.DrawString("7. Code 25 Interleaved", textFont, brush, 20, 490); PDFCode25InterleavedBarcode c25i = new PDFCode25InterleavedBarcode("0123456789"); page.Canvas.DrawBarcode(c25i, 20, 500); //PDF4NET v5: page.Canvas.DrawText("8. Code 39", textFont, null, brush, 20, 560); page.Canvas.DrawString("8. Code 39", textFont, brush, 20, 560); PDFCode39Barcode c39 = new PDFCode39Barcode("CODE39"); page.Canvas.DrawBarcode(c39, 20, 570); //PDF4NET v5: page.Canvas.DrawText("9. Code 39 Extended", textFont, null, brush, 20, 630); page.Canvas.DrawString("9. Code 39 Extended", textFont, brush, 20, 630); PDFCode39ExtendedBarcode c39x = new PDFCode39ExtendedBarcode("C39Ext"); page.Canvas.DrawBarcode(c39x, 20, 640); //PDF4NET v5: page.Canvas.DrawText("10. Code 93", textFont, null, brush, 20, 700); page.Canvas.DrawString("10. Code 93", textFont, brush, 20, 700); PDFCode93Barcode c93 = new PDFCode93Barcode("CODE93"); page.Canvas.DrawBarcode(c93, 20, 710); //PDF4NET v5: page.Canvas.DrawText("11. Code 93 Extended", textFont, null, brush, 200, 70); page.Canvas.DrawString("11. Code 93 Extended", textFont, brush, 200, 70); PDFCode93ExtendedBarcode c93x = new PDFCode93ExtendedBarcode("C93Ext"); page.Canvas.DrawBarcode(c93x, 200, 80); //PDF4NET v5: page.Canvas.DrawText("12. COOP 25", textFont, null, brush, 200, 140); page.Canvas.DrawString("12. COOP 25", textFont, brush, 200, 140); //PDF4NET v5: PDFCOOP25Barcode coop25 = new PDFCOOP25Barcode("0123456789"); PDFCoop25Barcode coop25 = new PDFCoop25Barcode("0123456789"); page.Canvas.DrawBarcode(coop25, 200, 150); //PDF4NET v5: page.Canvas.DrawText("13. EAN-13", textFont, null, brush, 200, 210); page.Canvas.DrawString("13. EAN-13", textFont, brush, 200, 210); //PDF4NET v5: PDFEAN13Barcode ean13 = new PDFEAN13Barcode("012345678901"); PDFEan13Barcode ean13 = new PDFEan13Barcode("012345678901"); page.Canvas.DrawBarcode(ean13, 200, 220); //PDF4NET v5: page.Canvas.DrawText("14. EAN-8", textFont, null, brush, 200, 280); page.Canvas.DrawString("14. EAN-8", textFont, brush, 200, 280); //PDF4NET v5: PDFEAN8Barcode ean8 = new PDFEAN8Barcode("0123456"); PDFEan8Barcode ean8 = new PDFEan8Barcode("0123456"); page.Canvas.DrawBarcode(ean8, 200, 290); //PDF4NET v5: page.Canvas.DrawText("15. IATA 25", textFont, null, brush, 200, 350); page.Canvas.DrawString("15. IATA 25", textFont, brush, 200, 350); //PDF4NET v5: PDFIATA25Barcode i25 = new PDFIATA25Barcode("0123456789"); PDFIata25Barcode i25 = new PDFIata25Barcode("0123456789"); page.Canvas.DrawBarcode(i25, 200, 360); //PDF4NET v5: page.Canvas.DrawText("16. ISBN", textFont, null, brush, 200, 420); page.Canvas.DrawString("16. ISBN", textFont, brush, 200, 420); //PDF4NET v5: PDFISBNBarcode isbn = new PDFISBNBarcode("123456789"); PDFIsbnBarcode isbn = new PDFIsbnBarcode("123456789"); page.Canvas.DrawBarcode(isbn, 200, 430); //PDF4NET v5: page.Canvas.DrawText("17. ISMN", textFont, null, brush, 200, 490); page.Canvas.DrawString("17. ISMN", textFont, brush, 200, 490); //PDF4NET v5: PDFISMNBarcode ismn = new PDFISMNBarcode("123456789"); PDFIsmnBarcode ismn = new PDFIsmnBarcode("123456789"); page.Canvas.DrawBarcode(ismn, 200, 500); //PDF4NET v5: page.Canvas.DrawText("18. ISSN", textFont, null, brush, 200, 560); page.Canvas.DrawString("18. ISSN", textFont, brush, 200, 560); //PDF4NET v5: PDFISSNBarcode issn = new PDFISSNBarcode("123456789"); PDFIssnBarcode issn = new PDFIssnBarcode("123456789"); page.Canvas.DrawBarcode(issn, 200, 570); //PDF4NET v5: page.Canvas.DrawText("19. JAN-13", textFont, null, brush, 200, 630); page.Canvas.DrawString("19. JAN-13", textFont, brush, 200, 630); //PDF4NET v5: PDFJAN13Barcode jan13 = new PDFJAN13Barcode("1234567890"); PDFJan13Barcode jan13 = new PDFJan13Barcode("1234567890"); page.Canvas.DrawBarcode(jan13, 200, 640); //PDF4NET v5: page.Canvas.DrawText("20. Matrix 25", textFont, null, brush, 200, 700); page.Canvas.DrawString("20. Matrix 25", textFont, brush, 200, 700); PDFMatrix25Barcode m25 = new PDFMatrix25Barcode("0123456789"); page.Canvas.DrawBarcode(m25, 200, 710); //PDF4NET v5: page.Canvas.DrawText("21. Msi/Plessey", textFont, null, brush, 350, 70); page.Canvas.DrawString("21. Msi/Plessey", textFont, brush, 350, 70); //PDF4NET v5: PDFMSIPlesseyBarcode msi = new PDFMSIPlesseyBarcode("0123456789"); PDFMsiPlesseyBarcode msi = new PDFMsiPlesseyBarcode("0123456789"); page.Canvas.DrawBarcode(msi, 350, 80); //PDF4NET v5: page.Canvas.DrawText("22. Planet", textFont, null, brush, 350, 140); page.Canvas.DrawString("22. Planet", textFont, brush, 350, 140); PDFPlanetBarcode planet = new PDFPlanetBarcode("012345678901"); page.Canvas.DrawBarcode(planet, 350, 150); //PDF4NET v5: page.Canvas.DrawText("23. Postnet", textFont, null, brush, 350, 210); page.Canvas.DrawString("23. Postnet", textFont, brush, 350, 210); PDFPostNetBarcode postnet = new PDFPostNetBarcode("012345678"); page.Canvas.DrawBarcode(postnet, 350, 220); //PDF4NET v5: page.Canvas.DrawText("24. RM4SCC", textFont, null, brush, 350, 280); page.Canvas.DrawString("24. RM4SCC", textFont, brush, 350, 280); //PDF4NET v5: PDFRM4SCCBarcode rm4scc = new PDFRM4SCCBarcode("RM4SCC"); PDFRm4sccBarcode rm4scc = new PDFRm4sccBarcode("RM4SCC"); page.Canvas.DrawBarcode(rm4scc, 350, 290); //PDF4NET v5: page.Canvas.DrawText("25. SCC-14", textFont, null, brush, 350, 350); page.Canvas.DrawString("25. SCC-14", textFont, brush, 350, 350); //PDF4NET v5: PDFSCC14Barcode scc14 = new PDFSCC14Barcode("0123456789012"); PDFScc14Barcode scc14 = new PDFScc14Barcode("0123456789012"); page.Canvas.DrawBarcode(scc14, 350, 360); //PDF4NET v5: page.Canvas.DrawText("26. SSCC-18", textFont, null, brush, 350, 420); page.Canvas.DrawString("26. SSCC-18", textFont, brush, 350, 420); //PDF4NET v5: PDFSSCC18Barcode sscc18 = new PDFSSCC18Barcode("00000012331234567"); PDFSscc18Barcode sscc18 = new PDFSscc18Barcode("00000012331234567"); page.Canvas.DrawBarcode(sscc18, 350, 430); //PDF4NET v5: page.Canvas.DrawText("27. UPC-A", textFont, null, brush, 350, 490); page.Canvas.DrawString("27. UPC-A", textFont, brush, 350, 490); //PDF4NET v5: PDFUPCABarcode upca = new PDFUPCABarcode("87567816412"); PDFUpcaBarcode upca = new PDFUpcaBarcode("87567816412"); upca.Supplement = "59999"; upca.SupplementYDimension = 20; //PDF4NET v5: upca.SupplementDisplayLocation = BarcodeTextLocation.Above; upca.SupplementTextPosition = PDFBarcodeTextPosition.Top; page.Canvas.DrawBarcode(upca, 350, 500); //PDF4NET v5: page.Canvas.DrawText("28. UPC-E", textFont, null, brush, 350, 560); page.Canvas.DrawString("28. UPC-E", textFont, brush, 350, 560); //PDF4NET v5: PDFUPCEBarcode upce = new PDFUPCEBarcode("0425261"); PDFUpceBarcode upce = new PDFUpceBarcode("0425261"); page.Canvas.DrawBarcode(upce, 350, 570); // Second page for linear barcodes. //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); //PDF4NET v5: page.Canvas.DrawText("1D/Linear barcodes (continued)", titleFont, null, brush, 20, 50); page.Canvas.DrawString("1D/Linear barcodes (continued)", titleFont, brush, 20, 50); //PDF4NET v5: page.Canvas.DrawText("29. Singapore Post", textFont, null, brush, 20, 70); page.Canvas.DrawString("29. Singapore Post", textFont, brush, 20, 70); PDFSingaporePostBarcode singPost = new PDFSingaporePostBarcode("0123456789"); page.Canvas.DrawBarcode(singPost, 20, 80); //PDF4NET v5: page.Canvas.DrawText("30. Royal Dutch TPG Post", textFont, null, brush, 20, 140); page.Canvas.DrawString("30. Royal Dutch TPG Post", textFont, brush, 20, 140); PDFKixBarcode kix = new PDFKixBarcode("0123456789"); page.Canvas.DrawBarcode(kix, 20, 150); //PDF4NET v5: page.Canvas.DrawText("31. PZN", textFont, null, brush, 20, 210); page.Canvas.DrawString("31. PZN", textFont, brush, 20, 210); //PDF4NET v5: PDFPZNBarcode pzn = new PDFPZNBarcode("123456"); PDFPznBarcode pzn = new PDFPznBarcode("123456"); page.Canvas.DrawBarcode(pzn, 20, 220); //PDF4NET v5: page.Canvas.DrawText("32. Deutsche Post Identcode", textFont, null, brush, 20, 280); page.Canvas.DrawString("32. Deutsche Post Identcode", textFont, brush, 20, 280); PDFIdentcodeBarcode identcode = new PDFIdentcodeBarcode("01234567890"); page.Canvas.DrawBarcode(identcode, 20, 290); //PDF4NET v5: page.Canvas.DrawText("33. Deutsche Post Leitcode", textFont, null, brush, 20, 350); page.Canvas.DrawString("33. Deutsche Post Leitcode", textFont, brush, 20, 350); PDFLeitcodeBarcode leitcode = new PDFLeitcodeBarcode("0123456789012"); page.Canvas.DrawBarcode(leitcode, 20, 360); //PDF4NET v5: page.Canvas.DrawText("34. USPS Facing Identification Mark", textFont, null, brush, 20, 420); page.Canvas.DrawString("34. USPS Facing Identification Mark", textFont, brush, 20, 420); //PDF4NET v5: PDFUSPSFIMBarcode fim = new PDFUSPSFIMBarcode("A"); PDFUspsFimBarcode fim = new PDFUspsFimBarcode("A"); page.Canvas.DrawBarcode(fim, 20, 430); //PDF4NET v5: page.Canvas.DrawText("35. USPS Horizontal Bars", textFont, null, brush, 20, 490); page.Canvas.DrawString("35. USPS Horizontal Bars", textFont, brush, 20, 490); //PDF4NET v5: PDFUSPSHorizontalBarcode hb = new PDFUSPSHorizontalBarcode("111"); PDFUspsHorizontalBarcode hb = new PDFUspsHorizontalBarcode("111"); page.Canvas.DrawBarcode(hb, 20, 500); //PDF4NET v5: page.Canvas.DrawText("36. USPS Package Identification Code", textFont, null, brush, 20, 560); page.Canvas.DrawString("36. USPS Package Identification Code", textFont, brush, 20, 560); //PDF4NET v5: PDFUSPSPICBarcode pic = new PDFUSPSPICBarcode("910123456789012345678"); PDFUspsPicBarcode pic = new PDFUspsPicBarcode("910123456789012345678"); page.Canvas.DrawBarcode(pic, 20, 570); //PDF4NET v5: page.Canvas.DrawText("37. FedEx Ground 96", textFont, null, brush, 20, 630); page.Canvas.DrawString("37. FedEx Ground 96", textFont, brush, 20, 630); PDFFedExGround96Barcode fg96 = new PDFFedExGround96Barcode("960123456789012345678"); page.Canvas.DrawBarcode(fg96, 20, 640); //PDF4NET v5: page.Canvas.DrawText("38. Pharmacode", textFont, null, brush, 20, 700); page.Canvas.DrawString("38. Pharmacode", textFont, brush, 20, 700); PDFPharmacodeBarcode pharma = new PDFPharmacodeBarcode("12345"); page.Canvas.DrawBarcode(pharma, 20, 710); //PDF4NET v5: page.Canvas.DrawText("39. Code 32 - Italian Pharmacode", textFont, null, brush, 200, 70); page.Canvas.DrawString("39. Code 32 - Italian Pharmacode", textFont, brush, 200, 70); PDFCode32Barcode c32 = new PDFCode32Barcode("12345678"); page.Canvas.DrawBarcode(c32, 200, 80); //PDF4NET v5: page.Canvas.DrawText("40. UCC/EAN 128", textFont, null, brush, 200, 140); page.Canvas.DrawString("40. UCC/EAN 128", textFont, brush, 200, 140); //PDF4NET v5: PDFEAN128Barcode ean128 = new PDFEAN128Barcode("0123456789"); PDFEan128Barcode ean128 = new PDFEan128Barcode("0123456789"); ean128.ApplicationIdentifier = "101"; page.Canvas.DrawBarcode(ean128, 200, 150); // Create the 3rd page to display 2D barcodes. //PDF4NET v5: page = doc.AddPage(); page = doc.Pages.Add(); //PDF4NET v5: page.Canvas.DrawText("2D/Bidimensional barcodes", titleFont, null, brush, 20, 50); page.Canvas.DrawString("2D/Bidimensional barcodes", titleFont, brush, 20, 50); //PDF4NET v5: page.Canvas.DrawText("1. Codablock F", textFont, null, brush, 20, 70); page.Canvas.DrawString("1. Codablock F", textFont, brush, 20, 70); PDFCodablockFBarcode cf = new PDFCodablockFBarcode(); cf.Rows = 5; cf.Columns = 7; cf.Data = "1234567890"; page.Canvas.DrawBarcode(cf, 20, 80); //PDF4NET v5: page.Canvas.DrawText("2. Code 16K", textFont, null, brush, 20, 140); page.Canvas.DrawString("2. Code 16K", textFont, brush, 20, 140); PDFCode16KBarcode c16k = new PDFCode16KBarcode(); c16k.Rows = 0; c16k.Data = "Abcd-1234567890-wxyZ"; page.Canvas.DrawBarcode(c16k, 20, 150); //PDF4NET v5: page.Canvas.DrawText("3. DataMatrix", textFont, null, brush, 20, 210); page.Canvas.DrawString("3. DataMatrix", textFont, brush, 20, 210); PDFDataMatrixBarcode dm = new PDFDataMatrixBarcode(); //PDF4NET v5: dm.Encoding = DataMatrixEncoding.ASCII; dm.DataEncoding = DataMatrixEncoding.ASCII; //PDF4NET v5: dm.SymbolSize = DataMatrixSymbolSize.Auto; dm.BarcodeSize = DataMatrixBarcodeSize.Auto; dm.Data = "ABCDabcd"; dm.XDimension = 3; page.Canvas.DrawBarcode(dm, 20, 220); //PDF4NET v5: page.Canvas.DrawText("4. MicroPDF417", textFont, null, brush, 20, 280); page.Canvas.DrawString("4. MicroPDF417", textFont, brush, 20, 280); //PDF4NET v5: PDFMicroPDF417Barcode mpdf417 = new PDFMicroPDF417Barcode(); PDF417MicroBarcode mpdf417 = new PDF417MicroBarcode(); mpdf417.CompactionMode = PDF417DataCompactionMode.Text; mpdf417.Data = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZAB"; mpdf417.XDimension = 1; mpdf417.YDimension = 2.5f; mpdf417.BarcodeSize = PDF417MicroBarcodeSize.Rows20Columns4; page.Canvas.DrawBarcode(mpdf417, 20, 290); //PDF4NET v5: page.Canvas.DrawText("5. PDF417", textFont, null, brush, 20, 370); page.Canvas.DrawString("5. PDF417", textFont, brush, 20, 370); //PDF4NET v5: PDF417Barcode pdf417 = new PDF417Barcode(); PDF417RegularBarcode pdf417 = new PDF417RegularBarcode(); pdf417.CompactionMode = PDF417DataCompactionMode.Text; pdf417.Data = "ABCDEF"; pdf417.Rows = 5; pdf417.Columns = 5; pdf417.XDimension = 1; pdf417.YDimension = 10; pdf417.ErrorCorrectionLevel = PDF417ErrorCorrectionLevel.Level2; page.Canvas.DrawBarcode(pdf417, 20, 380); doc.Save("Sample_Barcodes.pdf"); }