Load/Open PDF document from Byte Stream in Java | Aspose.PDF for Java

Hi Support,


we are evaluating the Apsose Java PDF library. Unfortunately I am not able to find a constructor to open the pdf file from a byte stream.

All I see in your documentation is following for opening a word document:

 new com.aspose.pdf.Document(“input.pdf”);

But how open a document from a byte stream, like “byte[] docAsBytes” ??

We are using an enterprise content management system where it is not possible to access the files through a path!

May you help? 

I used before Aspose Word and there it is possible without any problems doing that!! There was a constructor for byte[].

Also I have a further question: Is there a way to see all the content of the pdf document like in word, like the “Object Document Model” Application? With this it was possible to inspect the content of word documents. I know that in the newer version (we use the newest version of the aspose pdf library - download today, march 23th 2015).  

Thanks for your help,
Amin

aminzamani:

we are evaluating the Apsose Java PDF library. Unfortunately I am not able to find a constructor to open the pdf file from a byte stream.

All I see in your documentation is following for opening a word document:

 new com.aspose.pdf.Document(“input.pdf”);

But how open a document from a byte stream, like “byte[] docAsBytes” ??

We are using an enterprise content management system where it is not possible to access the files through a path!
Hi Amin,

Thanks for contacting support.

I am afraid com.aspose.pdf.Document class does not have a constructor which accepts byte array as an argument. However you may consider instantiating InputStream object with ByteArray contents and then initialize Document instance with InputStream contents as argument. Please take a look over following code snippet.

[Java]

// get reference of source/input file<o:p></o:p>

java.nio.file.Path path = java.nio.file.Paths.get(“input.pdf”);<o:p></o:p>

// read all the contents from source file into ByteArray<o:p></o:p>

byte[] data = java.nio.file.Files.readAllBytes(path);<o:p></o:p>

// create an instance of Stream object from ByteArray contents<o:p></o:p>

InputStream is = new ByteArrayInputStream(data);<o:p></o:p>


//Instantiate Document object from stream instance

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(is);


aminzamani:
I used before Aspose Word and there it is possible without any problems doing that!! There was a constructor for byte[].

Also I have a further question: Is there a way to see all the content of the pdf document like in word, like the “Object Document Model” Application? With this it was possible to inspect the content of word documents. I know that in the newer version (we use the newest version of the aspose pdf library - download today, march 23th 2015) 
.
I am afraid Aspose.Pdf for Java does not support/provide and Document Explorer object to inspect PDF file elements. However you may programmatically parse PDF file elements through our API. 

We are sorry for this inconvenience.

Thanks very much, I will try it!