protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); Rectangle rect = new Rectangle(150, 770, 50, 50); PdfAnnotation annotation = new PdfCircleAnnotation(rect) .SetBorderStyle(PdfAnnotation.STYLE_DASHED) .SetDashPattern(new PdfArray(new int[] { 3, 2 })) // This method sets the text that will be displayed for the annotation or the alternate description, // if this type of annotation does not display text. .SetContents("Circle") .SetTitle(new PdfString("Circle")) .SetColor(ColorConstants.BLUE) // Set to print the annotation when the page is printed .SetFlags(PdfAnnotation.PRINT) .SetBorder(new PdfArray(new float[] { 0, 0, 2 })) // Set the interior color .Put(PdfName.IC, new PdfArray(new int[] { 1, 0, 0 })); pdfDoc.GetFirstPage().AddAnnotation(annotation); pdfDoc.Close(); }
public virtual void CreatePDF(String dest) { PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); // רע ומר היה להם ליהודים String text = "\u05E8\u05E2\u0020\u05D5\u05DE\u05E8\u0020\u05D4\u05D9\u05D4\u0020\u05DC\u05D4\u05DD" + "\u0020\u05DC\u05D9\u05D4\u05D5\u05D3\u05D9\u05DD"; // Create a rectangle for an annotation Rectangle rectangleAnnot = new Rectangle(55, 750, 35, 35); // Create the annotation, set its contents and color PdfAnnotation annotation = new PdfCircleAnnotation(rectangleAnnot); annotation .SetContents(text) .SetColor(ColorConstants.MAGENTA); // Add an empty page to the document, then add the annotation to the page PdfPage page = pdfDocument.AddNewPage(); page.AddAnnotation(annotation); pdfDocument.Close(); }
public virtual void CreatePDF(String dest) { PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); // പദസൂചികഒരു String text = "\u0D2A\u0D26\u0D38\u0D42\u0D1A\u0D3F\u0D15\u0D12\u0D30\u0D41"; // Create a rectangle for an annotation Rectangle rectangleAnnot = new Rectangle(55, 750, 35, 35); // Create the annotation, set its contents and color PdfAnnotation annotation = new PdfCircleAnnotation(rectangleAnnot); annotation .SetContents(text) .SetColor(ColorConstants.MAGENTA); // Add an empty page to the document, then add the annotation to the page PdfPage page = pdfDocument.AddNewPage(); page.AddAnnotation(annotation); pdfDocument.Close(); }
public virtual void CreatePDF(String dest) { PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); // ਸਾਰੇ ਇਨਸਾਨ String text = "\u0A38\u0A3E\u0A30\u0A47\u0020\u0A07\u0A28\u0A38\u0A3E\u0A28"; // Create a rectangle for an annotation Rectangle rectangleAnnot = new Rectangle(55, 750, 35, 35); // Create the annotation, set its contents and color PdfAnnotation annotation = new PdfCircleAnnotation(rectangleAnnot); annotation .SetContents(text) .SetColor(ColorConstants.MAGENTA); // Add an empty page to the document, then add the annotation to the page PdfPage page = pdfDocument.AddNewPage(); page.AddAnnotation(annotation); pdfDocument.Close(); }
public virtual void CreatePDF(String dest) { PdfDocument pdfDocument = new PdfDocument(new PdfWriter(dest)); // ភាសាខ្មែរ String text = "\u1797\u17B6\u179F\u17B6\u1781\u17D2\u1798\u17C2\u179A"; // Create a rectangle for an annotation Rectangle rectangleAnnot = new Rectangle(55, 750, 35, 35); // Create the annotation, set its contents and color PdfAnnotation annotation = new PdfCircleAnnotation(rectangleAnnot); annotation .SetContents(text) .SetColor(ColorConstants.MAGENTA); // Add an empty page to the document, then add the annotation to the page PdfPage page = pdfDocument.AddNewPage(); page.AddAnnotation(annotation); pdfDocument.Close(); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> //protected override void OnNavigatedTo(NavigationEventArgs e) //{ //} private async void Button_Click_1(object sender, RoutedEventArgs e) { //Create a new PDF document PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); document.PageSettings.SetMargins(0); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f); PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0)); string text = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base."; page.Graphics.DrawString("Annotation with Comments and Reviews", font, brush, new PointF(30, 10)); page.Graphics.DrawString(text, font, brush, new RectangleF(30, 40, page.GetClientSize().Width - 60, 60)); string markupText = "North American, European and Asian commercial markets"; PdfTextMarkupAnnotation textMarkupAnnot = new PdfTextMarkupAnnotation("sample", "Highlight", markupText, new PointF(147, 63.5f), font); textMarkupAnnot.Author = "Annotation"; textMarkupAnnot.Opacity = 1.0f; textMarkupAnnot.Subject = "Comments and Reviews"; textMarkupAnnot.ModifiedDate = new DateTime(2015, 1, 18); textMarkupAnnot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight; textMarkupAnnot.TextMarkupColor = new PdfColor(System.Drawing.Color.Yellow); textMarkupAnnot.InnerColor = new PdfColor(System.Drawing.Color.Red); textMarkupAnnot.Color = new PdfColor(System.Drawing.Color.Yellow); if (flatten.IsChecked == true) { textMarkupAnnot.Flatten = true; } //Create a new comment. PdfPopupAnnotation userQuery = new PdfPopupAnnotation(); userQuery.Author = "John"; userQuery.Text = "Can you please change South Asian to Asian?"; userQuery.ModifiedDate = new DateTime(2015, 1, 18); //Add comment to the annotation textMarkupAnnot.Comments.Add(userQuery); //Creates a new comment PdfPopupAnnotation userAnswer = new PdfPopupAnnotation(); userAnswer.Author = "Smith"; userAnswer.Text = "South Asian has changed as Asian"; userAnswer.ModifiedDate = new DateTime(2015, 1, 18); //Add comment to the annotation textMarkupAnnot.Comments.Add(userAnswer); //Creates a new review PdfPopupAnnotation userAnswerReview = new PdfPopupAnnotation(); userAnswerReview.Author = "Smith"; userAnswerReview.State = PdfAnnotationState.Completed; userAnswerReview.StateModel = PdfAnnotationStateModel.Review; userAnswerReview.ModifiedDate = new DateTime(2015, 1, 18); //Add review to the comment userAnswer.ReviewHistory.Add(userAnswerReview); //Creates a new review PdfPopupAnnotation userAnswerReviewJohn = new PdfPopupAnnotation(); userAnswerReviewJohn.Author = "John"; userAnswerReviewJohn.State = PdfAnnotationState.Accepted; userAnswerReviewJohn.StateModel = PdfAnnotationStateModel.Review; userAnswerReviewJohn.ModifiedDate = new DateTime(2015, 1, 18); //Add review to the comment userAnswer.ReviewHistory.Add(userAnswerReviewJohn); //Add annotation to the page page.Annotations.Add(textMarkupAnnot); RectangleF bounds = new RectangleF(350, 170, 80, 80); //Creates a new Circle annotation. PdfCircleAnnotation circleannotation = new PdfCircleAnnotation(bounds); circleannotation.InnerColor = new PdfColor(System.Drawing.Color.Yellow); circleannotation.Color = new PdfColor(System.Drawing.Color.Red); circleannotation.AnnotationFlags = PdfAnnotationFlags.Default; circleannotation.Author = "Syncfusion"; circleannotation.Subject = "CircleAnnotation"; circleannotation.ModifiedDate = new DateTime(2015, 1, 18); page.Annotations.Add(circleannotation); page.Graphics.DrawString("Circle Annotation", font, brush, new PointF(350, 130)); //Creates a new Ellipse annotation. PdfEllipseAnnotation ellipseannotation = new PdfEllipseAnnotation(new RectangleF(30, 150, 50, 100), "Ellipse Annotation"); ellipseannotation.Color = new PdfColor(System.Drawing.Color.Red); ellipseannotation.InnerColor = new PdfColor(System.Drawing.Color.Yellow); page.Graphics.DrawString("Ellipse Annotation", font, brush, new PointF(30, 130)); page.Annotations.Add(ellipseannotation); //Creates a new Square annotation. PdfSquareAnnotation squareannotation = new PdfSquareAnnotation(new RectangleF(30, 300, 80, 80)); squareannotation.Text = "SquareAnnotation"; squareannotation.InnerColor = new PdfColor(System.Drawing.Color.Red); squareannotation.Color = new PdfColor(System.Drawing.Color.Yellow); page.Graphics.DrawString("Square Annotation", font, brush, new PointF(30, 280)); page.Annotations.Add(squareannotation); //Creates a new Rectangle annotation. RectangleF rectannot = new RectangleF(350, 320, 100, 50); PdfRectangleAnnotation rectangleannotation = new PdfRectangleAnnotation(rectannot, "RectangleAnnotation"); rectangleannotation.InnerColor = new PdfColor(System.Drawing.Color.Red); rectangleannotation.Color = new PdfColor(System.Drawing.Color.Yellow); page.Graphics.DrawString("Rectangle Annotation", font, brush, new PointF(350, 280)); page.Annotations.Add(rectangleannotation); //Creates a new Line annotation. int[] points = new int[] { 400, 350, 550, 350 }; PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annoation is the one of the annotation type..."); lineAnnotation.Author = "Syncfusion"; lineAnnotation.Subject = "LineAnnotation"; lineAnnotation.ModifiedDate = new DateTime(2015, 1, 18); lineAnnotation.Text = "PdfLineAnnotation"; lineAnnotation.BackColor = new PdfColor(System.Drawing.Color.Red); page.Graphics.DrawString("Line Annotation", font, brush, new PointF(400, 420)); page.Annotations.Add(lineAnnotation); //Creates a new Polygon annotation. int[] polypoints = new int[] { 50, 298, 100, 325, 200, 355, 300, 230, 180, 230 }; PdfPolygonAnnotation polygonannotation = new PdfPolygonAnnotation(polypoints, "PolygonAnnotation"); polygonannotation.Bounds = new RectangleF(30, 210, 300, 200); PdfPen pen = new PdfPen(System.Drawing.Color.Red); polygonannotation.Text = "polygon"; polygonannotation.Color = new PdfColor(System.Drawing.Color.Red); polygonannotation.InnerColor = new PdfColor(System.Drawing.Color.LightPink); page.Graphics.DrawString("Polygon Annotation", font, brush, new PointF(50, 420)); page.Annotations.Add(polygonannotation); //Creates a new Freetext annotation. RectangleF freetextrect = new RectangleF(405, 645, 80, 30); PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(freetextrect); freeText.MarkupText = "Free Text with Callouts"; freeText.TextMarkupColor = new PdfColor(System.Drawing.Color.Green); freeText.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); freeText.BorderColor = new PdfColor(System.Drawing.Color.Blue); freeText.Border = new PdfAnnotationBorder(.5f); freeText.AnnotationFlags = PdfAnnotationFlags.Default; freeText.Text = "Free Text"; freeText.Color = new PdfColor(System.Drawing.Color.Yellow); PointF[] Freetextpoints = { new PointF(365, 700), new PointF(379, 654), new PointF(405, 654) }; freeText.CalloutLines = Freetextpoints; page.Graphics.DrawString("FreeText Annotation", font, brush, new PointF(400, 610)); page.Annotations.Add(freeText); //Creates a new Ink annotation. List <float> linePoints = new List <float> { 72.919f, 136.376f, 72.264f, 136.376f, 62.446f, 142.922f, 61.137f, 142.922f, 55.901f, 139.649f, 55.246f, 138.34f, 54.592f, 132.449f, 54.592f, 127.867f, 55.901f, 125.904f, 59.828f, 121.976f, 63.101f, 121.322f, 65.719f, 122.631f, 68.992f, 125.249f, 70.301f, 130.485f, 71.61f, 133.104f, 72.264f, 136.376f, 72.919f, 140.304f, 74.883f, 144.885f, 76.192f, 150.776f, 76.192f, 151.431f, 76.192f, 152.085f, 76.192f, 158.631f, 76.192f, 159.94f, 75.537f, 155.358f, 74.228f, 150.122f, 74.228f, 146.195f, 73.574f, 141.613f, 73.574f, 137.685f, 74.228f, 132.449f, 74.883f, 128.522f, 75.537f, 124.594f, 76.192f, 123.285f, 76.846f, 122.631f, 80.774f, 122.631f, 82.737f, 123.285f, 85.355f, 125.249f, 88.628f, 129.831f, 89.283f, 133.104f, 89.937f, 137.031f, 90.592f, 140.958f, 89.937f, 142.267f, 86.665f, 141.613f, 85.355f, 140.304f, 84.701f, 138.34f, 84.701f, 137.685f, 85.355f, 137.031f, 87.974f, 135.722f, 90.592f, 136.376f, 92.555f, 137.031f, 96.483f, 139.649f, 98.446f, 140.958f, 101.719f, 142.922f, 103.028f, 142.922f, 100.41f, 138.34f, 99.756f, 134.413f, 99.101f, 131.14f, 99.101f, 128.522f, 99.756f, 127.213f, 101.065f, 125.904f, 102.374f, 123.94f, 103.683f, 123.94f, 107.61f, 125.904f, 110.228f, 129.831f, 114.156f, 135.067f, 117.428f, 140.304f, 119.392f, 143.576f, 121.356f, 144.231f, 122.665f, 144.231f, 123.974f, 142.267f, 126.592f, 139.649f, 127.247f, 140.304f, 126.592f, 142.922f, 124.628f, 143.576f, 122.01f, 142.922f, 118.083f, 141.613f, 114.81f, 136.376f, 114.81f, 131.14f, 113.501f, 127.213f, 114.156f, 125.904f, 118.083f, 125.904f, 120.701f, 126.558f, 123.319f, 130.485f, 125.283f, 136.376f, 125.937f, 140.304f, 125.937f, 142.922f, 126.592f, 143.576f, 125.937f, 135.722f, 125.937f, 131.794f, 125.937f, 131.14f, 127.247f, 129.176f, 129.21f, 127.213f, 131.828f, 127.213f, 134.447f, 128.522f, 136.41f, 136.376f, 139.028f, 150.122f, 141.647f, 162.558f, 140.992f, 163.213f, 138.374f, 160.595f, 135.756f, 153.395f, 135.101f, 148.158f, 134.447f, 140.304f, 134.447f, 130.485f, 133.792f, 124.594f, 133.792f, 115.431f, 133.792f, 110.194f, 133.792f, 105.612f, 134.447f, 105.612f, 137.065f, 110.194f, 137.719f, 116.74f, 139.028f, 120.013f, 139.028f, 123.94f, 137.719f, 127.213f, 135.756f, 130.485f, 134.447f, 130.485f, 133.792f, 130.485f, 137.719f, 131.794f, 141.647f, 135.722f, 146.883f, 142.922f, 152.774f, 153.395f, 153.428f, 159.286f, 150.156f, 159.94f, 147.537f, 156.667f, 146.883f, 148.813f, 146.883f, 140.958f, 146.883f, 134.413f, 146.883f, 125.904f, 145.574f, 118.703f, 145.574f, 114.776f, 145.574f, 112.158f, 146.228f, 111.503f, 147.537f, 111.503f, 148.192f, 112.158f, 150.156f, 112.812f, 150.81f, 113.467f, 152.119f, 114.776f, 154.083f, 117.394f, 155.392f, 119.358f, 156.701f, 120.667f, 157.356f, 121.976f, 156.701f, 121.322f, 156.047f, 120.013f, 155.392f, 119.358f, 154.083f, 117.394f, 154.083f, 116.74f, 152.774f, 114.776f, 152.119f, 114.121f, 150.81f, 113.467f, 149.501f, 113.467f, 147.537f, 112.158f, 146.883f, 112.158f, 145.574f, 111.503f, 144.919f, 112.158f, 144.265f, 114.121f, 144.265f, 115.431f, 144.265f, 116.74f, 144.265f, 117.394f, 144.265f, 118.049f, 144.919f, 118.703f, 145.574f, 120.667f, 146.228f, 122.631f, 147.537f, 123.285f, 147.537f, 124.594f, 148.192f, 125.904f, 147.537f, 128.522f, 147.537f, 129.176f, 147.537f, 130.485f, 147.537f, 132.449f, 147.537f, 134.413f, 147.537f, 136.376f, 147.537f, 138.34f, 147.537f, 138.994f, 145.574f, 138.994f, 142.956f, 138.252f }; RectangleF rectangle = new RectangleF(30, 580, 300, 400); PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints); inkAnnotation.Bounds = rectangle; inkAnnotation.Color = new PdfColor(System.Drawing.Color.Red); page.Graphics.DrawString("Ink Annotation", font, brush, new PointF(30, 610)); page.Annotations.Add(inkAnnotation); PdfPage secondPage = document.Pages.Add(); //Creates a new TextMarkup annotation. string s = "This is TextMarkup annotation!!!"; secondPage.Graphics.DrawString(s, font, brush, new PointF(30, 70)); PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation("sample", "Strikeout", s, new PointF(30, 70), font); textannot.Author = "Annotation"; textannot.Opacity = 1.0f; textannot.Subject = "pdftextmarkupannotation"; textannot.ModifiedDate = new DateTime(2015, 1, 18); textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.StrikeOut; textannot.TextMarkupColor = new PdfColor(System.Drawing.Color.Yellow); textannot.InnerColor = new PdfColor(System.Drawing.Color.Red); textannot.Color = new PdfColor(System.Drawing.Color.Yellow); if (flatten.IsChecked == true) { textannot.Flatten = true; } secondPage.Graphics.DrawString("TextMarkup Annotation", font, brush, new PointF(30, 40)); secondPage.Annotations.Add(textannot); //Creates a new popup annotation. RectangleF popupRect = new RectangleF(430, 70, 30, 30); PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(); popupAnnotation.Border.Width = 4; popupAnnotation.Border.HorizontalRadius = 20; popupAnnotation.Border.VerticalRadius = 30; popupAnnotation.Opacity = 1; popupAnnotation.Open = true; popupAnnotation.Text = "Popup Annotation"; popupAnnotation.Color = System.Drawing.Color.Green; popupAnnotation.InnerColor = System.Drawing.Color.Blue; popupAnnotation.Bounds = popupRect; if (flatten.IsChecked == true) { popupAnnotation.FlattenPopUps = true; popupAnnotation.Flatten = true; } secondPage.Graphics.DrawString("Popup Annotation", font, brush, new PointF(400, 40)); secondPage.Annotations.Add(popupAnnotation); //Creates a new Line measurement annotation. points = new int[] { 400, 630, 550, 630 }; PdfLineMeasurementAnnotation lineMeasureAnnot = new PdfLineMeasurementAnnotation(points); lineMeasureAnnot.Author = "Syncfusion"; lineMeasureAnnot.Subject = "LineAnnotation"; lineMeasureAnnot.ModifiedDate = new DateTime(2015, 1, 18); lineMeasureAnnot.Unit = PdfMeasurementUnit.Inch; lineMeasureAnnot.lineBorder.BorderWidth = 2; lineMeasureAnnot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular); lineMeasureAnnot.Color = new PdfColor(System.Drawing.Color.Red); if (flatten.IsChecked == true) { lineMeasureAnnot.Flatten = true; } secondPage.Graphics.DrawString("Line Measurement Annotation", font, brush, new PointF(370, 130)); secondPage.Annotations.Add(lineMeasureAnnot); //Creates a new Freetext annotation. RectangleF freetextrect0 = new RectangleF(80, 160, 100, 50); PdfFreeTextAnnotation freeText0 = new PdfFreeTextAnnotation(freetextrect0); freeText0.MarkupText = "Free Text with Callouts"; freeText0.TextMarkupColor = new PdfColor(System.Drawing.Color.Green); freeText0.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); freeText0.BorderColor = new PdfColor(System.Drawing.Color.Blue); freeText0.Border = new PdfAnnotationBorder(.5f); freeText0.AnnotationFlags = PdfAnnotationFlags.Default; freeText0.Text = "Free Text"; freeText0.Rotate = PdfAnnotationRotateAngle.RotateAngle90; freeText0.Color = new PdfColor(System.Drawing.Color.Yellow); PointF[] Freetextpoints0 = { new PointF(45, 220), new PointF(60, 175), new PointF(80, 175) }; freeText0.CalloutLines = Freetextpoints0; secondPage.Graphics.DrawString("Rotated FreeText Annotation", font, brush, new PointF(40, 130)); if (flatten.IsChecked == true) { freeText0.Flatten = true; } secondPage.Annotations.Add(freeText0); PdfRectangleAnnotation cloudannotation = new PdfRectangleAnnotation(new RectangleF(30, 300, 100, 50), "Rectangle Cloud Annoatation"); cloudannotation.Border.BorderWidth = 1; cloudannotation.Color = System.Drawing.Color.Red; cloudannotation.InnerColor = System.Drawing.Color.Blue; PdfBorderEffect bordereffect = new PdfBorderEffect(); bordereffect.Intensity = 2; bordereffect.Style = PdfBorderEffectStyle.Cloudy; cloudannotation.BorderEffect = bordereffect; secondPage.Graphics.DrawString("Cloud Annotation", font, brush, new PointF(40, 260)); secondPage.Annotations.Add(cloudannotation); if (flatten.IsChecked == false) { PdfRedactionAnnotation redactionannot = new PdfRedactionAnnotation(); redactionannot.Bounds = new RectangleF(350, 300, 100, 50); redactionannot.Text = "Redaction Annotation"; redactionannot.InnerColor = System.Drawing.Color.Orange; redactionannot.BorderColor = System.Drawing.Color.Red; redactionannot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 13); redactionannot.TextColor = System.Drawing.Color.Green; redactionannot.OverlayText = "REDACTED"; redactionannot.RepeatText = true; redactionannot.TextAlignment = PdfTextAlignment.Left; redactionannot.SetAppearance(true); secondPage.Graphics.DrawString("Redaction Annotation", font, brush, new PointF(350, 260)); secondPage.Annotations.Add(redactionannot); } //Saving the document MemoryStream SourceStream = new MemoryStream(); document.Save(SourceStream); document.Close(true); //Loading and flatten the annotation PdfLoadedDocument lDoc = new PdfLoadedDocument(SourceStream); PdfLoadedPage lpage1 = lDoc.Pages[0] as PdfLoadedPage; PdfLoadedPage lpage2 = lDoc.Pages[1] as PdfLoadedPage; if (flatten.IsChecked == true) { lpage1.Annotations.Flatten = true; lpage2.Annotations.Flatten = true; } MemoryStream stream = new MemoryStream(); await lDoc.SaveAsync(stream); lDoc.Close(true); Save(stream, "Sample.pdf"); }
private static void CreateSquareCircleAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Square annotations", font, blackBrush, 50, 50); PdfSquareAnnotation square1 = new PdfSquareAnnotation(); page.Annotations.Add(square1); square1.Author = "Xfinium.pdf"; square1.Contents = "Square annotation with red border"; square1.BorderColor = new PdfRgbColor(255, 0, 0); square1.BorderWidth = 3; square1.VisualRectangle = new PdfVisualRectangle(50, 70, 250, 150); PdfSquareAnnotation square2 = new PdfSquareAnnotation(); page.Annotations.Add(square2); square2.Author = "Xfinium.pdf"; square2.Contents = "Square annotation with blue interior"; square2.BorderColor = null; square2.BorderWidth = 0; square2.InteriorColor = new PdfRgbColor(0, 0, 192); square2.VisualRectangle = new PdfVisualRectangle(50, 270, 250, 150); PdfSquareAnnotation square3 = new PdfSquareAnnotation(); page.Annotations.Add(square3); square3.Author = "Xfinium.pdf"; square3.Contents = "Square annotation with yellow border and green interior"; square3.BorderColor = new PdfRgbColor(255, 255, 0); square3.BorderWidth = 3; square3.InteriorColor = new PdfRgbColor(0, 192, 0); square3.VisualRectangle = new PdfVisualRectangle(50, 470, 250, 150); page.Graphics.DrawString("Circle annotations", font, blackBrush, 50, 350); PdfCircleAnnotation circle1 = new PdfCircleAnnotation(); page.Annotations.Add(circle1); circle1.Author = "Xfinium.pdf"; circle1.Contents = "Circle annotation with red border"; circle1.BorderColor = new PdfRgbColor(255, 0, 0); circle1.BorderWidth = 3; circle1.VisualRectangle = new PdfVisualRectangle(350, 70, 250, 150); PdfCircleAnnotation circle2 = new PdfCircleAnnotation(); page.Annotations.Add(circle2); circle2.Author = "Xfinium.pdf"; circle2.Contents = "Circle annotation with blue interior"; circle2.BorderColor = null; circle2.BorderWidth = 0; circle2.InteriorColor = new PdfRgbColor(0, 0, 192); circle2.VisualRectangle = new PdfVisualRectangle(350, 270, 250, 150); PdfCircleAnnotation circle3 = new PdfCircleAnnotation(); page.Annotations.Add(circle3); circle3.Author = "Xfinium.pdf"; circle3.Contents = "Circle annotation with yellow border and green interior"; circle3.BorderColor = new PdfRgbColor(255, 255, 0); circle3.BorderWidth = 3; circle3.InteriorColor = new PdfRgbColor(0, 192, 0); circle3.VisualRectangle = new PdfVisualRectangle(350, 470, 250, 150); }
public ActionResult AnnotationFlatten(string InsideBrowser, string checkboxFlatten) { //Creates a new PDF document. PdfDocument document = new PdfDocument(); //Creates a new page PdfPage page = document.Pages.Add(); document.PageSettings.SetMargins(0); //Create new PDF color PdfColor blackColor = new PdfColor(0, 0, 0); RectangleF bounds = new RectangleF(350, 50, 80, 80); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f); PdfBrush brush = new PdfSolidBrush(blackColor); //Creates a new Circle annotation. PdfCircleAnnotation circleannotation = new PdfCircleAnnotation(bounds); circleannotation.InnerColor = new PdfColor(Color.Yellow); circleannotation.Color = new PdfColor(Color.Red); circleannotation.AnnotationFlags = PdfAnnotationFlags.Default; circleannotation.Author = "Syncfusion"; circleannotation.Subject = "CircleAnnotation"; circleannotation.ModifiedDate = new DateTime(2015, 1, 18); page.Annotations.Add(circleannotation); page.Graphics.DrawString("Circle Annotation", font, brush, new PointF(350, 10)); //Creates a new Ellipse annotation. PdfEllipseAnnotation ellipseannotation = new PdfEllipseAnnotation(new RectangleF(30, 30, 50, 100), "Ellipse Annotation"); ellipseannotation.Color = new PdfColor(Color.Red); ellipseannotation.InnerColor = new PdfColor(Color.Yellow); page.Graphics.DrawString("Ellipse Annotation", font, brush, new PointF(30, 10)); page.Annotations.Add(ellipseannotation); //Creates a new Square annotation. PdfSquareAnnotation squareannotation = new PdfSquareAnnotation(new RectangleF(30, 200, 80, 80)); squareannotation.Text = "SquareAnnotation"; squareannotation.InnerColor = new PdfColor(Color.Red); squareannotation.Color = new PdfColor(Color.Yellow); page.Graphics.DrawString("Square Annotation", font, brush, new PointF(30, 180)); page.Annotations.Add(squareannotation); //Creates a new Rectangle annotation. RectangleF rectannot = new RectangleF(350, 220, 100, 50); PdfRectangleAnnotation rectangleannotation = new PdfRectangleAnnotation(rectannot, "RectangleAnnotation"); rectangleannotation.InnerColor = new PdfColor(Color.Red); rectangleannotation.Color = new PdfColor(Color.Yellow); page.Graphics.DrawString("Rectangle Annotation", font, brush, new PointF(350, 180)); page.Annotations.Add(rectangleannotation); //Creates a new Line annotation. int[] points = new int[] { 400, 450, 550, 450 }; PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annoation is the one of the annotation type..."); lineAnnotation.Author = "Syncfusion"; lineAnnotation.Subject = "LineAnnotation"; lineAnnotation.ModifiedDate = new DateTime(2015, 1, 18); lineAnnotation.Text = "PdfLineAnnotation"; lineAnnotation.BackColor = new PdfColor(Color.Red); page.Graphics.DrawString("Line Annotation", font, brush, new PointF(400, 320)); page.Annotations.Add(lineAnnotation); //Creates a new Polygon annotation. int[] polypoints = new int[] { 50, 398, 100, 425, 200, 455, 300, 330, 180, 330 }; PdfPolygonAnnotation polygonannotation = new PdfPolygonAnnotation(polypoints, "PolygonAnnotation"); polygonannotation.Bounds = new RectangleF(30, 350, 300, 200); PdfPen pen = new PdfPen(Color.Red); polygonannotation.Text = "polygon"; polygonannotation.Color = new PdfColor(Color.Red); polygonannotation.InnerColor = new PdfColor(Color.LightPink); page.Graphics.DrawString("Polygon Annotation", font, brush, new PointF(50, 320)); page.Annotations.Add(polygonannotation); //Creates a new Freetext annotation. RectangleF freetextrect = new RectangleF(405, 525, 80, 30); PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(freetextrect); freeText.MarkupText = "Free Text with Callouts"; freeText.TextMarkupColor = new PdfColor(Color.Green); freeText.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); freeText.BorderColor = new PdfColor(Color.Blue); freeText.Border = new PdfAnnotationBorder(.5f); freeText.AnnotationFlags = PdfAnnotationFlags.Default; freeText.Text = "Free Text"; freeText.Color = new PdfColor(Color.Yellow); PointF[] Freetextpoints = { new PointF(365, 580), new PointF(379, 534), new PointF(405, 534) }; freeText.CalloutLines = Freetextpoints; page.Graphics.DrawString("FreeText Annotation", font, brush, new PointF(400, 510)); page.Annotations.Add(freeText); //Creates a new TextMarkup annotation. string s = "This is TextMarkup annotation!!!"; RectangleF Textmarkuprect = new RectangleF(30, 540, 200, 20); page.Graphics.DrawString(s, font, brush, new PointF(30, 540)); PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation("sample", "Highlight", s, new PointF(70, 580), font); textannot.Author = "Annotation"; textannot.Opacity = 1.0f; textannot.Subject = "pdftextmarkupannotation"; textannot.ModifiedDate = new DateTime(2015, 1, 18); textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.StrikeOut; textannot.TextMarkupColor = new PdfColor(Color.Yellow); textannot.InnerColor = new PdfColor(Color.Red); textannot.Color = new PdfColor(Color.Yellow); page.Graphics.DrawString("TextMarkup Annotation", font, brush, new PointF(30, 510)); page.Annotations.Add(textannot); //Creates a new Ink annotation. List <float> linePoints = new List <float> { 72.919f, 136.376f, 72.264f, 136.376f, 62.446f, 142.922f, 61.137f, 142.922f, 55.901f, 139.649f, 55.246f, 138.34f, 54.592f, 132.449f, 54.592f, 127.867f, 55.901f, 125.904f, 59.828f, 121.976f, 63.101f, 121.322f, 65.719f, 122.631f, 68.992f, 125.249f, 70.301f, 130.485f, 71.61f, 133.104f, 72.264f, 136.376f, 72.919f, 140.304f, 74.883f, 144.885f, 76.192f, 150.776f, 76.192f, 151.431f, 76.192f, 152.085f, 76.192f, 158.631f, 76.192f, 159.94f, 75.537f, 155.358f, 74.228f, 150.122f, 74.228f, 146.195f, 73.574f, 141.613f, 73.574f, 137.685f, 74.228f, 132.449f, 74.883f, 128.522f, 75.537f, 124.594f, 76.192f, 123.285f, 76.846f, 122.631f, 80.774f, 122.631f, 82.737f, 123.285f, 85.355f, 125.249f, 88.628f, 129.831f, 89.283f, 133.104f, 89.937f, 137.031f, 90.592f, 140.958f, 89.937f, 142.267f, 86.665f, 141.613f, 85.355f, 140.304f, 84.701f, 138.34f, 84.701f, 137.685f, 85.355f, 137.031f, 87.974f, 135.722f, 90.592f, 136.376f, 92.555f, 137.031f, 96.483f, 139.649f, 98.446f, 140.958f, 101.719f, 142.922f, 103.028f, 142.922f, 100.41f, 138.34f, 99.756f, 134.413f, 99.101f, 131.14f, 99.101f, 128.522f, 99.756f, 127.213f, 101.065f, 125.904f, 102.374f, 123.94f, 103.683f, 123.94f, 107.61f, 125.904f, 110.228f, 129.831f, 114.156f, 135.067f, 117.428f, 140.304f, 119.392f, 143.576f, 121.356f, 144.231f, 122.665f, 144.231f, 123.974f, 142.267f, 126.592f, 139.649f, 127.247f, 140.304f, 126.592f, 142.922f, 124.628f, 143.576f, 122.01f, 142.922f, 118.083f, 141.613f, 114.81f, 136.376f, 114.81f, 131.14f, 113.501f, 127.213f, 114.156f, 125.904f, 118.083f, 125.904f, 120.701f, 126.558f, 123.319f, 130.485f, 125.283f, 136.376f, 125.937f, 140.304f, 125.937f, 142.922f, 126.592f, 143.576f, 125.937f, 135.722f, 125.937f, 131.794f, 125.937f, 131.14f, 127.247f, 129.176f, 129.21f, 127.213f, 131.828f, 127.213f, 134.447f, 128.522f, 136.41f, 136.376f, 139.028f, 150.122f, 141.647f, 162.558f, 140.992f, 163.213f, 138.374f, 160.595f, 135.756f, 153.395f, 135.101f, 148.158f, 134.447f, 140.304f, 134.447f, 130.485f, 133.792f, 124.594f, 133.792f, 115.431f, 133.792f, 110.194f, 133.792f, 105.612f, 134.447f, 105.612f, 137.065f, 110.194f, 137.719f, 116.74f, 139.028f, 120.013f, 139.028f, 123.94f, 137.719f, 127.213f, 135.756f, 130.485f, 134.447f, 130.485f, 133.792f, 130.485f, 137.719f, 131.794f, 141.647f, 135.722f, 146.883f, 142.922f, 152.774f, 153.395f, 153.428f, 159.286f, 150.156f, 159.94f, 147.537f, 156.667f, 146.883f, 148.813f, 146.883f, 140.958f, 146.883f, 134.413f, 146.883f, 125.904f, 145.574f, 118.703f, 145.574f, 114.776f, 145.574f, 112.158f, 146.228f, 111.503f, 147.537f, 111.503f, 148.192f, 112.158f, 150.156f, 112.812f, 150.81f, 113.467f, 152.119f, 114.776f, 154.083f, 117.394f, 155.392f, 119.358f, 156.701f, 120.667f, 157.356f, 121.976f, 156.701f, 121.322f, 156.047f, 120.013f, 155.392f, 119.358f, 154.083f, 117.394f, 154.083f, 116.74f, 152.774f, 114.776f, 152.119f, 114.121f, 150.81f, 113.467f, 149.501f, 113.467f, 147.537f, 112.158f, 146.883f, 112.158f, 145.574f, 111.503f, 144.919f, 112.158f, 144.265f, 114.121f, 144.265f, 115.431f, 144.265f, 116.74f, 144.265f, 117.394f, 144.265f, 118.049f, 144.919f, 118.703f, 145.574f, 120.667f, 146.228f, 122.631f, 147.537f, 123.285f, 147.537f, 124.594f, 148.192f, 125.904f, 147.537f, 128.522f, 147.537f, 129.176f, 147.537f, 130.485f, 147.537f, 132.449f, 147.537f, 134.413f, 147.537f, 136.376f, 147.537f, 138.34f, 147.537f, 138.994f, 145.574f, 138.994f, 142.956f, 138.252f }; RectangleF rectangle = new RectangleF(30, 580, 300, 400); PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints); inkAnnotation.Bounds = rectangle; inkAnnotation.Color = new PdfColor(Color.Red); page.Graphics.DrawString("Ink Annotation", font, brush, new PointF(30, 610)); page.Annotations.Add(inkAnnotation); //Creates a new popup annotation. RectangleF popupRect = new RectangleF(430, 670, 30, 30); PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(); popupAnnotation.Border.Width = 4; popupAnnotation.Border.HorizontalRadius = 20; popupAnnotation.Border.VerticalRadius = 30; popupAnnotation.Opacity = 1; popupAnnotation.Open = true; popupAnnotation.Text = "Popup Annotation"; popupAnnotation.Color = Color.Green; popupAnnotation.InnerColor = Color.Blue; popupAnnotation.Bounds = popupRect; if (checkboxFlatten == "Flatten") { popupAnnotation.FlattenPopUps = true; popupAnnotation.Flatten = true; } page.Graphics.DrawString("Popup Annotation", font, brush, new PointF(400, 610)); page.Annotations.Add(popupAnnotation); //Creates a new Line measurement annotation. points = new int[] { 400, 350, 550, 350 }; PdfLineMeasurementAnnotation lineMeasureAnnot = new PdfLineMeasurementAnnotation(points); lineMeasureAnnot.Author = "Syncfusion"; lineMeasureAnnot.Subject = "LineAnnotation"; lineMeasureAnnot.ModifiedDate = new DateTime(2015, 1, 18); lineMeasureAnnot.Unit = PdfMeasurementUnit.Inch; lineMeasureAnnot.lineBorder.BorderWidth = 2; lineMeasureAnnot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular); lineMeasureAnnot.Color = new PdfColor(Color.Red); if (checkboxFlatten == "Flatten") { lineMeasureAnnot.Flatten = true; } page.Graphics.DrawString("Line Measurement Annotation", font, brush, new PointF(370, 410)); page.Annotations.Add(lineMeasureAnnot); PdfPage secondPage = document.Pages.Add(); //Creates a new Freetext annotation. RectangleF freetextrect0 = new RectangleF(80, 130, 100, 50); PdfFreeTextAnnotation freeText0 = new PdfFreeTextAnnotation(freetextrect0); freeText0.MarkupText = "Free Text with Callouts"; freeText0.TextMarkupColor = new PdfColor(Color.Green); freeText0.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); freeText0.BorderColor = new PdfColor(Color.Blue); freeText0.Border = new PdfAnnotationBorder(.5f); freeText0.AnnotationFlags = PdfAnnotationFlags.Default; freeText0.Text = "Free Text"; freeText0.Rotate = PdfAnnotationRotateAngle.RotateAngle90; freeText0.Color = new PdfColor(Color.Yellow); PointF[] Freetextpoints0 = { new PointF(45, 190), new PointF(60, 145), new PointF(80, 145) }; freeText0.CalloutLines = Freetextpoints0; secondPage.Graphics.DrawString("Rotated FreeText Annotation", font, brush, new PointF(40, 110)); if (checkboxFlatten == "Flatten") { freeText0.Flatten = true; } secondPage.Annotations.Add(freeText0); MemoryStream SourceStream = new MemoryStream(); document.Save(SourceStream); document.Close(true); //Creates a new Loaded document. PdfLoadedDocument lDoc = new PdfLoadedDocument(SourceStream); PdfLoadedPage lpage = lDoc.Pages[0] as PdfLoadedPage; if (checkboxFlatten == "Flatten") { lpage.Annotations.Flatten = true; } //Save the PDF to the MemoryStream MemoryStream ms = new MemoryStream(); lDoc.Save(ms); //If the position is not set to '0' then the PDF will be empty. ms.Position = 0; lDoc.Close(true); //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "Annotation.pdf"; return(fileStreamResult); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> //protected override void OnNavigatedTo(NavigationEventArgs e) //{ //} private async void Button_Click_1(object sender, RoutedEventArgs e) { //Create a new PDF document PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); document.PageSettings.SetMargins(0); RectangleF bounds = new RectangleF(350, 50, 80, 80); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f); PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0)); PdfColor yellow = new PdfColor(System.Drawing.Color.FromArgb(255, 255, 255, 0)); PdfColor red = new PdfColor(System.Drawing.Color.FromArgb(255, 255, 0, 0)); PdfColor green = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 255, 0)); PdfColor blue = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 255)); //Creating circle annotation PdfCircleAnnotation circleannotation = new PdfCircleAnnotation(bounds); circleannotation.InnerColor = yellow; circleannotation.Color = red; circleannotation.AnnotationFlags = PdfAnnotationFlags.Default; circleannotation.Author = "Syncfusion"; circleannotation.Subject = "CircleAnnotation"; circleannotation.ModifiedDate = new DateTime(2015, 1, 18); page.Annotations.Add(circleannotation); page.Graphics.DrawString("Circle Annotation", font, brush, new PointF(350, 10)); //Creating ellipse annotation PdfEllipseAnnotation ellipseannotation = new PdfEllipseAnnotation(new RectangleF(30, 30, 50, 100), "Ellipse Annotation"); ellipseannotation.Color = yellow; ellipseannotation.InnerColor = red; page.Graphics.DrawString("Ellipse Annotation", font, brush, new PointF(30, 10)); page.Annotations.Add(ellipseannotation); //Creating square annotation PdfSquareAnnotation squareannotation = new PdfSquareAnnotation(new RectangleF(30, 200, 80, 80)); squareannotation.Text = "SquareAnnotation"; squareannotation.InnerColor = red; squareannotation.Color = yellow; page.Graphics.DrawString("Square Annotation", font, brush, new PointF(30, 180)); page.Annotations.Add(squareannotation); //Creating rectangle annotation RectangleF rectangle1 = new RectangleF(350, 220, 100, 50); PdfRectangleAnnotation rectangleannotation = new PdfRectangleAnnotation(rectangle1, "RectangleAnnotation"); rectangleannotation.InnerColor = red; rectangleannotation.Color = yellow; page.Graphics.DrawString("Rectangle Annotation", font, brush, new PointF(350, 180)); page.Annotations.Add(rectangleannotation); //Creating line annotation int[] points = new int[] { 400, 450, 550, 450 }; PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annoation is the one of the annotation type..."); lineAnnotation.Author = "Syncfusion"; lineAnnotation.Subject = "LineAnnotation"; lineAnnotation.ModifiedDate = new DateTime(2015, 1, 18); lineAnnotation.Text = "PdfLineAnnotation"; lineAnnotation.BackColor = red; page.Graphics.DrawString("Line Annotation", font, brush, new PointF(400, 320)); page.Annotations.Add(lineAnnotation); //Creating polygon annotation int[] points1 = new int[] { 50, 398, 100, 425, 200, 455, 300, 330, 180, 330 }; PdfPolygonAnnotation polygonannotation = new PdfPolygonAnnotation(points1, "Polygon Annotation"); polygonannotation.Bounds = new RectangleF(30, 350, 300, 200); PdfPen pen = new PdfPen(System.Drawing.Color.FromArgb(255, 255, 0, 0)); polygonannotation.Text = "polygon"; polygonannotation.Color = red; polygonannotation.InnerColor = yellow; page.Graphics.DrawString("PolygonAnnotation", font, brush, new PointF(50, 320)); page.Annotations.Add(polygonannotation); //Creating text markup annotation string s = "This is TextMarkup annotation!!!"; RectangleF Textmarkuprect = new RectangleF(30, 540, 200, 20); page.Graphics.DrawString(s, font, brush, new PointF(30, 540)); PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation("sample", "Highlight", s, new PointF(70, 580), font); textannot.Author = "Annotation"; textannot.Opacity = 1.0f; textannot.Subject = "pdftextmarkupannotation"; textannot.ModifiedDate = new DateTime(2015, 1, 18); textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.StrikeOut; textannot.TextMarkupColor = yellow; textannot.InnerColor = red; textannot.Color = yellow; page.Graphics.DrawString("Text Markup Annotation", font, brush, new PointF(30, 510)); page.Annotations.Add(textannot); //Creates a new Ink annotation. float[] inkPoints = new float[] { 72.919f, 136.376f, 72.264f, 136.376f, 62.446f, 142.922f, 61.137f, 142.922f, 55.901f, 139.649f, 55.246f, 138.34f, 54.592f, 132.449f, 54.592f, 127.867f, 55.901f, 125.904f, 59.828f, 121.976f, 63.101f, 121.322f, 65.719f, 122.631f, 68.992f, 125.249f, 70.301f, 130.485f, 71.61f, 133.104f, 72.264f, 136.376f, 72.919f, 140.304f, 74.883f, 144.885f, 76.192f, 150.776f, 76.192f, 151.431f, 76.192f, 152.085f, 76.192f, 158.631f, 76.192f, 159.94f, 75.537f, 155.358f, 74.228f, 150.122f, 74.228f, 146.195f, 73.574f, 141.613f, 73.574f, 137.685f, 74.228f, 132.449f, 74.883f, 128.522f, 75.537f, 124.594f, 76.192f, 123.285f, 76.846f, 122.631f, 80.774f, 122.631f, 82.737f, 123.285f, 85.355f, 125.249f, 88.628f, 129.831f, 89.283f, 133.104f, 89.937f, 137.031f, 90.592f, 140.958f, 89.937f, 142.267f, 86.665f, 141.613f, 85.355f, 140.304f, 84.701f, 138.34f, 84.701f, 137.685f, 85.355f, 137.031f, 87.974f, 135.722f, 90.592f, 136.376f, 92.555f, 137.031f, 96.483f, 139.649f, 98.446f, 140.958f, 101.719f, 142.922f, 103.028f, 142.922f, 100.41f, 138.34f, 99.756f, 134.413f, 99.101f, 131.14f, 99.101f, 128.522f, 99.756f, 127.213f, 101.065f, 125.904f, 102.374f, 123.94f, 103.683f, 123.94f, 107.61f, 125.904f, 110.228f, 129.831f, 114.156f, 135.067f, 117.428f, 140.304f, 119.392f, 143.576f, 121.356f, 144.231f, 122.665f, 144.231f, 123.974f, 142.267f, 126.592f, 139.649f, 127.247f, 140.304f, 126.592f, 142.922f, 124.628f, 143.576f, 122.01f, 142.922f, 118.083f, 141.613f, 114.81f, 136.376f, 114.81f, 131.14f, 113.501f, 127.213f, 114.156f, 125.904f, 118.083f, 125.904f, 120.701f, 126.558f, 123.319f, 130.485f, 125.283f, 136.376f, 125.937f, 140.304f, 125.937f, 142.922f, 126.592f, 143.576f, 125.937f, 135.722f, 125.937f, 131.794f, 125.937f, 131.14f, 127.247f, 129.176f, 129.21f, 127.213f, 131.828f, 127.213f, 134.447f, 128.522f, 136.41f, 136.376f, 139.028f, 150.122f, 141.647f, 162.558f, 140.992f, 163.213f, 138.374f, 160.595f, 135.756f, 153.395f, 135.101f, 148.158f, 134.447f, 140.304f, 134.447f, 130.485f, 133.792f, 124.594f, 133.792f, 115.431f, 133.792f, 110.194f, 133.792f, 105.612f, 134.447f, 105.612f, 137.065f, 110.194f, 137.719f, 116.74f, 139.028f, 120.013f, 139.028f, 123.94f, 137.719f, 127.213f, 135.756f, 130.485f, 134.447f, 130.485f, 133.792f, 130.485f, 137.719f, 131.794f, 141.647f, 135.722f, 146.883f, 142.922f, 152.774f, 153.395f, 153.428f, 159.286f, 150.156f, 159.94f, 147.537f, 156.667f, 146.883f, 148.813f, 146.883f, 140.958f, 146.883f, 134.413f, 146.883f, 125.904f, 145.574f, 118.703f, 145.574f, 114.776f, 145.574f, 112.158f, 146.228f, 111.503f, 147.537f, 111.503f, 148.192f, 112.158f, 150.156f, 112.812f, 150.81f, 113.467f, 152.119f, 114.776f, 154.083f, 117.394f, 155.392f, 119.358f, 156.701f, 120.667f, 157.356f, 121.976f, 156.701f, 121.322f, 156.047f, 120.013f, 155.392f, 119.358f, 154.083f, 117.394f, 154.083f, 116.74f, 152.774f, 114.776f, 152.119f, 114.121f, 150.81f, 113.467f, 149.501f, 113.467f, 147.537f, 112.158f, 146.883f, 112.158f, 145.574f, 111.503f, 144.919f, 112.158f, 144.265f, 114.121f, 144.265f, 115.431f, 144.265f, 116.74f, 144.265f, 117.394f, 144.265f, 118.049f, 144.919f, 118.703f, 145.574f, 120.667f, 146.228f, 122.631f, 147.537f, 123.285f, 147.537f, 124.594f, 148.192f, 125.904f, 147.537f, 128.522f, 147.537f, 129.176f, 147.537f, 130.485f, 147.537f, 132.449f, 147.537f, 134.413f, 147.537f, 136.376f, 147.537f, 138.34f, 147.537f, 138.994f, 145.574f, 138.994f, 142.956f, 138.252f }; List <float> linePoints = new List <float>(inkPoints); RectangleF rectangle = new RectangleF(30, 580, 300, 400); PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints); inkAnnotation.Bounds = rectangle; inkAnnotation.Color = red; page.Graphics.DrawString("Ink Annotation", font, brush, new PointF(30, 610)); page.Annotations.Add(inkAnnotation); //Creates a new popup annotation. RectangleF popupRect = new RectangleF(430, 670, 30, 30); PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(); popupAnnotation.Border.Width = 4; popupAnnotation.Border.HorizontalRadius = 20; popupAnnotation.Border.VerticalRadius = 30; popupAnnotation.Opacity = 1; popupAnnotation.Open = true; popupAnnotation.Text = "Popup Annotation"; popupAnnotation.Color = green; popupAnnotation.InnerColor = blue; popupAnnotation.Bounds = popupRect; if (flatten.IsChecked == true) { popupAnnotation.FlattenPopUps = true; popupAnnotation.Flatten = true; } page.Graphics.DrawString("Popup Annotation", font, brush, new PointF(410, 610)); page.Annotations.Add(popupAnnotation); //Saving the document MemoryStream SourceStream = new MemoryStream(); document.Save(SourceStream); document.Close(true); //Loading and flatten the annotation PdfLoadedDocument lDoc = new PdfLoadedDocument(SourceStream); PdfLoadedPage lpage = lDoc.Pages[0] as PdfLoadedPage; if (flatten.IsChecked == true) { lpage.Annotations.Flatten = true; } MemoryStream stream = new MemoryStream(); await lDoc.SaveAsync(stream); lDoc.Close(true); Save(stream, "Sample.pdf"); }
private void AddAnnotationToPdf(AnnotObject annotObject, PdfDocument pdfDocument) { String annotName = annotObject.GetName(); if (annotName != null) { switch (annotName) { case XfdfConstants.TEXT: { //TODO add all attributes properly one by one PdfTextAnnotation pdfTextAnnotation = new PdfTextAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject .GetAttributeValue(XfdfConstants.RECT))); AddCommonAnnotationAttributes(pdfTextAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfTextAnnotation, annotObject); pdfTextAnnotation.SetIconName(new PdfName(annotObject.GetAttributeValue(XfdfConstants.ICON))); if (annotObject.GetAttributeValue(XfdfConstants.STATE) != null) { pdfTextAnnotation.SetState(new PdfString(annotObject.GetAttributeValue(XfdfConstants.STATE))); } if (annotObject.GetAttributeValue(XfdfConstants.STATE_MODEL) != null) { pdfTextAnnotation.SetStateModel(new PdfString(annotObject.GetAttributeValue(XfdfConstants.STATE_MODEL))); } pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttributeValue(XfdfConstants.PAGE))).AddAnnotation(pdfTextAnnotation ); break; } case XfdfConstants.HIGHLIGHT: { PdfTextMarkupAnnotation pdfHighLightAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Highlight, XfdfObjectUtils.ConvertQuadPointsFromCoordsString (annotObject.GetAttributeValue(XfdfConstants.COORDS))); AddCommonAnnotationAttributes(pdfHighLightAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfHighLightAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfHighLightAnnotation); break; } case XfdfConstants.UNDERLINE: { PdfTextMarkupAnnotation pdfUnderlineAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Underline, XfdfObjectUtils.ConvertQuadPointsFromCoordsString (annotObject.GetAttributeValue(XfdfConstants.COORDS))); AddCommonAnnotationAttributes(pdfUnderlineAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfUnderlineAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfUnderlineAnnotation); break; } case XfdfConstants.STRIKEOUT: { PdfTextMarkupAnnotation pdfStrikeoutAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.StrikeOut, XfdfObjectUtils.ConvertQuadPointsFromCoordsString (annotObject.GetAttributeValue(XfdfConstants.COORDS))); AddCommonAnnotationAttributes(pdfStrikeoutAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfStrikeoutAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfStrikeoutAnnotation); break; } case XfdfConstants.SQUIGGLY: { PdfTextMarkupAnnotation pdfSquigglyAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Squiggly, XfdfObjectUtils.ConvertQuadPointsFromCoordsString (annotObject.GetAttributeValue(XfdfConstants.COORDS))); AddCommonAnnotationAttributes(pdfSquigglyAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfSquigglyAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfSquigglyAnnotation); break; } case XfdfConstants.CIRCLE: { // case XfdfConstants.LINE: // pdfDocument.getPage(Integer.parseInt(annotObject.getAttribute(XfdfConstants.PAGE).getValue())) // .addAnnotation(new PdfLineAnnotation(XfdfObjectUtils.convertRectFromString(annotObject.getAttributeValue(XfdfConstants.RECT)), XfdfObjectUtils.convertVerticesFromString(annotObject.getVertices()))); // break; PdfCircleAnnotation pdfCircleAnnotation = new PdfCircleAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject .GetAttributeValue(XfdfConstants.RECT))); AddCommonAnnotationAttributes(pdfCircleAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfCircleAnnotation, annotObject); if (annotObject.GetAttributeValue(XfdfConstants.FRINGE) != null) { pdfCircleAnnotation.SetRectangleDifferences(XfdfObjectUtils.ConvertFringeFromString(annotObject.GetAttributeValue (XfdfConstants.FRINGE))); } pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfCircleAnnotation); break; } case XfdfConstants.SQUARE: { PdfSquareAnnotation pdfSquareAnnotation = new PdfSquareAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject .GetAttributeValue(XfdfConstants.RECT))); AddCommonAnnotationAttributes(pdfSquareAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfSquareAnnotation, annotObject); if (annotObject.GetAttributeValue(XfdfConstants.FRINGE) != null) { pdfSquareAnnotation.SetRectangleDifferences(XfdfObjectUtils.ConvertFringeFromString(annotObject.GetAttributeValue (XfdfConstants.FRINGE))); } pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfSquareAnnotation); break; } case XfdfConstants.POLYGON: { //XfdfConstants.CARET Rectangle rect = XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants.RECT)); float[] vertices = XfdfObjectUtils.ConvertVerticesFromString(annotObject.GetVertices()); PdfPolyGeomAnnotation polygonAnnotation = PdfPolyGeomAnnotation.CreatePolygon(rect, vertices); AddCommonAnnotationAttributes(polygonAnnotation, annotObject); AddMarkupAnnotationAttributes(polygonAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (polygonAnnotation); break; } case XfdfConstants.POLYLINE: { Rectangle polylineRect = XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants .RECT)); float[] polylineVertices = XfdfObjectUtils.ConvertVerticesFromString(annotObject.GetVertices()); PdfPolyGeomAnnotation polylineAnnotation = PdfPolyGeomAnnotation.CreatePolyLine(polylineRect, polylineVertices ); AddCommonAnnotationAttributes(polylineAnnotation, annotObject); AddMarkupAnnotationAttributes(polylineAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (polylineAnnotation); break; } case XfdfConstants.STAMP: { pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (new PdfStampAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants .RECT)))); break; } case XfdfConstants.FREETEXT: { //XfdfConstants.INK pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (new PdfFreeTextAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants .RECT)), annotObject.GetContents())); break; } default: { //XfdfConstants.FILEATTACHMENT //XfdfConstants.SOUND //XfdfConstants.LINK //XfdfConstants.REDACT //XfdfConstants.PROJECTION logger.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.XFDF_ANNOTATION_IS_NOT_SUPPORTED, annotName )); break; } } } }