Beispiel #1
0
        static void Main(string[] args)
        {
            //Initialize an instance of PdfDocument class and load the file
            PdfDocument doc = new PdfDocument();

            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf");

            //Get the first page
            PdfPageBase page = doc.Pages[0];

            //Call the FindText() method to  find the text which is needed to add annotation
            PdfTextFind[] results = page.FindText("IPCC").Finds;

            //Specify the location of annotation
            float x = results[0].Position.X - doc.PageSettings.Margins.Top;
            float y = results[0].Position.Y - doc.PageSettings.Margins.Left + results[0].Size.Height - 23;

            //Create the pop-up annotation
            RectangleF         rect            = new RectangleF(x, y, 15, 0);
            PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(rect);

            //Add the text into the annotation and set the icon and color
            popupAnnotation.Text  = "IPCC,This is a scientific and intergovernmental body under the auspices of the United Nations.";
            popupAnnotation.Icon  = PdfPopupIcon.Help;
            popupAnnotation.Color = Color.SandyBrown;

            //Add the annotation to the PDF file
            page.AnnotationsWidget.Add(popupAnnotation);

            //Save the file and view
            doc.SaveToFile("Annotation.pdf");
            System.Diagnostics.Process.Start("Annotation.pdf");
        }
Beispiel #2
0
        /// <summary>
        /// Remove the redaction annotations
        /// This method is called after the annotations are processed.
        /// </summary>
        private void RemoveRedactAnnots()
        {
            foreach (PdfRedactAnnotation annotation in redactAnnotations.Keys)
            {
                PdfPage page = annotation.GetPage();
                if (page != null)
                {
                    page.RemoveAnnotation(annotation);
                    PdfPopupAnnotation popup = annotation.GetPopup();
                    if (popup != null)
                    {
                        page.RemoveAnnotation(popup);
                    }
                }

                PdfCanvas canvas = new PdfCanvas(page);
                PdfStream redactRolloverAppearance = annotation.GetRedactRolloverAppearance();
                PdfString overlayText = annotation.GetOverlayText();
                Rectangle annotRect   = annotation.GetRectangle().ToRectangle();
                if (redactRolloverAppearance != null)
                {
                    DrawRolloverAppearance(canvas, redactRolloverAppearance, annotRect, redactAnnotations.Get(annotation));
                }
                else
                {
                    if (overlayText != null && !String.IsNullOrEmpty(overlayText.ToUnicodeString()))
                    {
                        DrawOverlayText(canvas, overlayText.ToUnicodeString(), annotRect, annotation.GetRepeat(), annotation.GetDefaultAppearance
                                            (), annotation.GetJustification());
                    }
                }
            }
        }
        private float AddPopupAnnotation(PdfPageBase page, float y)
        {
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            String prompt = "Markup incorrect spelling: ";
            SizeF  size   = font.MeasureString(prompt, format);

            page.Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);
            float x = size.Width;

            String label = "demo of annotation";

            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);
            x = x + font.MeasureString(label, format).Width;
            String markupText = "All words were spelled correctly";

            size = font.MeasureString(markupText);
            PdfPopupAnnotation annotation
                = new PdfPopupAnnotation(new RectangleF(new PointF(x, y), SizeF.Empty), markupText);

            annotation.Icon  = PdfPopupIcon.Paragraph;
            annotation.Open  = true;
            annotation.Color = Color.Yellow;
            (page as PdfNewPage).Annotations.Add(annotation);
            y = y + size.Height;

            return(y);
        }
