private static void CreateRubberStampAnnotations(PDFFixedDocument document, PDFFont font) { PDFBrush blackBrush = new PDFBrush(); PDFPage page = document.Pages.Add(); string[] rubberStampAnnotationNames = new string[] { "Approved", "AsIs", "Confidential", "Departmental", "Draft", "Experimental", "Expired", "Final", "ForComment", "ForPublicRelease", "NotApproved", "NotForPublicRelease", "Sold", "TopSecret" }; page.Canvas.DrawString("Rubber stamp annotations", font, blackBrush, 50, 50); for (int i = 0; i < rubberStampAnnotationNames.Length; i++) { PDFRubberStampAnnotation rsa = new PDFRubberStampAnnotation(); rsa.Author = "O2S.Components.PDF4NET"; rsa.Contents = "I am a " + rubberStampAnnotationNames[i] + " rubber stamp annotation."; rsa.StampName = rubberStampAnnotationNames[i]; page.Annotations.Add(rsa); rsa.DisplayRectangle = new PDFDisplayRectangle(50, 70 + 50 * i, 200, 40); page.Canvas.DrawString(rubberStampAnnotationNames[i], font, blackBrush, 270, 85 + 50 * i); } page.Canvas.DrawString("Stamp annotations with custom appearance", font, blackBrush, 350, 50); PDFRubberStampAnnotation customRubberStampAnnotation = new PDFRubberStampAnnotation(); customRubberStampAnnotation.Contents = "Rubber stamp annotation with custom appearance."; customRubberStampAnnotation.StampName = "Custom"; page.Annotations.Add(customRubberStampAnnotation); customRubberStampAnnotation.DisplayRectangle = new PDFDisplayRectangle(350, 70, 200, 40); PDFAnnotationAppearance customAppearance = new PDFAnnotationAppearance(50, 50); PDFPen redPen = new PDFPen(new PDFRgbColor(255, 0, 0), 10); PDFPen bluePen = new PDFPen(new PDFRgbColor(0, 0, 192), 10); customAppearance.Canvas.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Canvas.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Canvas.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Canvas.CompressAndClose(); customRubberStampAnnotation.NormalAppearance = customAppearance; }
/// <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); } }
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"); }
private static void CreateTextAnnotations(PDFFixedDocument document, PDFFont font) { PDFBrush blackBrush = new PDFBrush(); PDFPage page = document.Pages.Add(); string[] textAnnotationNames = new string[] { "Comment", "Check", "Circle", "Cross", "Help", "Insert", "Key", "NewParagraph", "Note", "Paragraph", "RightArrow", "RightPointer", "Star", "UpArrow", "UpLeftArrow" }; page.Canvas.DrawString("B/W text annotations", font, blackBrush, 50, 50); for (int i = 0; i < textAnnotationNames.Length; i++) { PDFTextAnnotation ta = new PDFTextAnnotation(); ta.Author = "O2S.Components.PDF4NET"; ta.Contents = "I am a " + textAnnotationNames[i] + " annotation."; ta.IconName = textAnnotationNames[i]; page.Annotations.Add(ta); ta.Location = new PDFPoint(50, 100 + 40 * i); page.Canvas.DrawString(textAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i); } Random rnd = new Random(); byte[] rgb = new byte[3]; page.Canvas.DrawString("Color text annotations", font, blackBrush, 300, 50); for (int i = 0; i < textAnnotationNames.Length; i++) { PDFTextAnnotation ta = new PDFTextAnnotation(); ta.Author = "O2S.Components.PDF4NET"; ta.Contents = "I am a " + textAnnotationNames[i] + " annotation."; ta.IconName = textAnnotationNames[i]; rnd.NextBytes(rgb); ta.OutlineColor = new PDFRgbColor(rgb[0], rgb[1], rgb[2]); rnd.NextBytes(rgb); ta.InteriorColor = new PDFRgbColor(rgb[0], rgb[1], rgb[2]); page.Annotations.Add(ta); ta.Location = new PDFPoint(300, 100 + 40 * i); page.Canvas.DrawString(textAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i); } page.Canvas.DrawString("Text annotations with custom icons", font, blackBrush, 50, 700); PDFTextAnnotation customTextAnnotation = new PDFTextAnnotation(); customTextAnnotation.Author = "O2S.Components.PDF4NET"; customTextAnnotation.Contents = "Text annotation with custom icon."; page.Annotations.Add(customTextAnnotation); customTextAnnotation.IconName = "Custom icon appearance"; customTextAnnotation.Location = new PDFPoint(50, 720); PDFAnnotationAppearance customAppearance = new PDFAnnotationAppearance(50, 50); PDFPen redPen = new PDFPen(new PDFRgbColor(255, 0, 0), 10); PDFPen bluePen = new PDFPen(new PDFRgbColor(0, 0, 192), 10); customAppearance.Canvas.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Canvas.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Canvas.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Canvas.CompressAndClose(); customTextAnnotation.NormalAppearance = customAppearance; }
private static void Create3DAnnotations(PDFFixedDocument document, PDFFont font, Stream u3dStream) { PDFBrush blackBrush = new PDFBrush(); PDFPage page = document.Pages.Add(); page.Rotation = 90; page.Canvas.DrawString("3D annotations", font, blackBrush, 50, 50); byte[] u3dContent = new byte[u3dStream.Length]; u3dStream.Read(u3dContent, 0, u3dContent.Length); PDF3DView view0 = new PDF3DView(); view0.CameraToWorldMatrix = new double[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, -0.417542, -0.881257, -0.125705 }; view0.CenterOfOrbit = 0.123106; view0.ExternalName = "Default"; view0.InternalName = "Default"; view0.Projection = new PDF3DProjection(); view0.Projection.FieldOfView = 30; PDF3DView view1 = new PDF3DView(); view1.CameraToWorldMatrix = new double[] { -0.999888, 0.014949, 0, 0.014949, 0.999887, 0.00157084, 0.0000234825, 0.00157066, -0.999999, -0.416654, -0.761122, -0.00184508 }; view1.CenterOfOrbit = 0.123106; view1.ExternalName = "Top"; view1.InternalName = "Top"; view1.Projection = new PDF3DProjection(); view1.Projection.FieldOfView = 14.8096; PDF3DView view2 = new PDF3DView(); view2.CameraToWorldMatrix = new double[] { -1.0, -0.0000411671, 0.0000000000509201, -0.00000101387, 0.0246288, 0.999697, -0.0000411546, 0.999697, -0.0246288, -0.417072, -0.881787, -0.121915 }; view2.CenterOfOrbit = 0.123106; view2.ExternalName = "Side"; view2.InternalName = "Side"; view2.Projection = new PDF3DProjection(); view2.Projection.FieldOfView = 12.3794; PDF3DView view3 = new PDF3DView(); view3.CameraToWorldMatrix = new double[] { -0.797002, -0.603977, -0.0000000438577, -0.294384, 0.388467, 0.873173, -0.527376, 0.695921, -0.48741, -0.3518, -0.844506, -0.0675629 }; view3.CenterOfOrbit = 0.123106; view3.ExternalName = "Isometric"; view3.InternalName = "Isometric"; view3.Projection = new PDF3DProjection(); view3.Projection.FieldOfView = 15.1226; PDF3DView view4 = new PDF3DView(); view4.CameraToWorldMatrix = new double[] { 0.00737633, -0.999973, -0.0000000000147744, -0.0656414, -0.000484206, 0.997843, -0.997816, -0.00736042, -0.0656432, -0.293887, -0.757928, -0.119485 }; view4.CenterOfOrbit = 0.123106; view4.ExternalName = "Front"; view4.InternalName = "Front"; view4.Projection = new PDF3DProjection(); view4.Projection.FieldOfView = 15.1226; PDF3DView view5 = new PDF3DView(); view5.CameraToWorldMatrix = new double[] { 0.0151008, 0.999886, 0.0000000000261366, 0.0492408, -0.000743662, 0.998787, 0.998673, -0.0150825, -0.0492464, -0.540019, -0.756862, -0.118884 }; view5.CenterOfOrbit = 0.123106; view5.ExternalName = "Back"; view5.InternalName = "Back"; view5.Projection = new PDF3DProjection(); view5.Projection.FieldOfView = 12.3794; PDF3DStream _3dStream = new PDF3DStream(); _3dStream.Views.Add(view0); _3dStream.Views.Add(view1); _3dStream.Views.Add(view2); _3dStream.Views.Add(view3); _3dStream.Views.Add(view4); _3dStream.Views.Add(view5); _3dStream.Content = u3dContent; _3dStream.DefaultViewIndex = 0; PDF3DAnnotation _3da = new PDF3DAnnotation(); _3da.Stream = _3dStream; PDFAnnotationAppearance appearance = new PDFAnnotationAppearance(200, 200); appearance.Canvas.DrawString("Click to activate", font, blackBrush, 50, 50); _3da.NormalAppearance = appearance; page.Annotations.Add(_3da); _3da.DisplayRectangle = new PDFDisplayRectangle(36, 36, 720, 540); PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions(); sao.Font = font; sao.Brush = blackBrush; PDFStringLayoutOptions slo = new PDFStringLayoutOptions(); slo.Y = 585 + 18 / 2; slo.HorizontalAlign = PDFStringHorizontalAlign.Center; slo.VerticalAlign = PDFStringVerticalAlign.Middle; PDFPen blackPen = new PDFPen(new PDFRgbColor(0, 0, 0), 1); page.Canvas.DrawRectangle(blackPen, 50, 585, 120, 18); slo.X = 50 + 120 / 2; page.Canvas.DrawString("Top", sao, slo); PDFGoTo3DViewAction gotoTopView = new PDFGoTo3DViewAction(); gotoTopView.ViewIndex = 1; gotoTopView.TargetAnnotation = _3da; PDFLinkAnnotation linkGotoTopView = new PDFLinkAnnotation(); page.Annotations.Add(linkGotoTopView); linkGotoTopView.DisplayRectangle = new PDFDisplayRectangle(50, 585, 120, 18); linkGotoTopView.Action = gotoTopView; page.Canvas.DrawRectangle(blackPen, 190, 585, 120, 18); slo.X = 190 + 120 / 2; page.Canvas.DrawString("Side", sao, slo); PDFGoTo3DViewAction gotoSideView = new PDFGoTo3DViewAction(); gotoSideView.ViewIndex = 2; gotoSideView.TargetAnnotation = _3da; PDFLinkAnnotation linkGotoSideView = new PDFLinkAnnotation(); page.Annotations.Add(linkGotoSideView); linkGotoSideView.DisplayRectangle = new PDFDisplayRectangle(190, 585, 120, 18); linkGotoSideView.Action = gotoSideView; page.Canvas.DrawRectangle(blackPen, 330, 585, 120, 18); slo.X = 330 + 120 / 2; page.Canvas.DrawString("Isometric", sao, slo); PDFGoTo3DViewAction gotoIsometricView = new PDFGoTo3DViewAction(); gotoIsometricView.ViewIndex = 3; gotoIsometricView.TargetAnnotation = _3da; PDFLinkAnnotation linkGotoIsometricView = new PDFLinkAnnotation(); page.Annotations.Add(linkGotoIsometricView); linkGotoIsometricView.DisplayRectangle = new PDFDisplayRectangle(330, 585, 120, 18); linkGotoIsometricView.Action = gotoIsometricView; page.Canvas.DrawRectangle(blackPen, 470, 585, 120, 18); slo.X = 470 + 120 / 2; page.Canvas.DrawString("Front", sao, slo); PDFGoTo3DViewAction gotoFrontView = new PDFGoTo3DViewAction(); gotoFrontView.ViewIndex = 4; gotoFrontView.TargetAnnotation = _3da; PDFLinkAnnotation linkGotoFrontView = new PDFLinkAnnotation(); page.Annotations.Add(linkGotoFrontView); linkGotoFrontView.DisplayRectangle = new PDFDisplayRectangle(470, 585, 120, 18); linkGotoFrontView.Action = gotoFrontView; page.Canvas.DrawRectangle(blackPen, 610, 585, 120, 18); slo.X = 610 + 120 / 2; page.Canvas.DrawString("Back", sao, slo); PDFGoTo3DViewAction gotoBackView = new PDFGoTo3DViewAction(); gotoBackView.ViewIndex = 5; gotoBackView.TargetAnnotation = _3da; PDFLinkAnnotation linkGotoBackView = new PDFLinkAnnotation(); page.Annotations.Add(linkGotoBackView); linkGotoBackView.DisplayRectangle = new PDFDisplayRectangle(610, 585, 120, 18); linkGotoBackView.Action = gotoBackView; }
private static void CreateFileAttachmentAnnotations(PDFFixedDocument document, PDFFont font) { PDFBrush blackBrush = new PDFBrush(); Random rnd = new Random(); // Random binary data to be used a file content for file attachment annotations. byte[] fileData = new byte[256]; PDFPage page = document.Pages.Add(); string[] fileAttachmentAnnotationNames = new string[] { "Graph", "Paperclip", "PushPin", "Tag" }; page.Canvas.DrawString("B/W file attachment annotations", font, blackBrush, 50, 50); for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++) { rnd.NextBytes(fileData); PDFFileAttachmentAnnotation faa = new PDFFileAttachmentAnnotation(); faa.Author = "O2S.Components.PDF4NET"; faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation."; faa.IconName = fileAttachmentAnnotationNames[i]; faa.Payload = fileData; faa.FileName = "BlackAndWhite" + fileAttachmentAnnotationNames[i] + "dat"; page.Annotations.Add(faa); faa.Location = new PDFPoint(50, 100 + 40 * i); page.Canvas.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i); } byte[] rgb = new byte[3]; page.Canvas.DrawString("Color file attachment annotations", font, blackBrush, 300, 50); for (int i = 0; i < fileAttachmentAnnotationNames.Length; i++) { rnd.NextBytes(fileData); PDFFileAttachmentAnnotation faa = new PDFFileAttachmentAnnotation(); faa.Author = "O2S.Components.PDF4NET"; faa.Contents = "I am a " + fileAttachmentAnnotationNames[i] + " annotation."; faa.IconName = fileAttachmentAnnotationNames[i]; faa.Payload = fileData; faa.FileName = "Color" + fileAttachmentAnnotationNames[i] + "dat"; rnd.NextBytes(rgb); faa.OutlineColor = new PDFRgbColor(rgb[0], rgb[1], rgb[2]); rnd.NextBytes(rgb); faa.InteriorColor = new PDFRgbColor(rgb[0], rgb[1], rgb[2]); page.Annotations.Add(faa); faa.Location = new PDFPoint(300, 100 + 40 * i); page.Canvas.DrawString(fileAttachmentAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i); } page.Canvas.DrawString("File attachment annotations with custom icons", font, blackBrush, 50, 700); PDFFileAttachmentAnnotation customFileAttachmentAnnotation = new PDFFileAttachmentAnnotation(); customFileAttachmentAnnotation.Author = "O2S.Components.PDF4NET"; customFileAttachmentAnnotation.Contents = "File attachment annotation with custom icon."; page.Annotations.Add(customFileAttachmentAnnotation); customFileAttachmentAnnotation.IconName = "Custom icon appearance"; customFileAttachmentAnnotation.Location = new PDFPoint(50, 720); PDFAnnotationAppearance customAppearance = new PDFAnnotationAppearance(50, 50); PDFPen redPen = new PDFPen(new PDFRgbColor(255, 0, 0), 10); PDFPen bluePen = new PDFPen(new PDFRgbColor(0, 0, 192), 10); customAppearance.Canvas.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Canvas.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Canvas.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Canvas.CompressAndClose(); customFileAttachmentAnnotation.NormalAppearance = customAppearance; }