Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a new PDF document.
            PdfDocument pdf = new PdfDocument();

            //Load the file from disk.
            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\Template_Pdf_3.pdf");

            //Get all annotations from the first page.
            PdfAnnotationCollection annotations = pdf.Pages[0].AnnotationsWidget;

            StringBuilder content = new StringBuilder();

            for (int i = 0; i < annotations.Count; i++)
            {
                //A text annotation will attach a popup annotation since they are father-son relationship.
                //The annotation information exists in the text annotation, so here we mask the blank popup annotation.
                if (annotations[i] is PdfPopupAnnotationWidget)
                {
                    continue;
                }
                content.AppendLine("Annotation information: ");
                content.AppendLine("Text: " + annotations[i].Text);
                string modifiedDate = annotations[i].ModifiedDate.ToString();
                content.AppendLine("ModifiedDate: " + modifiedDate);
            }

            String result = "Result-GetAllAnnotationsFromPage.txt";

            //Save to file.
            File.WriteAllText(result, content.ToString());

            //Launch the file.
            PDFDocumentViewer(result);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a new PDF document.
            PdfDocument pdf = new PdfDocument();

            //Load the file from disk.
            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\Template_Pdf_3.pdf");

            //Get the annotation collection from the document.
            PdfAnnotationCollection annotations = pdf.Pages[0].AnnotationsWidget;

            //Get particular annotation information from the document.
            StringBuilder content = new StringBuilder();

            if (annotations[0] is PdfTextAnnotationWidget)
            {
                PdfTextAnnotationWidget textAnnotation = annotations[0] as PdfTextAnnotationWidget;
                content.AppendLine("Annotation text: " + textAnnotation.Text);
                content.AppendLine("Annotation ModifiedDate: " + textAnnotation.ModifiedDate.ToString());
                content.AppendLine("Annotation author: " + textAnnotation.Author);
                content.AppendLine("Annotation Name: " + textAnnotation.Name);
            }


            String result = "GetParticularAnnotationInfo_out.txt";


            //Save to file.
            File.WriteAllText(result, content.ToString());

            //Launch the file.
            DocumentViewer(result);
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Load file from disk
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\LinkAnnotation.pdf");

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

            //Get the annotation collection
            PdfAnnotationCollection annotations = page.AnnotationsWidget;

            //Create StringBuilder to save
            StringBuilder content = new StringBuilder();

            //Verify whether widgetCollection is not null or not
            if (annotations.Count > 0)
            {
                //traverse the PdfAnnotationCollection
                foreach (PdfAnnotation pdfAnnotation in annotations)
                {
                    //if it is PdfTextWebLinkAnnotationWidget
                    if (pdfAnnotation is PdfTextWebLinkAnnotationWidget)
                    {
                        //Get the Url
                        PdfTextWebLinkAnnotationWidget WebLinkAnnotation = pdfAnnotation as PdfTextWebLinkAnnotationWidget;
                        string url = WebLinkAnnotation.Url;

                        //Add strings to StringBuilder
                        content.AppendLine("The url of link annotation is " + url);
                        content.AppendLine("The text of link annotation is " + WebLinkAnnotation.Text);
                    }
                }
            }

            String result = "GetLinkAnnotation_out.txt";

            //Save them to a txt file
            File.WriteAllText(result, content.ToString());

            //Launch the file
            DocumentViewer(result);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Load file from disk
            doc.LoadFromFile(@"..\..\..\..\..\..\Data\LinkAnnotation.pdf");

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

            //Get the annotation collection
            PdfAnnotationCollection annotations = page.AnnotationsWidget;

            //Verify whether widgetCollection is not null or not
            if (annotations.Count > 0)
            {
                //traverse the PdfAnnotationCollection
                foreach (PdfAnnotation pdfAnnotation in annotations)
                {
                    //if it is PdfTextWebLinkAnnotationWidget
                    if (pdfAnnotation is PdfTextWebLinkAnnotationWidget)
                    {
                        //Get the link annotation
                        PdfTextWebLinkAnnotationWidget annotation = pdfAnnotation as PdfTextWebLinkAnnotationWidget;

                        //Change the url
                        annotation.Url = "http://www.e-iceblue.com/Introduce/pdf-for-net-introduce.html";
                    }
                }
            }
            String result = "ExtractAndUpdateLink_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a new PDF document.
            PdfDocument pdf = new PdfDocument();

            //Load the file from disk.
            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\UpdateFreeTextAnnotation.pdf");

            //Get the annotation Collection from the document.
            PdfAnnotationCollection annotations = pdf.Pages[0].AnnotationsWidget;

            //Update free text annotation.
            foreach (PdfFreeTextAnnotationWidget annotaion in annotations)
            {
                annotaion.Color = Color.YellowGreen;
            }

            String result = "UpdateFreeTextAnnotation_out.pdf";

            //Save the document
            pdf.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Example #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load an existing PDF file
            PdfDocument document = new PdfDocument();

            document.LoadFromFile(@"..\..\..\..\..\..\Data\RemoveHyperlinks.pdf");

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

            //Get the annotation collection
            PdfAnnotationCollection widgetCollection = page.AnnotationsWidget;

            //Verify whether widgetCollection is null or not
            if (widgetCollection.Count > 0)
            {
                for (int i = widgetCollection.Count - 1; i >= 0; i--)
                {
                    PdfAnnotation annotation = widgetCollection[i];
                    //Get the TextWebLink Annotation
                    if (annotation is PdfTextWebLinkAnnotationWidget)
                    {
                        PdfTextWebLinkAnnotationWidget link = annotation as PdfTextWebLinkAnnotationWidget;
                        //Remove the TextWebLink annotation
                        widgetCollection.Remove(link);
                    }
                }
            }

            string output = "RemoveHyperlinks-result.pdf";

            document.SaveToFile(output);

            //Launch the Pdf file
            PDFDocumentViewer(output);
        }