Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Last active February 19, 2024 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conholdate-gists/99232eacdaa6d5399b0f7f9327e18e89 to your computer and use it in GitHub Desktop.
Save conholdate-gists/99232eacdaa6d5399b0f7f9327e18e89 to your computer and use it in GitHub Desktop.
Convert PDF to Word using Java

Learn how to Convert PDF to Word using Java

The following topics are covered here:

  1. Convert PDF to Word using Java
  2. Convert Specific Pages of PDF to Word using Java
  3. Load Pasword Protected PDF and Convert to Word using Java
// create converter
Converter converter = new Converter("C:\\Files\\sample.pdf");
// set Word convert options
WordProcessingConvertOptions options = new WordProcessingConvertOptions();
options.setPageNumber(1);
options.setPagesCount(1);
options.setFormat(WordProcessingFileType.Docx);
// convert
converter.convert("C:\\Files\\output.docx", options);
// PDF load options
PdfLoadOptions loadOptions = new PdfLoadOptions();
loadOptions.setPassword("password");
// create converter
Converter converter = new Converter("C:\\Files\\sample.pdf", loadOptions);
// define Word convert options
WordProcessingConvertOptions options = new WordProcessingConvertOptions();
// convert
converter.convert("C:\\Files\\output.docx", options);
// create converter
Converter converter = new Converter("C:\\Files\\sample.pdf");
// define Word convert options
WordProcessingConvertOptions options = new WordProcessingConvertOptions();
options.setPages(Arrays.asList(2, 3));
// convert
converter.convert("C:\\Files\\output.docx", options);
// create converter
Converter converter = new Converter("C:\\Files\\sample.pdf");
// set Word convert options
WordProcessingConvertOptions options = new WordProcessingConvertOptions();
options.setFormat(WordProcessingFileType.Docx);
// convert
converter.convert("C:\\Files\\output.docx", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment