Page 1 of 1

Read only PDF with FOP. Is it possible?

Posted: Tue May 16, 2006 3:42 pm
by Luke
Hi.
I use fop to create a pdf from xml with java.
But I would like to create a read only pdf, without the possibility to copy text by the user. Is it possible with fop? If not, what can I use?

thanks

Posted: Tue May 16, 2006 4:22 pm
by sorin_ristache
Hello,

Yes it is possible. The Apache website documents the PDF encryption features of FOP when it is called from Java.

Regards,
Sorin

Posted: Tue May 16, 2006 4:56 pm
by Luke
Thank you very much

This is my code:

ByteArrayOutputStream BAout = new ByteArrayOutputStream();
org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver();

driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
driver.setOutputStream(BAout);

driver.render(input.getParser(), input.getInputSource());

File outputFile = new File(filenamePDF);
FileOutputStream outFileWriter = new FileOutputStream(filenamePDF);

byte[] content = BAout.toByteArray();

outFileWriter.write(content);
outFileWriter.flush();
outFileWriter.close();

How can I integrate with the code of the page you redirect me?

thanks

Posted: Tue May 16, 2006 5:01 pm
by sorin_ristache
Hello,

You have to obtain a reference to a FOUserAgent object and call getRendererOptions().put("encryption-params", new PDFEncryptionParams( ... )) on that reference.

Regards,
Sorin

Posted: Tue May 16, 2006 5:25 pm
by Luke
I use this:

ByteArrayOutputStream BAout = new ByteArrayOutputStream();
org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver();

java.util.HashMap rendererOptions = new java.util.HashMap();
rendererOptions.put("ownerPassword", "mypassword");
rendererOptions.put("allowCopyContent", "FALSE");
rendererOptions.put("allowEditContent", "FALSE");
rendererOptions.put("allowPrint", "FALSE");
driver.getRenderer().setOptions(rendererOptions);

driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
driver.setOutputStream(BAout);

driver.render(input.getParser(), input.getInputSource());

File outputFile = new File(filenamePDF);

FileOutputStream outFileWriter = new FileOutputStream(filenamePDF);

byte[] content = BAout.toByteArray();

outFileWriter.write(content);
outFileWriter.flush();
outFileWriter.close();


but I get a Nullpointerexception

Posted: Tue May 16, 2006 5:31 pm
by sorin_ristache
Hello,

I think you can get more help about FOP problems that are not related with <oXygen/> on the FOP mailing list.

Regards,
Sorin

Posted: Tue May 16, 2006 5:35 pm
by Luke
sorry, it was my mistake. this is the real error:

Algorithm RC4 not available