Closed
Solved
PDF geneartion in PEGA
Can we generate password protected pdf's in PEGA?
This content is closed to future replies and is no longer being maintained or updated.
Links may no longer function. If you have a similar request, please write a new post.
Can we generate password protected pdf's in PEGA?
Accepted Solution
Hi Vandana,
I checked the OOTB 'HTMLTOPDF' and I don't believe it currently allows for the 'setPermissions()' call which is available in PD4ML at this point: I will log an ENH request for this : so our Product Management Teams will be able to review this request whether it would be a viable and desirable thing to include in a future release of PRPC.
[ EDIT - I have logged the FEEDBACK/ENHANCEMENT for this FDBK-12511:"Request for 'Password-Protected' PDFs option in HTMLTOPDF." ]
You could probably create a custom ACTIVITY which initializes the 'PD4ML' engine yourself, and add in the required call to do this: the downside of this approach is that you lose all the other handling (of CSS/IMAGES etc) that HTMLTOPDF (or indeed the Public API call 'PDFUtils') does for you.
Hi Vandana,
I checked the OOTB 'HTMLTOPDF' and I don't believe it currently allows for the 'setPermissions()' call which is available in PD4ML at this point: I will log an ENH request for this : so our Product Management Teams will be able to review this request whether it would be a viable and desirable thing to include in a future release of PRPC.
[ EDIT - I have logged the FEEDBACK/ENHANCEMENT for this FDBK-12511:"Request for 'Password-Protected' PDFs option in HTMLTOPDF." ]
You could probably create a custom ACTIVITY which initializes the 'PD4ML' engine yourself, and add in the required call to do this: the downside of this approach is that you lose all the other handling (of CSS/IMAGES etc) that HTMLTOPDF (or indeed the Public API call 'PDFUtils') does for you.
So instead of doing that: you can 'post-process' the PDF making use of the 'PDFBox' library - which also ships with OOTB PRPC. See this previous POST (regarding getting Page Counts from a PDF) for more information on this.
In the meantime, I have thrown together an ACTIVITY which does just this - here's the code: (I happened to do this on 7.1.7 - it should still work on 7.1.8 (and lower versions as well: just check your system [see the post linked above] for what version of 'PDFBOX' you have)).
And here's the JavaStep that does the conversion - note how we have already transferred some PARAM objects to 'mirrored' LOCAL variables here (just make the Javacode more readable IMHO).
com.pega.apache.pdfbox.pdmodel.PDDocument doc=null; com.pega.apache.pdfbox.pdmodel.encryption.AccessPermission ap=null; com.pega.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy spp=null; //Get the byte array of original PDF (transferred from Param->Local Variable in previous step). byte[] byteArray=(byte[]) PDFDocument; java.io.ByteArrayInputStream bis=null; bis = new java.io.ByteArrayInputStream(byteArray); try { doc=com.pega.apache.pdfbox.pdmodel.PDDocument .load( bis ); ap=new com.pega.apache.pdfbox.pdmodel.encryption.AccessPermission(); ap.setReadOnly(); spp=new com.pega.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy( UserName, Password, ap); doc.protect(spp); java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream(); doc.save(out); PDFDocument=out.toByteArray(); // Replace old byte array with newly generated one. } catch(Exception e) { throw new PRRuntimeException(e); } finally { if (bis!=null) { try { bis.close(); } catch(Exception e) { throw new PRRuntimeException(e); } } if(doc!=null) { try { doc.close(); } catch(Exception e) { throw new PRRuntimeException(e); } } }
By the way: I'm not very happy about my try/catch/finally logic there, looks to be overcomplicated - so I won't be offended if anybody wants to tidy up this !!!
NOTES:
1. PRPC ships with a 're-badged' PDFBOX here - so that the package name is not 'org.apache[...]', but 'com.pega.apache[...]'.
2. We are using the OOTB 'VIEW' activity here to actually display the PDF: (I missed this off on the first screenshot, to concentrate on the PROPERTY-SETs).
3. We are using the 'Pass current parameter page' for both HTMLTOPDF and VIEW - which makes it easier (IMHO) to 'chain-up' steps here.
4. The PDFBOX library wants both a username (I used 'gcs' in my test) and a password (I used 'topsecret' in my test) - but when I open the PDF (with 'Foxit' as it happens) - only the password was asked for.
I'll attach the result here for reference.
Cheers
John
One other thing: I *think* this is a problem with my Foxit installation - I (most of the time, but not always?) get this error when I enter the password - the PDF shows ok:
----
[FoxItCloud]
( X ) Encountered an improper argument
----
Does anybody else get the same error when opening in Foxit (or indeed Adobe Acrobat?)
[ EDIT: pretty sure the error is Foxit-specific - just opened up the same PDF on a different machine using Adobe Acrobat - no errors for me. ]
Thanq very much John:-)
I'll try implementing your inputs on this..
Its Workinggg!!! Thanks John!
Great ! Cheers !
Question
Question Solved
Question
Question Solved
Question
Question
Question Solved
Question
Question
Question
Pega Collaboration Center has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.