/// <summary> /// Checks if two ink annotations are matched by comparing their colors and ink points. /// </summary> /// <param name="loadedInk">The ink annotation in the pdf file.</param> /// <param name="appInk">The ink annotation constructed by the app.</param> /// <returns>If the two annotations are matched, true. Otherwise false.</returns> private bool MatchInkAnnotations(PdfLoadedInkAnnotation loadedInk, PdfInkAnnotation appInk) { // Color if (loadedInk.Color.R != appInk.Color.R || loadedInk.Color.G != appInk.Color.G || loadedInk.Color.B != appInk.Color.B) { return(false); } // Points List <float> points1 = loadedInk.InkList; List <float> points2 = appInk.InkList; if (points1.Count != points2.Count) { return(false); } for (int i = 0; i < points1.Count; i++) { double threshold = 0.5; if (Math.Abs(points1[i] - points2[i]) > threshold) { return(false); } } return(true); }
private static void CreateInkAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); Random rnd = new Random(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Ink annotations", font, blackBrush, 50, 50); // The ink annotation will contain 3 lines, each one with 10 points. PdfPoint[][] points = new PdfPoint[3][]; for (int i = 0; i < points.Length; i++) { points[i] = new PdfPoint[10]; for (int j = 0; j < points[i].Length; j++) { points[i][j] = new PdfPoint(rnd.NextDouble() * page.Width, rnd.NextDouble() * page.Height); } } PdfInkAnnotation ia = new PdfInkAnnotation(); page.Annotations.Add(ia); ia.Contents = "I am an ink annotation."; ia.InkColor = new PdfRgbColor(255, 0, 255); ia.InkWidth = 5; ia.Points = points; }
/// <summary> /// Removes a list of ink annotations from a page. /// </summary> /// <param name="page">1-based page number.</param> /// <param name="inkAnnotations">A list of ink annotations to be removed. /// Annotation not found in the page will be ignored.</param> /// <returns>If at least one annotation is removed, true. Otherwise false.</returns> public bool RemoveInkAnnotations(PdfLoadedPage page, List <PdfInkAnnotation> inkAnnotations) { bool annotationRemoved = false; List <PdfLoadedAnnotation> toBeRemoved = new List <PdfLoadedAnnotation>(); foreach (PdfLoadedAnnotation annotation in page.Annotations) { if (annotation is PdfLoadedInkAnnotation loadedInk) { PdfInkAnnotation matched = null; foreach (PdfInkAnnotation erasedInk in inkAnnotations) { if (MatchInkAnnotations(loadedInk, erasedInk)) { toBeRemoved.Add(annotation); matched = erasedInk; break; } } if (matched != null) { inkAnnotations.Remove(matched); } } } foreach (PdfLoadedAnnotation a in toBeRemoved) { page.Annotations.Remove(a); annotationRemoved = true; } return(annotationRemoved); }
/// <summary> /// Converts an ink stroke (displaying on the screen) to an ink annotation (to be saved in the file). /// </summary> /// <param name="stroke"></param> /// <param name="mapping"></param> /// <returns></returns> public PdfInkAnnotation InkStroke2InkAnnotation(InkStroke stroke) { List <float> strokePoints = new List <float>(); foreach (InkPoint p in stroke.GetInkPoints()) { float X = (float)(p.Position.X * ScaleRatio + Offset.X); float Y = (float)(p.Position.Y * ScaleRatio + Offset.Y); switch (Rotation) { case 0: // No rotation { strokePoints.Add(X); strokePoints.Add(PageSize.Height - Y); break; } case 1: // 90-degree rotation { strokePoints.Add(Y); strokePoints.Add(X); break; } case 2: // 180-degree rotation { strokePoints.Add(PageSize.Width - X); strokePoints.Add(Y); break; } case 3: // 270-degree rotation { strokePoints.Add(PageSize.Height - Y); strokePoints.Add(PageSize.Width - X); break; } } } PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(Rectangle, strokePoints) { // Color Color = new PdfColor(ColorFromUI(stroke.DrawingAttributes.Color)), // Size // TODO: Possible 0-width BorderWidth = (int)Math.Round(stroke.DrawingAttributes.Size.Width * ScaleRatio) }; if (stroke.DrawingAttributes.DrawAsHighlighter) { inkAnnotation.Opacity = InkingManager.HighlighterOpacity; } return(inkAnnotation); }
/// <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 CreateInkAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); Random rnd = new Random(); PdfPage page = document.Pages.Add(); page.Graphics.DrawString("Ink annotations", font, blackBrush, 50, 50); // The ink annotation will contain 3 lines, each one with 10 points. PdfPoint[][] points = new PdfPoint[3][]; for (int i = 0; i < points.Length; i++) { points[i] = new PdfPoint[10]; for (int j = 0; j < points[i].Length; j++) { points[i][j] = new PdfPoint(rnd.NextDouble() * page.Width, rnd.NextDouble() * page.Height); } } PdfInkAnnotation ia = new PdfInkAnnotation(); page.Annotations.Add(ia); ia.Contents = "I am an ink annotation."; ia.InkColor = new PdfRgbColor(255, 0, 255); ia.InkWidth = 5; ia.Points = points; }
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> /// Save the ink annotations into the pdf file. /// </summary> /// <param name="inkDictionary"></param> /// <returns></returns> /// <remarks> /// The page size returned from Syncfusion pdf is the media box size. /// The page size displayed to the end user is the crop box size. /// The size of the ink canvas is the same as the crop box size. /// Syncfusion uses the bottom left corner as the origin, while ink canvas uses the top left corner. /// </remarks> public async Task <bool> SaveInkingToPdf(InkingManager inkManager) { // Indicate whether any ink annotation is added to the PDF file bool fileChanged = false; // Remove ereased ink annotations foreach (KeyValuePair <int, List <InkStroke> > entry in await inkManager.ErasedStrokesDictionary()) { // The key of the dictionary is page number, which is 1-based. int pageNumber = entry.Key; PdfLoadedPage sfPage = sfPdf.GetPage(pageNumber); // Get page information from MS model Windows.Data.Pdf.PdfPage msPage = msPdf.GetPage(pageNumber); PageMapping mapping = new PageMapping(msPage, sfPage); List <PdfInkAnnotation> erasedAnnotations = new List <PdfInkAnnotation>(); // Add each ink stroke to the page foreach (InkStroke stroke in entry.Value) { PdfInkAnnotation inkAnnotation = mapping.InkStroke2InkAnnotation(stroke); erasedAnnotations.Add(inkAnnotation); } if (sfPdf.RemoveInkAnnotations(sfPage, erasedAnnotations)) { fileChanged = true; } } // Add new ink annotations foreach (KeyValuePair <int, InkStrokeContainer> entry in await inkManager.InAppInkDictionary()) { PdfLoadedPage sfPage = sfPdf.GetPage(entry.Key); // Get page information from MS model Windows.Data.Pdf.PdfPage msPage = msPdf.GetPage(entry.Key); PageMapping mapping = new PageMapping(msPage, sfPage); // Add each ink stroke to the page foreach (InkStroke stroke in entry.Value.GetStrokes()) { PdfInkAnnotation inkAnnotation = mapping.InkStroke2InkAnnotation(stroke); sfPage.Annotations.Add(inkAnnotation); fileChanged = true; } } // Save the file only if there are changes. bool inkSaved = false; if (fileChanged) { try { inkSaved = await sfPdf.SaveAsync(); // Copy and replace the actual file await sfFile.CopyAndReplaceAsync(pdfFile); } catch (Exception ex) { // Try to save the file by extracting the pages. StorageFile newFile = await backupFolder.CreateFileAsync("COPY_" + pdfFile.Name, CreationCollisionOption.GenerateUniqueName); try { await sfPdf.CopyPages(newFile); inkSaved = true; // Copy and replace the actual file await newFile.CopyAndReplaceAsync(pdfFile); } catch { App.NotifyUser(typeof(ViewerPage), "Error: \n" + ex.Message, true); } } } return(!(inkSaved ^ fileChanged)); }
/// <summary> /// Save the ink annotations into the pdf file. /// </summary> /// <param name="inkManager"></param> /// <returns></returns> /// <remarks> /// The page size returned from Syncfusion pdf is the media box size. /// The page size displayed to the end user is the crop box size. /// The size of the ink canvas is the same as the crop box size. /// Syncfusion uses the bottom left corner as the origin, while ink canvas uses the top left corner. /// </remarks> public async Task<bool> SaveInkingToPdf(InkingManager inkManager, Windows.Data.Pdf.PdfDocument pdfDoc) { // Indicate whether any ink annotation is added to the PDF file bool fileChanged = false; // Add ink annotations for each page foreach (KeyValuePair<int, InkStrokeContainer> entry in inkManager.InkDictionary) { // The key of the dictionary is page number, which is 1-based. Page index is 0-based. int pageIndex = entry.Key - 1; PdfLoadedPage sfPage = pdf.Pages[pageIndex] as PdfLoadedPage; // Get page information from MS model Windows.Data.Pdf.PdfPage msPage = pdfDoc.GetPage((uint)pageIndex); int rotation = (int)msPage.Rotation; // The page size returned from Syncfusion pdf is the media box size. double scaleRatio = sfPage.Size.Width / msPage.Dimensions.MediaBox.Width; // The ink canvas size is the same as crop box // Crop box could be smaller than media box // There will be an offset if the crop box is smaller than the media box. double xOffset = msPage.Dimensions.CropBox.Left * scaleRatio; double yOffset = msPage.Dimensions.CropBox.Top * scaleRatio; RectangleF rectangle = new RectangleF(0, 0, sfPage.Size.Width, sfPage.Size.Height); // Add each ink stroke to the page foreach (InkStroke stroke in entry.Value.GetStrokes()) { List<float> strokePoints = new List<float>(); foreach (InkPoint p in stroke.GetInkPoints()) { float X = (float)(p.Position.X * scaleRatio + xOffset); float Y = (float)(p.Position.Y * scaleRatio + yOffset); switch (rotation) { case 0: // No rotation { strokePoints.Add(X); strokePoints.Add(sfPage.Size.Height - Y); break; } case 1: // 90-degree rotation { strokePoints.Add(Y); strokePoints.Add(X); break; } case 2: // 180-degree rotation { strokePoints.Add(sfPage.Size.Width - X); strokePoints.Add(Y); break; } case 3: // 270-degree rotation { strokePoints.Add(sfPage.Size.Height - Y); strokePoints.Add(sfPage.Size.Width - X); break; } } } PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, strokePoints); // Color inkAnnotation.Color = new PdfColor(fromUIColor(stroke.DrawingAttributes.Color)); // Size inkAnnotation.BorderWidth = (int) Math.Round(stroke.DrawingAttributes.Size.Width * scaleRatio); sfPage.Annotations.Add(inkAnnotation); fileChanged = true; } } bool inkSaved = false; // Save the file only if there are changes. if (fileChanged) { try { inkSaved = await pdf.SaveAsync(pdfFile); } catch (Exception ex) { App.NotifyUser(typeof(ViewerPage), "Error: \n" + ex.Message, true); } } //pdf.Close(true); return !(inkSaved ^ fileChanged); }
/// <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"); }