You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by tr...@kaz.com.au on 2002/05/27 00:58:25 UTC

Re: Question about watermarking in FOP.

I'm afraid I don't know the answer to that one but I have forwarded your
enquiry to the fop-user mailing list.  You should join in, perhaps.

Trev



                                                                                                         
                    "Todeush,                                                                            
                    Serhiy"              To:     "'Trevor_Campbell@kaz.com.au'"                          
                    <Serhiy.Todeus        <Tr...@kaz.com.au>                                   
                    h@AIG.COM>           cc:                                                             
                                         Subject:     Question about watermarking in FOP.                
                    25/05/2002                                                                           
                    02:55 AM                                                                             
                                                                                                         
                                                                                                         




Hello, Trevor!

My name is Serhiy Todeush. I am using FOP 0.20.3 to generate PDFs.
Couple of days ago I run into problem with watermark in my documents
because
current version of FOP does not support BACKGROUND-IMAGE.

I saw you answer on the FOP-user forum about using an image in REGION-BEFOR
as a substitution for watermark.
I tried this technique and it worked. But I still have a problem, because
the image appears on the top of text in the main body, i.e. I cannot see
text behind the image.
(I use GIF file with transparent background as the image).

Dou you know by any chance how to resolve the issue? Is there any way to
bring main body text to foreground?
May be you have some working example which you can share with me?


I really appreciate your attention to my request.

Thank you in advance,
Serhiy






Re: Question about watermarking in FOP.

Posted by "J.Pietschmann" <j3...@yahoo.de>.
trevor_campbell@kaz.com.au forwarded:
> I saw you answer on the FOP-user forum about using an image in REGION-BEFOR
> as a substitution for watermark.
> I tried this technique and it worked. But I still have a problem, because
> the image appears on the top of text in the main body, i.e. I cannot see
> text behind the image.

It seems the recommended technique for generating
watermarks is still postprocessing with iText, unless
background image is fully working.
  http://www.lowagie.com/iText/

Here is a demonstration how to achive this. The iText
code is manly lifted directly from the iText tutorial.
Pass the name of the .fo file as parameter 1, the target
file name as parameter 2 and the x and y offset for the
watermark as parameters 3 and 4 respectively.

import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

class rendtest1 {
   public static void main(String args[]) {
     try {
       ByteArrayOutputStream fopout=new ByteArrayOutputStream();
       FileOutputStream outfile=new FileOutputStream(args[1]);
       Driver driver =new Driver(new org.xml.sax.InputSource(args[0]),fopout);
       driver.setRenderer(Driver.RENDER_PDF);
       driver.run();
       PdfReader reader = new PdfReader(fopout.toByteArray());
       int n = reader.getNumberOfPages();
       Document document = new Document(reader.getPageSizeWithRotation(1));
       PdfWriter writer = PdfWriter.getInstance(document, outfile);
       Watermark watermark = new Watermark(Image.getInstance("g.jpg"),
          Integer.parseInt(args[2]),Integer.parseInt(args[3]));
       document.add(watermark);
       document.open();
       PdfContentByte cb = writer.getDirectContent();
       PdfImportedPage page;
       int rotation;
       int i = 0;
       while (i < n) {
         i++;
         document.setPageSize(reader.getPageSizeWithRotation(i));
         document.newPage();
         page = writer.getImportedPage(reader, i);
         rotation = reader.getPageRotation(i);
         if (rotation == 90 || rotation == 270) {
           cb.addTemplate(page, 0, -1f, 1f, 0, 0, reader.getPageSizeWithRotation(i).height());
         }
         else {
           cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
         }
         System.out.println("Processed page " + i);
       }
       document.close();
     }
     catch( Exception e) {
       e.printStackTrace();
     }
   }
}

J.Pietschmann