Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active December 23, 2021 05:48
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/75b9f1628cfdabc6c1dd1b0a2137fc82 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/75b9f1628cfdabc6c1dd1b0a2137fc82 to your computer and use it in GitHub Desktop.
Convert PS or EPS to Word DOCX or DOC Document Programmatically in Java
// Declare ByteArrayOutputStream to save intermediary PDF document.
final ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
// Instantiate EPS or PS PostScript using FileInputSream
FileInputStream psStream = new FileInputStream("input.ps");
// Initialize PsDocument class object.
PsDocument document = new PsDocument(psStream);
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
// Initialize PdfSaveOptions object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
options.setJpegQualityLevel(70);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
//options.setAdditionalFontsFolders(new String [] {"FONTS_FOLDER"});
// If you need to specify page size then use following line
PdfDevice device = new PdfDevice(pdfStream, new Dimension(595, 842));
// Convert EPS or PS Postscript file to PDF
document.save(device , options);
// Load the intermediary PDF file
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(pdfStream.toByteArray());
// Instantiate an object of DocSaveOptions
com.aspose.pdf.DocSaveOptions saveOptions = new com.aspose.pdf.DocSaveOptions();
// Set output document format as DOCX or DOC
saveOptions.setFormat(com.aspose.pdf.DocSaveOptions.DocFormat.DocX);
// Convert the EPS or PS file to a Word DOCX or DOC file
doc.save("output.docx", saveOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment