We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF to word from byte[]

Hi,



I have program which generate byte array of PDF file. I like to take the byte object in PDF and convert it into MSFT word. Can you advice if this can be complete? Do you have sample which you can share?



In other word, I want to convert byte[] object to Aspose.pdf object.





2nd. I like to save the output as binary stream back to browser. Will the following method supported? pdfDocument.save(response.getOutputStream(), com.aspose.pdf.SaveFormat.Doc);



3rd question, does the converted file format have any limitation. IE does images\charts embedded within PDF also gets converted into word?





Attached is the sample pdf file that I want to convert into word.



Thanks!

jeremyyma:
I have program which generate byte array of PDF file. I like to take the byte object in PDF and convert it into MSFT word. Can you advice if this can be complete? Do you have sample which you can share?
In other word, I want to convert byte[] object to Aspose.pdf object.

Hi Jeremy,

Thanks for contacting support.

You can load PDF file from FileInputStream object. Please take a look over following code snippet.

[Java]
//source
PDF file 
java.io.File
file = new
java.io.File(“c:/pdftest/untitled+(9).pdf”);
java.io.FileInputStream
fis = new
java.io.FileInputStream(file);
//System.out.println(file.exists()
“!!”);
//InputStream
in = resource.openStream();
java.io.ByteArrayOutputStream
bos = new
java.io.ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum); //no doubt here is 0
//Writes
len bytes from the specified byte array starting at offset off to this byte
array output stream.
System.out.println(“read " + readNum + "
bytes,”);
}
} catch (java.io.IOException ex) {
}
byte[] bytes = bos.toByteArray();
//instantiate
Document Object with ByteArrayInputStream while passing byte array as argument
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(new java.io.ByteArrayInputStream(bytes));

jeremyyma:
2nd. I like to save the output as binary stream back to browser. Will the following method supported? pdfDocument.save(response.getOutputStream(), com.aspose.pdf.SaveFormat.Doc);
You can save the output in ByteArrayOutputStream object. Please take a look over following code lines.

[Java]
//instantiate Document Object with ByteArrayInputStream while passing byte array as argument
com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(new java.io.ByteArrayInputStream(bytes));
java.io.InputStream is = null;
java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
try{
pdfDocument.save(os,com.aspose.pdf.SaveFormat.Doc);
System.out.println(os.size());
is = new java.io.ByteArrayInputStream(os.toByteArray());
os.close();
os.flush();
pdfDocument.close();
}catch (Throwable e) {}

jeremyyma:
3rd question, does the converted file format have any limitation. IE does images\charts embedded within PDF also gets converted into word?
Attached is the sample pdf file that I want to convert into word.

The resultant Word file should contain all the images/resources inside it. In case you encounter any issue, please feel free to contact.