Saving a word document in different formats?

We are using Aspose.Words to create and/or update word documents and save them, it works great, however we would like to be able to save as PDF as well. When we purchased the product we were under the impression this would work, if we get the Aspose.PDF license as well as the Aspose.Words product will the following be possible?

Document doc = new Document()
…
doc.save("word.doc");
doc.save("adobe.pdf");

Thanks

Hi

Thanks for your request. Currently Aspose.Words supports direct conversion to PDF (without using Aspose.Pdf). See the following link for more information:

So, you can try using direct method to convert your document to PDF. Here is the code:

Document doc = new Document("in.doc");
doc.SaveToPdf("out.pdf");

Best regards,

I Must be missing something as there appears to be no Document.saveToPdf() function. I have double checked the documentation and it does not show there is a saveToPdf method either.

I downloaded a fresh version of aspose words yesterday so I must have the right version, the jar is called “Aspose.Words.jdk16.jar”

Currently my code is working like this:

WordExport exporter = new WordExport();
Document document = exporter.export(policy);
response.setContentType(“application/msword”);
document.save(response.getOutputStream(), SaveFormat.DOC);

However this doesn’t work as there is no “SaveFormat.PDF”:

WordExport exporter = new WordExport();
Document document = exporter.export(policy);
response.setContentType(“application/pdf”);
document.save(response.getOutputStream(), SaveFormat.PDF);

So I have tried making a test class to try to get it to work, the following results in generating a doc, but not a pdf:

Document doc = new Document()
//… add some test stuff…
doc.save(“test.doc”);
doc.save(“test.pdf”);

When it gets to the pdf it says:

java.lang.UnsupportedOperationException: Unsupported SaveFormat: .pdf
at com.aspose.words.Document.save(Document.java:912)
at com.aspose.words.Document.save(Document.java:859)
at Test2.create(Test2.java:79)
at Test2.main(Test2.java:49)

Is there some trick to it we dont know about?

Hi

Thanks for your request. This feature is currently in beta, that is why it is not described in the documentation. However, it is described on in the download notes of the latest version:

Please make sure you are using the latest version. To check version of Aspose.Words for java, unzip Aspose.Words.jar, open META-INF\ MANIFEST.MF file in notepad, you will see the following:

Manifest-Version: 1.0
Specification-Title: Aspose.Words for Java
Implementation-Title: Aspose.Words for Java
Specification-Version: 4.0.0.0
Implementation-Version: 4.0.0.0
Specification-Vendor: Aspose Pty Ltd
Implementation-Vendor: Aspose Pty Ltd
Copyright: Copyright 2003-2009 Aspose Pty Ltd

Best regards,