Convert PDF to Word in Java

The article demonstrates how to convert PDF documents to Word (.doc and .docx) documents using Spire.PDF for Java with a few lines of code.

The sample PDF file looks like the one below.

Convert PDF to Word in Java

Entire Code

import com.spire.pdf.*;

public class PdfToDoc {

    public static void main(String[] args) {

        //create a PdfDocument object
        PdfDocument doc = new PdfDocument();

        //load a sample PDF file
        doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\Introduction of Spire.PDF for Java.pdf");

        //save as .doc file
        doc.saveToFile("output/ToDoc.doc",FileFormat.DOC);

        //save as. docx file
        doc.saveToFile("output/ToDocx.docx",FileFormat.DOCX);
        doc.close();
    }
}

Output

Convert PDF to Word in Java