On Tue, Apr 27, 2010 at 8:59 AM, 1T3XT info <[email protected]> wrote: > A Cheung wrote: > > Hello, > > I have spent quite a while investigating the > > automated removal/replacement of images in a PDF. (ex: 100 page pdf, 1 > > image per page needs replacing, but each page also has text which I want > > to keep) > > > > Strategy 1: > > Find the XObject, KillIindirect() it, remove it from the XObject > Dictionary. > > Won't work. > > You can't remove an image stream if it's referred to, for instance > from a Resources dictionary of a page. > > You can't remove an object /Im0 from the Resources dictionary, > if you don't remove the /Im0 Do from the content stream. > > This is way to complicated for what you need. >
Complicated yes, but is it theoretically possible with iText? Can it modify these streams and save the modifications? GUI Editors/Applications that do allow the removal of images must be doing it somehow. > Strategy 2: Replace it, > > Similar to http://1t3xt.info/examples/browse/?page=example&id=421 > <http://1t3xt.info/examples/browse/?page=example&id=421> This is a better strategy, but the example only works for JPEG images. > > > Is there some newer process that makes this easy? Snippets of existing > > code? > > This is an update of the example you refer to: > http://itextpdf.com/examples/index.php?page=example&id=286 > > Instead of using the old image to "resize" the image, you need > to create the BufferedImage and use drawString() instead of > drawRenderedImage(). You may also want to create another type > of image, for instance a PNG instead of a JPEG, in which case > you'll need to use a different Filter and stuff. > > Retrieving the text from the original image isn't possible. > Thanks, but my question is then about Colorspaces. I am trying to keep the PDF small so making images of 16M colours makes it too large. PdfContentByte p = stamper.getOverContent(1); p.addImage(Image.getInstance("my.tiff"), width,0,0,height,0,0) The above code adds an image (Xi0) to my file with the Colorspace that is correct. (It isn't DeviceGray or DeviceRGB). I use the Enfocus Browser to see the PDF object tree structure and this new "Xi0" image has a ColorSpace array[4] and item [3] is the stream data for the colorspace of 256 specific colors in use. What I'd like to do is have iText create this Colorspace structure for me based on an image file (along with Filter/Width/BitsPerComponent) so I can replace my original Im0 structure with that data (as in the sample at your URL), but _without_ having to add an Xi0 to the PDF to do it since that just leaves me with another image that I'd want to remove. Possible?
------------------------------------------------------------------------------
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
