Julien,

Doesn't this code[1] create a new image object which is in no way attached 
to the PDF?  Modifying "(COSStream) obj.getObject()" seems like it'd do 
what you intend.  I'm not familiar with PDXObject.createXObject(), but it 
seems like that'd be creating a copy of the data passed it (similar to a 
copy constructor).  Obviously modifying a copy isn't going to affect the 
original.

I'm pretty sure that's your problem, but I've never done anything with 
streams nor images in PDFs, so I'm afraid I don't know the way to it's 
supposed to be done.

Another thing which might be important: some PDF programs don't write out 
anything in the xref table.  This doesn't follow the spec, but Adobe 
Reader opens them fine either way, so many people don't realize they're 
out of spec (and thus expect your code to process them the same as a 
proper PDF).

[1] PDXObjectImage image = (PDXObjectImage) 
PDXObject.createXObject((COSStream) obj.getObject() );

---- 
Thanks,
Adam





From:
Julien Plée <[email protected]>
To:
[email protected]
Date:
08/25/2010 15:00
Subject:
Replacing images contents



Hello,

I have to put a watermark stamp on images stored in PDF files and I'm 
having hard times trying to embed images back into the PDF.
I'm using the XrefTable to filter images. For embedding, I'm trying to 
replace the stream of the original object but with no luck, the saved 
PDF always looks the same.
Here is my method code focused on the PDXObjectImage :

/**
  * Replaces a PDF image content with content from an image file on file
  * system identified by the object id.
  *
  * (this.doc : PDDocument)
  * @param obj
  * @throws IOException
  */
protected void embedImageBack(COSObject obj) throws IOException
{
                 String path = "img/";
                 PDXObjectImage image = (PDXObjectImage) 
PDXObject.createXObject(
                                                 (COSStream) 
obj.getObject() );
                 File inputFile = new File(
 path+obj.getObjectNumber()+"."+image.getSuffix() );
                 PDXObjectImage newImage = null;
                 if (image.getSuffix().equals("jpg"))
                                 newImage = new PDJpeg( this.doc, new 
FileInputStream(inputFile) );
                 else
                                 newImage = new PDCcitt( this.doc,
 (RandomAccess) new RandomAccessFile( inputFile, "r" ) );
 image.getCOSStream().replaceWithStream(newImage.getCOSStream());
                 this.shouldSaveDoc = true;
}

After all images have been processed, I save the document in a new 
file, but except that the file size changes, nothing else visible 
happens.
Thanks for any help.

Julien PLÉE


?  Click here to submit conditions  

This email and any content within or attached hereto from  Sun West Mortgage 
Company, Inc.  is confidential and/or legally privileged. The information is 
intended only for the use of the individual or entity named on this email. If 
you are not the intended recipient, you are hereby notified that any 
disclosure, copying, distribution or the taking of any action in reliance on 
the contents of this email information is strictly prohibited, and that the 
documents should be returned to this office immediately by email. Receipt by 
anyone other than the intended recipient is not a waiver of any privilege. 
Please do not include your social security number, account number, or any other 
personal or financial information in the content of the email. Should you have 
any questions, please call  (800) 453 7884.   

Reply via email to