java - iText: Setting image interpolation for images on a page -
i want iterate through pages of pdf , write new pdf images have interpolation set false. expecting able following, cannot find method of accessing images or rectangles on pdf page.
pdfcopy copy = new pdfcopy(document, new fileoutputstream(outfilename)); copy.newpage(); pdfreader reader = new pdfreader(infilename); for(int = 1; <= reader.getnumberofpages(); i++) { pdfimportedpage importedpage = copy.getimportedpage(reader, i); for(image image : importedpage.images()) image.isinterpolated(false); copy.addpage(importedpage); } reader.close();
there is, however, no pdfimportedpage.images(). suggestions on how might otherwise same?
cheers
nik
it won't easy. there's no high-level way of doing want. you'll have enumerate resources looking xobject images, , clear /interpolate flag.
and you'll have before creating pdfimportedpage because there's no public way access resources. grr.
void removeinterpolation( int pagenum ) { pdfdictionary page = somereader.getpagen(pagenum); pdfdictionary resources = page.getasdict(pdfname.resources); enumresources(resources); } void enumresource( pdfdictionary resources) { pdfdictionary xobjs = resources.getasdict(pdfname.xobjects); set<pdfname> xobjnames = xobjs.getkeys(); (pdfname name : xobjnames) { pdfstream xobjstream = xobjs.getasstream(name); if (pdfname.form.equals( xobjstream.getasname(pdfname.subtype))) { // xobject forms have own nested resources. pdfdictionary nestedresources = xobjstream.getasdict(pdfname.resources); enumresources(nestedresources); } else { xobjstream.remove(pdfname.interpolate); } } }
there's quite bit of null-checking that's skipped in above code. page doesn't have have resource dictionary, though do. ditto xobject forms. getas*
functions return null if given key missing or of different type... idea.
Comments
Post a Comment