wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes PDFBOX- PDDocument to ByteArray Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "PDFBOX- PDDocument to ByteArray" Watch "PDFBOX- PDDocument to ByteArray" New topic
Author

PDFBOX- PDDocument to ByteArray

Marco Pasqualone
Greenhorn

Joined: May 28, 2013
Posts: 6
Hi,
I'd like to get a bytearray from a PDDocument..I tried to use PDStream(PDDocument pdDoc) but the object created seems to be empty!

Any Help??

Thank you!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2158
    
  47
Welcome to the Ranch.

Can you show the code you tried to use, remembering to UseCodeTags (← click) .
Marco Pasqualone
Greenhorn

Joined: May 28, 2013
Posts: 6
The PDDocument isn't empty..but pdStream.getByteArray() length is 0

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2158
    
  47
Are you sure it isn't empty - have you tried printing the pdDoc object?
Marco Pasqualone
Greenhorn

Joined: May 28, 2013
Posts: 6
Fixed..Even if I don't kwon why the PDStream still remains empty..
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2158
    
  47
Glad to hear you have found a way around the problem. I've also no idea why your original idea didn't work but I have no experience of using the library, hopefully someone has used this library will be able to explain why.
Nathan Powers
Greenhorn

Joined: Mar 10, 2014
Posts: 1
Marco Pasqualone, I got the same blank nothingness until I broke the pddocument into pages like so:

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2158
    
  47
Welcome to the Ranch Nathan and thanks for posting a solution.
Marco Bianconi
Greenhorn

Joined: Mar 14, 2014
Posts: 1
Nathan Powers wrote:Marco Pasqualone, I got the same blank nothingness until I broke the pddocument into pages like so:



Hi, I tried your suggestion and it goes.. contents.getByteArray() is correctly filled...
so how can I retrive the entire doc byte array by this way (reading contents bytestream of each page)?
Did You find a solution?
Thanks in advance,
M.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41033
    
  43
If the PDF is in a file, you could use a FileInputStream to read it into a byte[].

If the PDF is a PDDocument, you can save it to a ByteArrayOutputStream, and get a byte[] that way.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PDFBOX- PDDocument to ByteArray
 
Similar Threads
Conversion of Pdf Data to Text Data
Read PDF using Java
getting problem while indexing pdf files with pdfbox with lucene
java.io.IOException: Error: End-of-File, expected line
Barcode in PDF