Convert PDF to Word without losing the styles

1

I wanted a code to convert a pdf document into word without losing the styles.

I have this class that converts to word plus it does not maintain document styles.

public class teste {
public static void main(String[] args) throws IOException {
     System.out.println("Document converted started");
    XWPFDocument doc = new XWPFDocument();
    String pdf = "C:\Users\eder\Downloads\teste1111.pdf";
    PdfReader reader = new PdfReader(pdf);
    PdfReaderContentParser parser = new PdfReaderContentParser(reader);
    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("C:\Users\eder\Downloads\testandoWord.docx");
    doc.write(out);
    out.close();
    reader.close();
    System.out.println("Document converted successfully");
}

I'm using iText and POI. I've looked at the documentation but I do not find anything in the style I need. Example of pdf:

Does anyone know how to do this?

    
asked by anonymous 05.06.2018 / 13:40

0 answers