pdf to word java code example

Example 1: convert pdf to word in java

XWPFDocument doc = new XWPFDocument();String pdf = filename;PdfReader reader = new PdfReader(pdf);PdfReaderContentParser parser = new PdfReaderContentParser(reader);

Example 2: convert pdf to word in java

for (int i = 1; i <= reader.getNumberOfPages(); i++) {    TextExtractionStrategy strategy =      parser.processContent(i, new SimpleTextExtractionStrategy());    String text = strategy.getResultantText();    XWPFParagraph p = doc.createParagraph();    XWPFRun run = p.createRun();    run.setText(text);    run.addBreak(BreakType.PAGE);}FileOutputStream out = new FileOutputStream("src/output/pdf.docx");doc.write(out);// Close all open files

Tags:

Java Example