Beispiel #4
0
        void table_BeginCellLayout(object sender, BeginCellLayoutEventArgs args)
        {
            if (args.CellIndex == 2 && args.RowIndex > -1)
            {
                CreateTextBox(interactivePage, "price" + args.RowIndex.ToString(), "Price", args.Bounds, true, args.Value);
                args.Skip = true;
            }
            else if (args.CellIndex == 3 && args.RowIndex == -1)
            {
                PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(new RectangleF(args.Bounds.Right - 18, args.Bounds.Top + 2, 1, 1),
                                                                            "Please enter a validate interger between 1 to 50");
                popupAnnotation.Border.Width            = 4;
                popupAnnotation.Open                    = false;
                popupAnnotation.Border.HorizontalRadius = 10;
                popupAnnotation.Border.VerticalRadius   = 10;
                popupAnnotation.Icon                    = PdfPopupIcon.Comment;
                interactivePage.Annotations.Add(popupAnnotation);
            }
            else if (args.CellIndex == 3 && args.RowIndex > -1)
            {
                PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "quantity" + args.RowIndex.ToString());


                //Set properties to the textbox.
                textBoxField.Font        = new PdfStandardFont(PdfFontFamily.Helvetica, 12);;
                textBoxField.BorderColor = new PdfColor(white);
                textBoxField.BackColor   = Syncfusion.Drawing.Color.FromArgb(255, 238, 238, 248);
                textBoxField.Bounds      = args.Bounds;
                textBoxField.Text        = "0";
                PdfJavaScriptAction action = new PdfJavaScriptAction(@"event.rc = event.value > -1 && event.value < 51; 
                var f = this.getField('price" + args.RowIndex.ToString() + @"')
                var f1 = this.getField('quantity" + args.RowIndex.ToString() + @"')
                var f2 = this.getField('TotalPrice" + args.RowIndex.ToString() + @"')
                var f3 = this.getField('GrandTotal');
                if(!event.rc)
                {

                f1.fillColor=color.red;
                app.beep();
                }
                else
                {
                    f1.fillColor = color.transparent;
                    f2.value = f1.value * f.value;
                    f3.value = this.getField('TotalPrice0').value + this.getField('TotalPrice1').value + this.getField('TotalPrice2').value + this.getField('TotalPrice3').value + this.getField('TotalPrice4').value +this.getField('TotalPrice5').value;
                }");
                textBoxField.Actions.LostFocus = action;
                document.Form.Fields.Add(textBoxField);
            }
            else if (args.CellIndex == 4 && args.RowIndex > -1)
            {
                CreateTextBox(interactivePage, "TotalPrice" + args.RowIndex.ToString(), "Total Price", args.Bounds, true, "0");
            }
        }
        //Add comment to the annotations
        public PdfPopupAnnotation AddComment(PdfTextMarkupAnnotation annotation, string author, string comment, DateTime modifiedDate)
        {
            //Creates a new comment
            PdfPopupAnnotation userComment = new PdfPopupAnnotation();

            userComment.Author       = author;
            userComment.Text         = comment;
            userComment.ModifiedDate = modifiedDate;
            //Add comment to the annotation
            annotation.Comments.Add(userComment);
            return(userComment);
        }
        //Add review to the comments
        public void AddReview(PdfPopupAnnotation userComment, string author, PdfAnnotationState reviewState, PdfAnnotationStateModel stateModel, DateTime modifiedDate)
        {
            //Creates a new review history
            PdfPopupAnnotation userReview = new PdfPopupAnnotation();

            userReview.Author       = author;
            userReview.State        = reviewState;
            userReview.StateModel   = stateModel;
            userReview.ModifiedDate = modifiedDate;
            //Add review to the comment
            userComment.ReviewHistory.Add(userReview);
        }
 public virtual void TestCopyingPageWithAnnotationContainingPopupKey()
 {
     NUnit.Framework.Assert.That(() => {
         // TODO remove expected exception and thus enable assertions when DEVSIX-3585 is implemented
         String inFilePath            = sourceFolder + "annotation-with-popup.pdf";
         String outFilePath           = destinationFolder + "copy-annotation-with-popup.pdf";
         PdfDocument originalDocument = new PdfDocument(new PdfReader(inFilePath));
         PdfDocument outDocument      = new PdfDocument(new PdfWriter(outFilePath));
         originalDocument.CopyPagesTo(1, 1, outDocument);
         // During the second copy call we have to rebuild/preserve all the annotation relationship (Popup in this case),
         // so that we don't end up with annotation on one page referring to an annotation on another page as its popup
         // or as its parent
         originalDocument.CopyPagesTo(1, 1, outDocument);
         originalDocument.Close();
         outDocument.Close();
         outDocument = new PdfDocument(new PdfReader(outFilePath));
         for (int pageNum = 1; pageNum <= outDocument.GetNumberOfPages(); pageNum++)
         {
             PdfPage page = outDocument.GetPage(pageNum);
             NUnit.Framework.Assert.AreEqual(2, page.GetAnnotsSize());
             NUnit.Framework.Assert.AreEqual(2, page.GetAnnotations().Count);
             bool foundMarkupAnnotation = false;
             foreach (PdfAnnotation annotation in page.GetAnnotations())
             {
                 PdfDictionary annotationPageDict = annotation.GetPageObject();
                 if (annotationPageDict != null)
                 {
                     NUnit.Framework.Assert.AreSame(page.GetPdfObject(), annotationPageDict);
                 }
                 if (annotation is PdfMarkupAnnotation)
                 {
                     foundMarkupAnnotation    = true;
                     PdfPopupAnnotation popup = ((PdfMarkupAnnotation)annotation).GetPopup();
                     NUnit.Framework.Assert.IsTrue(page.ContainsAnnotation(popup), MessageFormatUtil.Format("Popup reference must point to annotation present on the same page (# {0})"
                                                                                                            , pageNum));
                     PdfDictionary parentAnnotation = popup.GetParentObject();
                     NUnit.Framework.Assert.AreSame(annotation.GetPdfObject(), parentAnnotation, "Popup annotation parent must point to the annotation that specified it as Popup"
                                                    );
                 }
             }
             NUnit.Framework.Assert.IsTrue(foundMarkupAnnotation, "Markup annotation expected to be present but not found"
                                           );
         }
         outDocument.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <AssertionException>())
     ;
 }
        public virtual void AnnotationCheckTest02()
        {
            String       outPdf = destinationFolder + "pdfA2b_annotationCheckTest02.pdf";
            String       cmpPdf = cmpFolder + "cmp_pdfA2b_annotationCheckTest02.pdf";
            PdfWriter    writer = new PdfWriter(outPdf);
            Stream       @is    = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read);
            PdfADocument doc    = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", ""
                                                                                                              , "http://www.color.org", "sRGB IEC61966-2.1", @is));
            PdfPage       page  = doc.AddNewPage();
            Rectangle     rect  = new Rectangle(100, 650, 400, 100);
            PdfAnnotation annot = new PdfPopupAnnotation(rect);

            page.AddAnnotation(annot);
            doc.Close();
            CompareResult(outPdf, cmpPdf);
        }
