Sunday, 15 January 2012

How to set interactive PDF form in read-only mode while writing as new PDF by using Apache PDFBox? -



How to set interactive PDF form in read-only mode while writing as new PDF by using Apache PDFBox? -

i using apache pdfbox library fill info in fillable pdf form(acrofrom). after finish info filling, needs write new pdf file (in non-editable format).

i tried setreadonly() method, available in accesspermission class. still can able edit values in new created pdf document.

code:

private static pddocument _pdfdocument; public static void main(string[] args) { string originalpdf = "c:/sample/original.pdf"; string targetpdf = "c:/sample/target.pdf"; seek { populateandcopy(originalpdf, targetpdf); ----------- ----------- ----------- ----------- } } // main method complted private static void populateandcopy(string originalpdf, string targetpdf) throws ioexception, cosvisitorexception { _pdfdocument = pddocument.load(originalpdf); _pdfdocument.getnumberofpages(); _pdfdocument.getcurrentaccesspermission().setcanmodify(false); _pdfdocument.getcurrentaccesspermission().setreadonly(); system.out.println(_pdfdocument.getcurrentaccesspermission().isreadonly()); _pdfdocument.save(targetpdf); _pdfdocument.close(); }

please help me prepare issue.

your code not set encryption, problem.

try this:

accesspermission ap = new accesspermission(); ap.setcanmodify(false); ap.setreadonly(); standardprotectionpolicy spp = new standardprotectionpolicy("owner-password", "", ap); spp.setencryptionkeylength(128); doc.protect(spp); doc.save(targetpdf); doc.close();

i've set 128 keylength 256 not supported in 1.8 , 40 short.

a user able open document without password (see empty password parameter), he'll have restricted rights.

pdfbox

No comments:

Post a Comment