java - iText : unable to retrieve /Resources from a page -
i'm using itext 5.0.1 manipulate existing pdf. when analyzing existing pdf using rups, can see first page contains /resources :
however, when manipulating pdf using following example, i'm getting npe because pagedictionary.get(pdfname.resources) returning null.
here pagedictionnary object contains when debugging :
unfortunately, because of confidentiality, can't post pdf now, have idea why i'm getting npe ? or have idea how investigate further ? (i'm far being expert itext , pdf structure ... , getting out of idea)
thank !
the sample code use assumes page objects immediate kids of dictionary pointed pages catalog key:
pdfdictionary pages = (pdfdictionary) pdfreader.getpdfobject(reader.getcatalog().get(pdfname.pages)); pdfarray kids = (pdfarray) pdfreader.getpdfobject(pages.get(pdfname.kids)); pdfdictionary pagedictionary = (pdfdictionary) pdfreader.getpdfobject((pdfobject) kids.getarraylist().get(pagenum - 1));
this assumption ok because many pdf producers generate simple page trees, in general page tree can indeed tree depth larger 1, i.e. leafs, page nodes, may deeper down in structure, kids of kids of kids of root pages dictionary etc.
in case of pdf case, page dictionary of page 1 (object 3) kid of pages dictionary object 6 in turn kid of root pages dictionary object 70.
thus, code assumes intermediary pages dictionary object 6 page object.
this not issue of sample code, though. e.g. assumes resources dictionary attached page object itself. need not true, may attached parent pages object including page tree root:
resources dictionary (required; inheritable) dictionary containing resources required page (see 7.8.3, "resource dictionaries"). if page requires no resources, value of entry shall empty dictionary. omitting entry entirely indicates resources shall inherited ancestor node in page tree.
(table 30 – entries in page object - in iso 32000-1, current pdf specification)
so, sample use in general useless not honor pdf specification.
that been said, sample time when newest version of itext 1.02b while using itext 5.0.1... why did not more current sample? wonder after 4 major versions can tweaked compile easily!
in current itext versions can dictionary of given page using pdfreader
method getpagen(final int pagenum)
or getpagenrelease(final int pagenum)
.
you should not expect current pdfreader
method getpageresources(final int pagenum)
return resources of given page, though, (just sample code) looks @ page dictionary resources dictionary
is there specific reason use itext 5.0.1? version pretty old , many bug fixes , features have been applied since then.
Comments
Post a Comment