Hello to itext user,

i have a problem to replace an jpeg image inside an existing pdf document.

First i check if an xobject is inside the pdf document, if i found one i get 
the PRStream from this object.
Then i create an PdfImageObject read the data and save this to the filesystem 
(this image i can open with photoshop etc.)
Then i clear the prstream and read the save image to replace (for test i use 
the image saved before, so this is exact the same image),
i do all necessary settings like before, but the saved PDF document doesn't 
show the image. 

I got an error from acrobat "not enough memory" and when i try to open this 
saved image i got an error from photoshop "wrong jpeg mark found".

any idea's?



here is the code snippet:

stream.clear();

stream.put(PdfName.TYPE, PdfName.XOBJECT);
stream.put(PdfName.SUBTYPE, PdfName.IMAGE);
stream.put(PdfName.WIDTH, new PdfNumber(replaceImage.getWidth()));
stream.put(PdfName.HEIGHT, new PdfNumber(replaceImage.getHeight()));


switch (replaceImage.type())
        {
        case Image.JPEG:
                                
        switch (replaceImage.getColorspace())
                {
                case 1:
                stream.put(PdfName.COLORSPACE, PdfName.DEVICEGRAY);
                break;
                case 3:
                stream.put(PdfName.COLORSPACE, PdfName.DEVICERGB);
                break;
                default:
                stream.put(PdfName.COLORSPACE, PdfName.DEVICECMYK);
                                                
                if (replaceImage.isInverted())
                        {
                        stream.put(PdfName.DECODE, new PdfLiteral("[1 0 1 0 1 0 
1 0]"));
                        }
                }
                stream.put(PdfName.BITSPERCOMPONENT, new PdfNumber(8));
                stream.put(PdfName.LENGTH, new PdfNumber(image.length));
                                
                stream.setData(image);
                                
                stream.put(PdfName.FILTER, PdfName.DCTDECODE);
}

with regards

Thomas Kübler
                                








------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
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

Reply via email to