> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On
> Behalf Of Antonios Papadakis-Pesaresi
> Sent: Monday, January 07, 2008 1:52 PM
> To: [email protected]
> Subject: [iText-questions] BMP in PDFs
>
> Hello,
>
> I am trying to add & retrieve a bmp image in the last page of
Add is ok, retrieve is, well, maybe.
> a pdf file using iText. My code, so far, is the following:
>
> private void cmd_addImageToPDF() throws Exception {
>
> PdfReader reader = new PdfReader(pdfFileName.getName());
> PdfStamper stamp = new PdfStamper(reader, new
> FileOutputStream("output.pdf"));
> PdfWriter writer = stamp.getWriter();
> PdfContentByte content =
> stamp.getOverContent(reader.getNumberOfPages());
> com.lowagie.text.Image img =
> com.lowagie.text.Image.getInstance(BMPFileLocation);
>
> //img.setDirectReference(new PRIndirectReference(reader, 10));
> img.setAbsolutePosition(450,10);
> content.addImage(img);
>
> stamp.close();
> reader.close();
> }
>
> The image is added perfectly in the last page of the pdf.
>
> The problem comes when I try to retrieve and re-create the
> BMP image. The code goes like that:
>
> private void retrieveImageFromPDF() {
>
> try {
>
> PdfReader reader = new PdfReader(pdfFileName.getName());
>
> for (int i = 0; i < reader.getXrefSize(); i++) {
> PdfObject pdfobj = reader.getPdfObject(i);
> if (pdfobj != null) {
> if (pdfobj.isStream()) {
> PdfStream pdfdict = (PdfStream) pdfobj;
> PdfObject pdfsubtype = pdfdict.get(PdfName.SUBTYPE);
> if (pdfsubtype == null) {
> continue;
> }
> if (!pdfsubtype.toString().equals(
> PdfName.IMAGE.toString())) {
> continue;
> }
> System.out.println("height:"
> + pdfdict.get(PdfName.HEIGHT));
> System.out.println("width:"
> + pdfdict.get(PdfName.WIDTH));
> System.out.println("bitspercomponent:"
> + pdfdict.get(PdfName.BITSPERCOMPONENT));
> System.out.println(pdfdict.getRawLength()+" ");
> byte[] barr = PdfReader.getStreamBytesRaw((PRStream) pdfdict);
Use getStreamBytes.
>
> stegoImage = Toolkit.getDefaultToolkit().createImage(barr);
> System.out.println(pdfdict.toString()+" ");
>
> System.out.println(barr.length);
>
> for ( int a = 0; a < barr.length; a++ )
> System.out.print(barr[a]+" ");
>
> return;
> }
> }
> }
> } catch (IOException ioe) {
> ioe.printStackTrace();
> }
> }
>
> So when stegoImage (awt.Image) is re-created by the pdf file,
> I try to write it to a file, using a specific class
> re-creating the BMP file using the raw data (awt.Image --> File bmp).
The raw data is flate encoded (if the bmp was added with iText), you
need the decoded bytes, as above.
> But all I am left with is a black bmp image.
>
> Is this the correct way to go, or am I missing something?
It's the correct way to go but you're assuming that the pdf has a bmp
when in reality the bmp was processed and changed to be a pdf image.
> Should I retrieve the image's bytes using something like pdfbox?
Pdfbox will get you the image, not the individual bytes, but that a
question to ask them.
>
> My main requirement is to retrieve the image bytes, exactly
> as they are, because I am "embedding" hidden information in
> them, which will be retrieved
> using other functions operating on the bmp file.
>
That's impossible, any bmp added to a pdf will be completely changed. In
fact, it's not a bmp anymore.
Paulo
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.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/