Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Aug 26, 2021 3:22 pm

In the example pdf, the attachment is located on page 17498. Using the spire, I can get the data, but I couldn't find a way to identify the number where this attachment was in the pdf.

the test pdf is very large, i uploaded it on a website and the access link is in the attachment sent to you, you can download the attachment here for 7 days

How to identify the page where the attachment is located, is it possible?

Code: Select all
 public void test2()
        {
            string location = @"C:\pdf\test_page17498.pdf";
            Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument(location);           
           
            Spire.Pdf.Attachments.PdfAttachmentCollection collection = pdf.Attachments;

            string attExtPath = @"C:\PDFReader\Extract\";

            if (!Directory.Exists(attExtPath))
                Directory.CreateDirectory(attExtPath);
            foreach (Spire.Pdf.Attachments.PdfAttachment att in collection.List)
            {

                System.IO.File.WriteAllBytes(attExtPath + att.FileName, att.Data);
            }
        }

ldin2021
 
Posts: 1
Joined: Wed Aug 25, 2021 7:55 pm

Fri Aug 27, 2021 10:56 am

Hello,

Thank you for your inquiry.
After investigating the PDF file you provided, I found that the attachment link on page 17498 is an Action. Sorry currently we do not support getting Action. We will consider adding it as a new feature into our future upgrade, if it can be achieved in the future, I will inform you.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Dec 08, 2021 8:24 am

Hello,

Thanks for your patience.
Glad to inform you that we just released Spire.PDF Pack(Hot Fix) Version:7.12.1 , which achieved the requirement to read the number of pages where attachments are located. Please download the new version from the following links for testing.
Website link:
https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
Nuget link:
https://www.nuget.org/packages/Spire.PDF/7.12.1
https://www.nuget.org/packages/Spire.PDF.NETCore/7.12.1
Code: Select all
 static void Main(string[] args)
 {
     PdfDocument pdf = new PdfDocument();
     pdf.LoadFromFile(inputFile);
     PdfAttachmentCollection collection = pdf.Attachments;
     foreach (PdfAttachment pdfAttachment in collection )
     {
         string filename = pdfAttachment.FileName;
         int pageIndex = GetAttachmentPage(pdf.Pages, filename);
         Console.WriteLine(pageIndex);
     }
 }
 private static int GetAttachmentPage(Spire.Pdf.Widget.PdfPageCollection pageCollection, string fileName)
 {
     if (string.IsNullOrEmpty(fileName))
     {
         throw new ArgumentException("fileName is null or empty");
     }
     for (int i = 0; i < pageCollection.Count; i++)
     {
         PdfPageBase page = pageCollection[i];
         for (int j = 0; j < page.AnnotationsWidget.Count; j++)
         {
             PdfFileLinkAnnotationWidget pdfFileLinkAnnotationWidget = page.AnnotationsWidget[j] as PdfFileLinkAnnotationWidget;
             if (pdfFileLinkAnnotationWidget != null)
             {
                 if (fileName.Equals(pdfFileLinkAnnotationWidget.FileName))
                 {
                     return i;
                 }
             }
         }
     }
     return -1;
 }

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Dec 17, 2021 9:04 am

Hello,

Hope you are doing well!
Have you tried the new version of Spire.PDF? Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF

cron