I have been searching the mailing list archives and using Google for hours and 
haven't found the answer, so I am asking here.
 
I have a pdf that I need to split based on the outlines. I have been parsing 
the iText objects trying to find the answer with no
luck so far. I have looked at the Split example and have gotten pretty close, 
but I can't seem to get the page numbers that I need.
 
First I get the catalog:
 
---------------------------------
Dictionary of type: /Catalog : 
/Type = /Catalog
/Outlines = 3 0 R
/PageMode = /UseOutlines
/Pages = 974 0 R
---------------------------------

and make sure the pdf has /PageMode = /UseOutlines, then I get the outlines 
Dictionary:
 
---------------------------------
Dictionary : 
/Count = 74
/Last = 2151 0 R
/First = 51 0 R
---------------------------------

I note the count and then recurse through the entries, starting with the first:
 
Parsing 74 entries.
 
Starting entry: 1.
 
Parsing entry: 1.
---------------------------------
Dictionary : 
/Next = 79 0 R
/Parent = 2 0 R
/Dest = [54 0 R, /XYZ, 999, 999, 0]
/Title = 1: 5401770001207812
/Count = -2
/Last = 66 0 R
/First = 52 0 R
---------------------------------
 
I will use the /next entries to go through all of the entries and, at the end, 
check that I have iterated through 74 entries and
that the final entry is equal to the original /Last or 2151 0 R.
 
>From this entry I get a /Count of 2 sub entries. I use the /First, /Last and 
>/Next as above to ensure that I got all the entries and
that the end result is that the final entry = /Last.
 
I use the title to create the name for the pdf and go into the first sub-entry:
 
Creating PDF 1-5401770001207812.pdf with 2 entries.
---------------------------------
Dictionary : 
/Next = 66 0 R
/Parent = 51 0 R
/Dest = [54 0 R, /XYZ, 999, 999, 0]
/Title = WF Stmt Document with Check
/Count = -4
/Last = 65 0 R
/First = 56 0 R
---------------------------------

>From this I can see that I have 4 sub-entries and that this is not a page. I 
>get the first one:
 
---------------------------------
Dictionary : 
/Next = 59 0 R
/Parent = 52 0 R
/Dest = [54 0 R, /XYZ, 999, 999, 0]
/Title = 1: WF Stmt Page with Check
---------------------------------

This is a still a PdfDictionary, but it is for a page of the document. I try to 
get the page:
 
First page.
---------------------------------
Dictionary of type: /Page : 
/Parent = 55 0 R
/Contents = 53 0 R
/Type = /Page
/Resources = 5 0 R
/MediaBox = [0, 0, 498, 792]
---------------------------------

And here is where I am failing. This says that it's a /Page, but I can't cast 
it to a PdfPage. I get a ClassCastException that says
I can't cast from a PdfDictionary to a PdfPage. Fine, I can see that it reads 
"Dictionary of type". This is the entry 54 0 R. I want
to keep all of the outline/bookmarks/whatever you want to call them in the new 
document. I also want to be able to pull just the
pages that are associated with bookmarks. One of my earlier attempts used the 
/Counts to get the page total for each entry and just
count from 1 to 1 + count, using the end of the last operation as the first 
page of the next one, but this didn't put all of the
right pages into the right pdfs.
 
What I really need is a way to get the page numbers, the int's, for each page 
so I can use PdfCopy's addPage. Any help would be
appreciated. If there is a better way to extract the contents of a pdf as 
referenced by nested outlines into a new one, please let
me know. If this is discussed elsewhere, links are helpful too. Thanks.
 
I also tried several of the .toPdf methods to no avail. I'm guessing it added 
the dictionary, but not the content the dictionary
referred to.
 
Edward W. Rouse

ComSquared Systems, Inc.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to