This discussion is archived
5 Replies Latest reply: Mar 14, 2012 2:14 AM by EJP RSS

Providing security to the PDF file using apache FOP in java

907238 Newbie
Currently Being Moderated
I am working on PDF file generation using Apache FOP, I have security concerns which are
1. PDF file will be placed in a folder after generation and that should not be copied to other locations.
2. PDF file should only have an option print nothing else. The save/save as options should never be enabled.
3. PDF expiry date is required, so that PDF file will get expire after duration.
  • 1. Re: Providing security to the PDF file using apache FOP in java
    EJP Guru
    Currently Being Moderated
    1. PDF file will be placed in a folder after generation and that should not be copied to other locations.
    You can't control that from Java. You probably can't control it at all.
    2. PDF file should only have an option print nothing else. The save/save as options should never be enabled.
    That should be in the security API if supported.
    3. PDF expiry date is required, so that PDF file will get expire after duration.
    Ditto.
  • 2. Re: Providing security to the PDF file using apache FOP in java
    907238 Newbie
    Currently Being Moderated
    I have searched the apache FOP API, but I didn't find the relevant information.
    Could you suggest me any other API, which will fullfill my concern.
  • 3. Re: Providing security to the PDF file using apache FOP in java
    EJP Guru
    Currently Being Moderated
    <a href="http://www.lowagie.com/iText>iText</a>. I found that in 30 seconds with Google. You could have done that too, without the forum wait.                                                                                                                                                                                                                                                                                           
  • 4. Re: Providing security to the PDF file using apache FOP in java
    907238 Newbie
    Currently Being Moderated
    HI,

    I did that too, with too much experiments.

    Code snippet for reference.

    PdfReader reader = new PdfReader(getOutputFilePath());
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("my-new-file.pdf"));
    stamper.setDuration(1,1);
    int permissions = PdfWriter.HideMenubar & PdfWriter.HideToolbar & PdfWriter.HideWindowUI & ~( PdfWriter.AllowCopy | PdfWriter.AllowModifyAnnotations | PdfWriter.AllowFillIn | PdfWriter.AllowAssembly | PdfWriter.AllowModifyContents | PdfWriter.AllowScreenReaders);
    stamper.setEncryption(null, null,
    permissions, PdfWriter.STRENGTH40BITS);
    stamper.setFormFlattening(true);

    System.out.println(stamper.getMoreInfo());
    stamper.close();


    I am able to disable the save button, but I am unable to disable the save as option.
    It would be great help, if you can give some inputs on this.
  • 5. Re: Providing security to the PDF file using apache FOP in java
    EJP Guru
    Currently Being Moderated
    I can't. I don't know any more about it than you do. All I have is possibly a greater aptitude at reading API documents and using Google. You could develop both.