示例#1
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);
        }
示例#3
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);
        }