Beispiel #9
0
 public virtual void CheckAppearanceStreamsWithCycle()
 {
     using (MemoryStream bos = new MemoryStream()) {
         using (PdfWriter writer = new PdfWriter(bos)) {
             using (PdfDocument document = new PdfDocument(writer)) {
                 PdfDictionary normalAppearance = new PdfDictionary();
                 normalAppearance.Put(PdfName.ON, normalAppearance);
                 normalAppearance.MakeIndirect(document);
                 PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
                 annotation.SetAppearance(PdfName.N, normalAppearance);
                 PdfPage pageToCheck = document.AddNewPage();
                 pageToCheck.AddAnnotation(annotation);
                 // no assertions as we want to check that no exceptions would be thrown
                 pdfAChecker.CheckResourcesOfAppearanceStreams(annotation.GetAppearanceDictionary());
             }
         }
     }
 }
Beispiel #10
0
 public virtual void CheckAppearanceStreamWithoutTransparencyGroup()
 {
     using (MemoryStream bos = new MemoryStream()) {
         using (PdfWriter writer = new PdfWriter(bos)) {
             using (PdfDocument document = new PdfDocument(writer)) {
                 PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
                 PdfAnnotation  annotation  = new PdfPopupAnnotation(new Rectangle(0f, 0f));
                 annotation.SetNormalAppearance(formXObject.GetPdfObject());
                 PdfPage pageToCheck = document.AddNewPage();
                 pageToCheck.AddAnnotation(new PdfPopupAnnotation(new Rectangle(0f, 0f)));
                 pageToCheck.AddAnnotation(annotation);
                 EnsureTransparencyObjectsNotEmpty();
                 // no assertions as we want to check that no exceptions would be thrown
                 pdfA2Checker.CheckSinglePage(pageToCheck);
             }
         }
     }
 }
Beispiel #11
0
 public virtual void CheckAppearanceStreamWithTransparencyGroup()
 {
     using (MemoryStream bos = new MemoryStream()) {
         using (PdfWriter writer = new PdfWriter(bos)) {
             using (PdfDocument document = new PdfDocument(writer)) {
                 PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(0f, 0f));
                 formXObject.SetGroup(new PdfTransparencyGroup());
                 PdfAnnotation annotation = new PdfPopupAnnotation(new Rectangle(0f, 0f));
                 annotation.SetNormalAppearance(formXObject.GetPdfObject());
                 PdfPage pageToCheck = document.AddNewPage();
                 pageToCheck.AddAnnotation(new PdfPopupAnnotation(new Rectangle(0f, 0f)));
                 pageToCheck.AddAnnotation(annotation);
                 NUnit.Framework.Assert.That(() => {
                     pdfA2Checker.CheckSinglePage(pageToCheck);
                 }
                                             , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.THE_DOCUMENT_DOES_NOT_CONTAIN_A_PDFA_OUTPUTINTENT_BUT_PAGE_CONTAINS_TRANSPARENCY_AND_DOES_NOT_CONTAIN_BLENDING_COLOR_SPACE))
                 ;
             }
         }
     }
 }
Beispiel #12
0
        /// <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");
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        /// <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");
        }