Hello, I'm currently evaluating iTextPDF for a project and now I'm stuck with a problem.
My use case requires me to find the left image (PDF format) in the document and
do some stuff with it and then do the same thing with the right image. The
PDF-document is created by In-design and the images does not have any
specialId. At first I just thought I would traverse all images and then compare
there filenames to see if I found the right one, but as I understand the
filenames are not preserved when adding them to a PDF-document.
I then tried to use the image's metadata (which I can see in XML if I look at
the file in a texteditor) by addin a title attribute and check against that,
but I couldn't find how to get hold on this metadata from a PdfObject/PdfImage.
I then placed the images in there own layer called left and right and tried to
either traverse the layers to find the each layers image or traversing all
images and checking what layer they belong to.
I've read the book, looked on all the examples and done a lot of experiment and
so far:
* I successfully retrieved the layers with PdfStamper
PdfStamper stamper = new PdfStamper(new PdfReader(src), new
FileOutputStream(dest));
Map<String, PdfLayer> layers = stamper.getPdfLayers();
PdfLayer layer = layers.get("left");
However I can not find any references to the image(s) contained in this
layer.
* Found the Image element in two ways
1. int n = reader.getXrefSize();
PdfObject object;
PRStream stream;
for (int i = 0; i < n; i++) {
object = reader.getPdfObject(i);
stream = (PRStream)object;
if (stream.get(PdfName.SUBTYPE) != null &&
stream.get(PdfName.SUBTYPE).equals(PdfName.IMAGE)){
PdfImageObject image = new PdfImageObject(stream);
}
}
2. Using PdfReaderContentParser as in the ExtractImages example.
However, I haven't been able to find any reference to the layer in the
PdfImageObjects that I retrieve.
* Export the simple structure with TaggedPdfReader
TaggedPdfReaderTool reader = new TaggedPdfReaderTool();
reader.convertToXml(new PdfReader(src), new
FileOutputStream("/tmp/kaka.xml"));
But then I only get the following structure (no images)
<Document>
<Article>
<Left></Left>
<Right></Right>
</Article>
</Document>
I would really appreciate any pointers how to proceed with this.
Thank you
Lukas Johansson
itext-evaluation.pdf
Description: itext-evaluation.pdf
------------------------------------------------------------------------------ BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions iText(R) is a registered trademark of 1T3XT BVBA. Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/ Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
