You need to take into account the mediabox and the cropbox to place the text, placing it always at the same height won't work.
Paulo ----- Original Message ----- From: "Sapien" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Thursday, April 10, 2008 6:02 PM Subject: [iText-questions] iText Watermark position issue > > Coders, > > Please forgive me in advance as my java kung foo is not that strong. I > have > a site which allows users to merge multiple pdf documents they choose via > a > checklist, and then it will apply a small watermark to the top left > (xposition 158, yposition 743). The problem is that there are some pdfs > in > which the watermark gets set in the middle of the page instead of the top > left. I believe I have read in some forums where it may be a size issue > of > sorts, but I'm still confused. I do know that I have found a weird work > around, which involves saving the pdf documents that don't work right, > then > rescanning via copy machine and having my copy machine send it back to me > via email. It will then apply the watermark to the upper left corner. I > will attach my code below (note: code is written in coldfusion and java): > > > <!--- BEGIN WATERMARK SCRIPT ---> > > <cfscript> > > paths = arrayNew(1); > > /* > This points to the jar we want to load. > Could also load a directory of .class files > */ > paths[1] = expandPath("iText.jar"); > > //create the loader > loader2 = createObject("component", "javaloader.JavaLoader").init(paths); > > function insertWatermarkPDF(pdfFileIn, imageFile, pdfFileOut, xPos, yPos, > zIndex) > { > // zindex refers to placing the image over or under the content, default > is > under > // but if your content has a background, it may obscure the watermark > if (NOT structKeyExists(arguments, "zIndex")) > arguments.zIndex = 0; > > //try > //{ > document = loader2.create("com.lowagie.text.Document"); > document.init(); > > pdfReader = loader2.create("com.lowagie.text.pdf.PdfReader"); > pdfReader.init(arguments.pdfFileIn); > > // page countING > n = pdfReader.getNumberOfPages(); > > // creae an outputstream > streamOut = loader2.create("java.io.FileOutputStream"); > streamOut.init(arguments.pdfFileOut); > > // give it to the pdfstamper > pdfStamper = loader2.create("com.lowagie.text.pdf.PdfStamper"); > pdfStamper.init(pdfReader, streamOut); > > // contentbyte is a static object, no constructor > under = loader2.create("com.lowagie.text.pdf.PdfContentByte"); > > // create the Image handler, static object, no constructor > Image = loader2.create("com.lowagie.text.Image"); > > // now create an instance with this file (report_watermark.jpg) > img = Image.getInstance(JavaCast("string", arguments.imageFile)); > img.setAbsolutePosition(arguments.xPos, arguments.yPos); > > for (ii = 1; ii LT n; ii = ii + 1) > { > // pdfStamper supports getUnderContent() and getOverContent() > if (arguments.zIndex) > under = pdfStamper.getOverContent(JavaCast("int", ii)); > else > under = pdfStamper.getUnderContent(JavaCast("int", ii)); > > under.addImage(img); > } > > pdfStamper.close(); > > return true; > //} > //catch (any e) > //{ > // return false; > //} > } > > </cfscript> > > <cfoutput>#insertWatermarkPDF("<PATH REMOVED>\concatenation.pdf" > ,"<PATH REMOVED>\n#form.tail#up.gif" > ,"<PATH REMOVED>\concatenation2.pdf" > ,158 > ,743 > ,1)# > </cfoutput> > > I hope this isn't confusing. Thanks in advance for everyone's assistance. ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Do you like iText? Buy the iText book: http://www.1t3xt.com/docs/book.php Or leave a tip: https://tipit.to/itexttipjar
