It seems my problem is indeed with that setData() uses some sort of
compression filter on the data, which is not desirable when dealing with
JPEG. I added a simple method setDataRaw() in
com/lowagie/text/pdf/PRStream.java like this:
public void setDataRaw (byte[] data)
{
this.offset = -1;
bytes = data;
setLength(bytes.length);
}
And calling this instead of setData() when dealing with JPEG fixes my
problem. What I am asking for now is, I guess, if there are any official
way of achieving the same effect as I have with my method. (I see that
this result is also achieved with setData() if the Document.compression
field is false, but I'm not sure that is the correct way either.) Because
I don't really want to make my own changes in the iText library since that
makes upgrading so much more difficult in the future.
Any word on this?
Regards,
Petter Nyström
On Mon, 17 Apr 2006, Petter Nyström wrote:
Good evening list!
This problem might not have anything to do with Itext as such. It's mostly a
cry out to see if anyone on this list have an idea for a solution to my
problem. I hope that is okay.
My problem then, is this: I extract images from PDF documents using Itext.
Sometimes, this is a JPEG/JFIF image. (I treat any image with a DCTDecode
filter as a JPEG. Is that incorrect?) I then convert extracted images into
TIFF and perform some image processing before they are turned back into their
internal PDF format, e.g. JPEG or raw CMYK etc.. The image format conversions
are made with the ImageMagick API.
I then proceed to replace the data of the images in the PDF with the data of
the images that has gone through conversion and image processing. For this I
use the setData() method in the PRStream object of the images I find in the
PDF, and a PdfStamper to write a new PDF.
The unfortunate result is that JPEG images in the new PDF document appear
garbled, while other image formats I have been working with come through
fine.
My premier theory to explain this is that the JPEG image generated by
ImageMagick is somehow not compatible with what is standard within the PDF.
So while ImageMagick can make sense out of a JPEG come from a PDF, a PDF
cannot make sense out of a JPEG come from ImageMagick.
My secondary theory is that there could be some problem with how I do the
replacement. Should I have to apply some filters to the data before I call
the setData() method?
Obviously I have tried a whole lineup of approaches but always with the same
dissapointing result. So this mail is a hope that someone out there has a
clue as to what might go wrong and what one might do to stop it from doing
so. If you have one such clue, please let me know of it!
Regards,
Petter Nyström
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions