0

I'm using pdfbox 1.8.11 and FOP to add water mark to pdf:s. It works nicely to most input pdf files. However I get a problem when the file is in landscape, the watermarking will be 90 degree right rotated. I had similar problem with visible signature, it is fixed. thanks to the solution in sign landscape file . Any idea how to make water mark rotation works? Thanks in advance!

The original picture for watermark is: Up arrow

After FOP watermark the image is rotated: image rotated

Community
  • 1
  • 1
ryuukei
  • 23
  • 8
  • Answered here: https://issues.apache.org/jira/browse/PDFBOX-3434 – Tilman Hausherr Jul 21 '16 at 17:51
  • Finally get it works, the solution is to add a orientation configuration in xsl:fo in page settings. e.g. ` – ryuukei Jul 25 '16 at 11:07
  • I didn't realize that this was more a FOP question. Anyway, I suggest you answer the question yourself, so that it will help other people. – Tilman Hausherr Jul 25 '16 at 11:10
  • I didn't realize it either. Anyway, thanks for your suggestions! I will come back for a readable answer later on. :-) – ryuukei Jul 25 '16 at 11:18
  • @TilmanHausherr are you interested another question? http://stackoverflow.com/questions/40217187/how-to-add-vri-dictonary-into-a-pdf – ryuukei Oct 24 '16 at 13:50
  • sorry I can't help there, although I have fixed some smaller signature issues in the past. But yours is a bigger one. – Tilman Hausherr Oct 24 '16 at 15:45
  • @TilmanHausherr thank you for answering question! :-) do you mean it is an unsolved feature in pdfbox? Now i'm still struggling to try to add DSS and VRI data after the pdf signed. Not sure whether it makes sense. If it is possible would you like to discuss a bit more with me? I'm really interested in pdf-sign related things. If I can solve this problem, i might could have it as my master thesis. – ryuukei Oct 24 '16 at 19:50
  • It would be better to discuss this in the PDFBox user mailing list... obviously, if something can become your master thesis, it is too big for stackoverflow :-) Yes, it "is an unsolved feature in pdfbox", i.e. PADES & co are not available there "out of the box". I believe that it has been implemented on top of PDFBox, see here: https://github.com/esig/dss – Tilman Hausherr Oct 24 '16 at 21:21
  • @TilmanHausherr thanks! i checked their code out also. Grabbing knowledge from any possibility. I believe there definitely some work round solution for it. – ryuukei Oct 25 '16 at 08:56

1 Answers1

0

apologize for answer late. The idea for 'water mark' here to add add some transforms into the original pdf using fop apache fop. You can fine java code example and fo template example from apache fop website.

In any case i will illustrate the example here too: 1. the java code of how to use fop

import org.apache.fop.apps.*;
import org.xml.sax.*;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.sax.*;
import javax.xml.transform.stream.*;

class rendtest {

    private static FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
    private static TransformerFactory tFactory = TransformerFactory.newInstance();

    public static void main(String args[]) {
        OutputStream out;
        try {
            //Load the stylesheet
            Templates templates = tFactory.newTemplates(
                new StreamSource(new File(args[1])));

            //First run (to /dev/null)
            out = new org.apache.commons.io.output.NullOutputStream();
            FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
            Transformer transformer = templates.newTransformer();
            transformer.setParameter("page-count", "#");
            transformer.transform(new StreamSource(new File(args[0])),
                new SAXResult(fop.getDefaultHandler()));

            //Get total page count
            String pageCount = Integer.toString(driver.getResults().getPageCount());

            //Second run (the real thing)
            out = new java.io.FileOutputStream(args[2]);
            out = new java.io.BufferedOutputStream(out);
            try {
              foUserAgent = fopFactory.newFOUserAgent();
              fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
              transformer = templates.newTransformer();
              transformer.setParameter("page-count", pageCount);
              transformer.transform(new StreamSource(new File(args[0])),
                  new SAXResult(fop.getDefaultHandler()));
            } finally {
                out.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
  1. for the problem i had for rendering landscape pdf:s, in fop template you only need to add one more attribute to tell this file is in landscape layout. The attribute is to set reference-orientation="90". Then your other definitions in the fop template will be applied properly.
ryuukei
  • 23
  • 8