package net.ensode.pdfunlock; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.DocumentException; import com.lowagie.text.pdf.PdfEncryptor; import com.lowagie.text.pdf.PdfReader; import com.lowagie.text.pdf.PdfWriter; public class PdfUnlock { public static void main(String[] args) { if (args.length < 2) { System.err .println("usage: java net.ensode.pdfunlock.PdfUnlock inputfile.pdf outputfile.pdf"); } else { new PdfUnlock().unlockPdf(args[0], args[1]); } } private void unlockPdf(String inputFile, String outputFile) { try { PdfReader reader = new PdfReader(inputFile); PdfEncryptor.encrypt(reader, new FileOutputStream(outputFile), null, null, PdfWriter.AllowAssembly | PdfWriter.AllowCopy | PdfWriter.AllowDegradedPrinting | PdfWriter.AllowFillIn | PdfWriter.AllowModifyAnnotations | PdfWriter.AllowModifyContents | PdfWriter.AllowPrinting | PdfWriter.AllowScreenReaders, false); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } }