logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Jonah Coleman  
#1 Posted : Friday, August 31, 2018 2:50:12 PM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
Hello,

I'm trying to locate pages within a PDF with a specific page label.

I have used pdfDocument.Root["PageLabels"] to try an access it through the dictionary, but I don't see a way to use it as a PDFArray type (casting doesn't work). I also thought there might be a pdfDocument.Root.GetArrayBy() function but there is not.

Any suggestions?

Paul Rayman  
#2 Posted : Friday, August 31, 2018 7:21:53 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Seems "PageLabels" it is not an array.
It is a "number tree"

Quote:
PageLabels - number tree - (Optional; PDF 1.3) A number tree (see Section 3.8.6, “Number Trees”)
defining the page labeling for the document. The keys in this tree are
page indices; the corresponding values are page label dictionaries (see
Section 8.3.1, “Page Labels”). Each page index denotes the first page in a
labeling range to which the specified page label dictionary applies. The
tree must include a value for page index 0.


So you should cast it to PdfTypeDictionary.

Description of keys of number tree dictionary can be found here:
http://archimedespalimps...al/pdf_reference_1-7.pdf

on a page 166. (3.8.6 Number Trees).
Guest  
#3 Posted : Tuesday, September 4, 2018 6:21:06 AM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
I really appreciate the reply. This put me on the path to figure it out.

Oddly enough the dictionary contained an item that was an array, which had a pdf dictionary inside it, which finally had the strings for the page labels. Test code that worked:

Code:

                        PdfDocument searchDocument = PdfDocument.Load(pdfFile);
                        PdfTypeIndirect indirectThing = (PdfTypeIndirect)searchDocument.Root.GetBy("PageLabels");
                        PdfTypeDictionary pageLabels = (PdfTypeDictionary)indirectThing.Direct;

                        foreach (PdfTypeBase theValue in pageLabels.Values)
                        {
                            PdfTypeArray ofCourseTheresAnotherArray = (PdfTypeArray)theValue;
                            foreach (var thing in ofCourseTheresAnotherArray)
                            {
                                if (thing is PdfTypeDictionary)
                                {
                                    PdfTypeDictionary anotherDictionary = (PdfTypeDictionary)thing;
                                    foreach (PdfTypeBase andWhyIsThereAnotherDictionary in anotherDictionary.Values)
                                    {
                                        if (andWhyIsThereAnotherDictionary is PdfTypeString)
                                        {
                                            string sheetLabel = ((PdfTypeString)andWhyIsThereAnotherDictionary).UnicodeString;
                                            if (sheetLabel.ToUpper().Contains(drawingTextBox.Text.ToUpper()))
                                            {
                                                foundFilesListView.Items.Add(pdfFile);
                                            }
                                        }
                                    }

                                }
                            }
                        }                            
                            
                        searchDocument.Dispose();

Edited by user Tuesday, September 4, 2018 6:22:32 AM(UTC)  | Reason: Code

Guest  
#4 Posted : Tuesday, September 4, 2018 12:47:50 PM(UTC)
Guest

Rank: Guest

Groups: Guests
Joined: 1/5/2016(UTC)
Posts: 162

Was thanked: 5 time(s) in 5 post(s)
FYI it turns out that PDF's vary in where the actual data is held- sometimes in dictionaries containing dictionaries containing arrays, you have to follow indirects, etc.

I ended up writing code to run the whole damn tree through.
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.