Working on it... Paulo
> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of Petter Nyström > Sent: Thursday, May 04, 2006 4:46 PM > To: [email protected] > Subject: RE: [iText-questions] Far cry for help with JPEG in PDF > > Hello again! > > On Thu, 27 Apr 2006, Paulo Soares wrote: > > > It can't be done in a reliable way without changing the > library. I'll > > get back to you next week with some kind of solution. > > I was just wondering if you (or anyone) had got around to this? It is > clear that you have no shortage of questions from this list > though, so > I'll be patient. > > Thanks, > > Petter > > >> -----Original Message----- > >> From: [EMAIL PROTECTED] > >> [mailto:[EMAIL PROTECTED] On > >> Behalf Of Petter Nyström > >> Sent: Thursday, April 27, 2006 12:15 PM > >> To: [email protected] > >> Subject: RE: [iText-questions] Far cry for help with JPEG in PDF > >> > >> On Mon, 17 Apr 2006, Paulo Soares wrote: > >> > >>> You shouldn't be messing with PRStream. Create a new > PdfStream with > >>> the right filters to replace the old PRStream. Don't > forget to kill > >>> the old PRStream with PdfReader.killIndirect(). > >> > >> I have been pondering this and trying to do things the > right way as > >> hinted at by Paulo Soares, but I haven't managed to get it > working out. > >> The code I have that works (but requires a hack in the > iText library in > >> its full version) looks something like this in a very > condensed form: > >> > >> void foo (PRStream image) > >> { > >> File file = new File("someimage.cmyk"); > >> FileInputStream stream = new FileInputStream(file); > >> byte[] data = new byte[file.length()]; > >> > >> stream.read(data, 0, file.length()); > >> image.setData(data); > >> } > >> > >> If I am not to mess with the PRStream but instead make a > new PdfStream, > >> my problem revolves around how to set up the new PdfStream > in a manner > >> so it has all the properties of the old one. I can copy the > >> PdfDictionary values easily enough, but I also need to > make sure it has > >> the same positions etc. within the document. Since the one > and only > >> thing I wish to do is really to replace the stream data, > the suggested > >> solution seems like a lot more work to me. Work that I > can't even get > >> right at the moment. But I still want to do this "the > right way" and > >> absolutely don't want to resort to hacking the iText > library. So I am > >> interested in how to set up this new PdfStream object in > such a way > >> that it will completely replace the old one. Answers are > appreciated, > >> as usual. > >> > >> Regards, > >> > >> Petter Nyström > >> > >> P.S. I see how a few same people answer dozens of > questions on this > >> list every day, and I would just like to say that your efforts are > >> noticed and greatly appreciated! =) D.S. > >> > >>>> -----Original Message----- > >>>> From: [EMAIL PROTECTED] > >>>> [mailto:[EMAIL PROTECTED] On > >>>> Behalf Of Petter Nyström > >>>> Sent: Monday, April 17, 2006 1:14 PM > >>>> To: [email protected] > >>>> Subject: Re: [iText-questions] Far cry for help with JPEG in PDF > >>>> > >>>> 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 > > > ------------------------------------------------------- > 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=k&kid0709&bid&3057&dat1642 > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > ------------------------------------------------------- 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&kid0709&bid&3057&dat1642 _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
