java - encryption exception with PDFBox while the file is readable -
i using pdfbox extracting text pdf file in java. works fine in of cases have problem pdf files follows:
exception in thread "main" java.io.ioexception: javax.crypto.illegalblocksizeexception: input length must multiple of 16 when decrypting padded cipher
the files have following properties
is there way can open type of files extract contents?
i guess getting error because try extract texts page page. , page extraction here not allowed! but, picture suggests content copying allowed. also, can open file , see content! then, there should way opening , getting content of these files. right?
this link example of pdf file have problem.
the exception occured @ following line if objnr = 9
securityhandler.decryptstream(stream, objnr, objgennr);
then, if set program proceed line if objnr != 9
works fine! know why happens? have pdf file work when objnr != 10
. idea?
the code have (tested latest version of pdfbox try , see if problem because of version use) follows
import java.io.ioexception; public class test { public static void main(string[] args) throws ioexception { pdfmanager pdfmanager = new pdfmanager(); pdfmanager.setfilepath("pathtothepdffile"); system.out.println(pdfmanager.totext()); } } import org.apache.pdfbox.pdfparser.pdfparser; import org.apache.pdfbox.pdmodel.pddocument; import org.apache.pdfbox.util.pdftextstripper; import org.apache.pdfbox.cos.cosdocument; import java.io.file; import java.io.fileinputstream; import java.io.ioexception; public class pdfmanager { private pdfparser parser; private pdftextstripper pdfstripper; private pddocument pddoc ; private cosdocument cosdoc ; private string text ; private string filepath; private file file; public pdfmanager() { } public string totext() throws ioexception { this.pdfstripper = null; this.pddoc = null; this.cosdoc = null; file = new file(filepath); parser = new pdfparser(new fileinputstream(file)); parser.parse(); cosdoc = parser.getdocument(); pdfstripper = new pdftextstripper(); pddoc = new pddocument(cosdoc); pddoc.getnumberofpages(); pdfstripper.setstartpage(1); pdfstripper.setendpage(10); text = pdfstripper.gettext(pddoc); return text; } public void setfilepath(string filepath) { this.filepath = filepath; } }
Comments
Post a Comment