Read only PDF with FOP. Is it possible?

Here should go questions about transforming XML with XSLT and FOP.
Luke
Posts: 4
Joined: Tue May 16, 2006 3:40 pm

Read only PDF with FOP. Is it possible?

Post 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
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post 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
Luke
Posts: 4
Joined: Tue May 16, 2006 3:40 pm

Post 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
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post 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
Luke
Posts: 4
Joined: Tue May 16, 2006 3:40 pm

Post 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
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post 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
Luke
Posts: 4
Joined: Tue May 16, 2006 3:40 pm

Post by Luke »

sorry, it was my mistake. this is the real error:

Algorithm RC4 not available
Post Reply