Great suggestion and good reasoning! Before than trying it on the server I have tryed something similar on my own computer, and found that the problem is not in constructing the PdfReader from the String with the PDF document content. I wrote the following simple method, which watermarks my original String, saving the resulting PDF document on a file and also sending it to the browser:
public static String preWaterMark(String pdfContent, String image) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { PdfReader reader = new PdfReader(pdfContent.getBytes("ISO-8859-1")); PdfStamper stamp = new PdfStamper(reader, baos); waterMark(reader, stamp, image); reader.close(); stamp.close(); PdfReader reader2 = new PdfReader(contenidoPDF.getBytes("ISO-8859-1")); PdfStamper stamp2 = new PdfStamper(reader2, new FileOutputStream("c:/testFile.pdf")); waterMark(reader2, stamp2, image); reader2.close(); stamp2.close(); } catch (Exception e){...} String ret = ""; try{ if (baos.toString()!= null) ret = new String(baos.toString()); } catch (Exception e){...} return ret; /* this string will be sent to the browser output */ } And found that the file was watermarked with an image, but not the file on the browser (which appeared without the image). I saved the file that the browse-embedded Acrobat Reader showed (the one without the watermark), and then opened both (this one and the properly watermarked one) and found that the internal differences are that some characters show like "?" in the not properly watermarked file. For example, the set of characters "hijstuvwxyzƒ„…†‡ˆ‰Š'"" from the well watermarked file shows as "hijstuvwxyz??????????" inside the bad watermarked file. Then, I think it implies it has to be something related to - browser encoding (happens in both Explorer and Firefox), or - ByteArrayOutputStream treatment on the above method Do you agree? I feel the answer is very close... Thanks again, I appreciate very much your efforts in helping me. Adriano. 2007/11/16, Bruno Lowagie <[EMAIL PROTECTED]>: > Adriano Leite Ribero wrote: > > I have the String that I mentioned, with the known structure > > "%PDF-1.1....", I receive it in a servlet and I can properly print it > > out to the browser > > Let's add some extra (unnecessary) code to find out > where it goes wrong. Afterwards, we can remove that code. > > You can properly send the PDF to a browser. > OK, > then you can also properly write the PDF to a PDF document > on the server, read the PDF (FROM FILE!) from this location > and serve the PDF with the watermark. > > Try this. Note that this is for testing purposes only. > We're not going to do this in production (it's not very > efficient). > > If this works, we'll continue from there. > However, it would be more interesting if it doesn't work; > because then we might have found the root of the problem. > Why does it fail? Can you open the file you've written to > the server in Adobe Reader? If not, what's inside that file? > > Depending on the result, I'll be able to decide what would > be the next step; so keep us posted on the mailing list. > br, > Bruno > > ------------------------------------------------------------------------- > 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 > iText-questions@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/itext-questions > Buy the iText book: http://itext.ugent.be/itext-in-action/ > ------------------------------------------------------------------------- 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 iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/