Saving Html File as Word Pdf ByteArray Incomplete Output

Hello,

The issue is that when saving to the byte array, I only get the first few parts of the file, rather than the entire output.

Here is the code I am using for the byte array:

ByteArrayOutputStream os = new ByteArrayOutputStream();
InputStream is = new ByteArrayInputStream("Hello World".getBytes("UTF-8"));
com.aspose.words.Document doc = new com.aspose.words.Document(is);
SaveOutputParameters params = doc.save(os, com.aspose.words.SaveFormat.PDF);
return os.toByteArray();

Here is the code for the file:

InputStream is = new ByteArrayInputStream("Hello World".getBytes("UTF-8"));
com.aspose.words.Document doc = new com.aspose.words.Document(is);
SaveOutputParameters params = doc.save("somedirectory\file.pdf");

Attached are the two different outputs; byteArray is the file from the byte array code and file is the output from the file output.

Thanks!

Hi Vinny,

Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for Java 16.2.0 and have not found the shared issue. We have used following code example to test this scenario. Please use Aspose.Words for Java 16.2.0 and let us know if you have any more queries.

ByteArrayOutputStream os = new ByteArrayOutputStream();
InputStream is = new ByteArrayInputStream("Hello World".getBytes("UTF-8"));
com.aspose.words.Document doc = new com.aspose.words.Document(is);
doc.save(os, com.aspose.words.SaveFormat.PDF);
FileOutputStream fos = new FileOutputStream(MyDir + "output.pdf");
fos.write(os.toByteArray());
fos.close();

My apologies. I was having a different error and thought I was reproducing it with that example. Turns out it was just an issue with how my clipboard was behaving.

I have attached a zip file with the html that I used and the resultant pdfs for saving it directly to a file and saving it to a byte array. You can see only the file save has any content. I am currently on 16.2.0.

Thanks for the help!

Hi Vinny,

Thanks for sharing the detail. We have tested the scenario using same code example and have not found the shared issue. Please check the attached output Pdf. Perhaps, you are not saving the byte array to file at disk correctly. Please use the code example shared in my previous post. Hope this helps you.

I figured out the initial issue; this was due to an encoding issue on our webserver. Thanks for the help.

Hi Vinny,

Thanks for your feedback. It is nice to hear from you that you have solved your issue. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.