Hi,
I tried it but just doing this didn't suffice, as in content i am (still) refering to a non-existing XObject. To do this I am removing the XObject from resource of page2 (say) and putting the XObject to this resource.
Also I am facing one more problem. Is there any I can create image from the image data in pdf? I have searched archives for related issues, and found quite a few but none of them leads to solution.
As below I am trying to get the data from PRStream but not able to created image, even if stream is filtered. What addition I need to do to get the image from this stream?


Thanks
aqueel

Paulo Soares <[EMAIL PROTECTED]> wrote:
Replace the reference in Resources/XObject to the other images with your image, that is already present in the PDF.

Paulo

________________________________

De: [EMAIL PROTECTED] em nome de aqeel saifi
Enviada: qua 01-Nov-06 06:27
Para: Post all your questions about iText here
Assunto: Re: [iText-questions] Modifying the images in PDF


Thanks a lot Paulo.
This worked fine for the pre-existing image file. I was trying to get image data from pdf and replacing the others with this image, but failed to do so. My code is as follows...

PdfDictionary pg = reader.getPageN(i + 1);
PdfDictionary res = (PdfDictionary)PdfReader.getPdfObject(pg.get(PdfName.RESOURCES));
PdfDictionary xobj = (PdfDictionary)PdfReader.getPdfObject(res.get(PdfName.XOBJECT));
byte[] imageData = null;

if (xobj != null) {
for (Iterator it = xobj.getKeys().iterator(); it.hasNext();) {
PdfObject obj = xobj.get((PdfName)it.next());
if (obj.isIndirect()) {
PdfDictionary tg = (PdfDictionary)PdfReader.getPdfObject(obj);
PdfName type = (PdfName)PdfReader.getPdfObject(tg.get(PdfName.SUBTYPE));
if (PdfName.IMAGE.equals(type)) {
imageData = PdfReader.getStreamBytesRaw((PRStream) obj);
}
}
}
}

Image img = Image.getInstance(imageData ); // here it the problem

.......
Code to replace the image
.......

The problem, i believe lies, in getting image data from PdfReader. getStreamBytesRaw just returns raw data, not neccecarily in format image is expecting.
Is it possible to get image data from pdf to recreate the image?

Thanks
aqueel






----- Original Message ----
From: Paulo Soares <[EMAIL PROTECTED]>
To: Post all your questions about iText here
Sent: Tuesday, 31 October, 2006 4:35:07 PM
Subject: Re: [iText-questions] Modifying the images in PDF


Here's the code to replace images in PDFs. It will replace
the first image in the first page.

PdfReader pdf = new PdfReader("in.pdf");
PdfStamper stp = new PdfStamper(pdf, new
FileOutputStream("c:\\out.pdf"));
PdfWriter writer = stp.getWriter();
Image img = Image.getInstance("image.png");
PdfDictionary pg = pdf.getPageN(1);
PdfDictionary res =
(PdfDictionary)PdfReader.getPdfObject(pg.get(PdfName.RESOURCES));
PdfDictionary xobj =
(PdfDictionary)PdfReader.getPdfObject(res.get(PdfName.XOBJECT));
if (xobj != null) {
for (Iterator it = xobj.getKeys().iterator(); it.hasNext();) {
PdfObject obj = xobj.get((PdfName)it.next());
if (obj.isIndirect()) {
PdfDictionary tg =
(PdfDictionary)PdfReader.getPdfObject(obj);
PdfName type =
(PdfName)PdfReader.getPdfObject(tg.get(PdfName.SUBTYPE));
if (PdfName.IMAGE.equals(type)) {
PdfReader.killIndirect(obj);
Image maskImage = img.getImageMask();
if (maskImage != null)
writer.addDirectImageSimple(maskImage);
writer.addDirectImageSimple(img,
(PRIndirectReference)obj);
break;
}
}
}
}
stp.close();

Paulo

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of aqeel saifi
> Sent: Tuesday, October 31, 2006 7:44 AM
> To: [email protected]
> Subject: [iText-questions] Modifying the images in PDF
>
> Hi All,
> As far as I have digged, we can not directly modify the
> images in pdf file with iText. Although we can get the image
> data from the XObject. right?
> Actually I intend to create a new pdf from an existing one
> with some of the contained images changed/repalced with some other.
> As we can't replace image directly with iText, I have two
> options in mind to achieve this.
> a. Is it possible that I render the changed image (different
> image) on the existing image position to give the effect that
> image is actually changed.
> b. Other could be, if possible, I create new pdf from the
> existing one and all the pdf objects to new one except the
> images to be modified. In place of these images I can add my
> changed images to new pdf.
>
> Please guide if any of this is feasible, please share if you
> have any other option in mind.
>
> Any help would be greatly appreciated.
>
> Thanks
> aqueel
>
> ________________________________
>
> Find out what India is talking about on - Yahoo! Answers
> India
>
> hoo.com/>
> Send FREE SMS to your friend's mobile from Yahoo! Messenger
> Version 8. Get it NOW
>
> ssenger.yahoo.com>
>


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions



________________________________

Find out what India is talking about on - Yahoo! Answers India
Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter informação confidencial ou legalmente protegida. A incorrecta transmissão desta mensagem não significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions


Find out what India is talking about on - Yahoo! Answers India
Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to