Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 06:12
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 aspose-com-gists/1e9e2f83bba549ef6e134c5cfd4c12c4 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/1e9e2f83bba549ef6e134c5cfd4c12c4 to your computer and use it in GitHub Desktop.
Convert or Export MS Publisher PUB File to Word Document DOC or DOCX Programmatically in Java
// Specify path for input Publisher file
String fileName = "Sample.pub";
// Initialize ByteArrayOutputStream to hold intermediary PDF file.
final ByteArrayOutputStream os = new ByteArrayOutputStream();
// Initialize Pub Parser for the PUB file
IPubParser parser = PubFactory.createParser(fileName);
// Parse the Publisher file
com.aspose.pub.Document doc = parser.parse();
// Convert PUB to PDF file and save output into the stream
PubFactory.createPdfConverter().convertToPdf(doc, os);
// Load the intermediary PDF document
Document pdfDocument = new Document(os.toByteArray());
// Convert or Export the file to MS Word DOCX or DOC format
pdfDocument.save("PUBToDOCX.docx", SaveFormat.DocX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment