Aspose Word. Java : get the document without saving

Hi,

I am first time using Aspose word Java API in our project. I have below requirement. After retrieving document template and execute mail merge, my data will be filled up in the template document. Since we want to convert Document into PDF, we were using PDFSaveOption class. But as per requirement we dont want to store this pdf document to any physical location, instead it should be converted into PDF and should be in memory and we retrieve it as Blob and send it to client.

is that possible?

Please advice.

Thanks
unmarshall

Hi
Thanks for your request. Sure you can achieve this. Please see the following code:

// Open input document (you can also open document from InputStream).
Document doc = new Document("C:\\Temp\\in.doc");
// Save document as PDF ito output stream and get byte array.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.PDF);
byte[] pdfBytes = baos.toByteArray();
baos.flush();
baos.close();

Best regards,

with above code i am getting below exception

java.lang.NullPointerException: stream
at com.aspose.words.Document.a(Document.java: 1701)
at com.aspose.words.Document.a(Document.java: 1445)
at com.aspose.words.Document.save(Document.java: 959)
at BlobTest.main(BlobTest.java: 17)

Here is my code:

public static void main(String[] args)
{

    try
    {
        Document doc = new Document("C:\Test\Deployment.doc");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        doc.save(baos, SaveFormat.PDF);
        byte[] pefBytes = baos.toByteArray();
        System.out.println(pefBytes);

        baos.flush();
        baos.close();

    }
    catch (Exception e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    finally
    {}

}
}

Hi
Thanks for your request. Which version of Aspose.Words do you use? Have you tried with latest version? You can download it from here:
https://releases.aspose.com/words/java
If the problem still occurs, please attach your input document here for testing.
Best regards,

I am using Aspose.Words.jdk15.jar.

i can not see attachment option here. Word document is very simple. it has “abc” text in it.

we are using Specification-Version: 4.0.2.0
Implementation-Version: 4.0.2.0
Specification-Vendor: Aspose Pty Ltd

Hello
Thanks for your request. Please try using more recent version of Aspose.Words (10.2.0) and let me know how it goes on your side.
You can download the latest version from here:
https://releases.aspose.com/words/java
Best regards,