[EMAIL PROTECTED] 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



Reply via email to