Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PDFBOX- PDDocument to ByteArray

 
Marco Pasqualone
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2952
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Can you show the code you tried to use, remembering to UseCodeTags (← click) .
 
Marco Pasqualone
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The PDDocument isn't empty..but pdStream.getByteArray() length is 0

 
Tony Docherty
Bartender
Posts: 2952
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure it isn't empty - have you tried printing the pdDoc object?
 
Marco Pasqualone
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed..Even if I don't kwon why the PDStream still remains empty..
 
Tony Docherty
Bartender
Posts: 2952
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco Pasqualone, I got the same blank nothingness until I broke the pddocument into pages like so:

 
Tony Docherty
Bartender
Posts: 2952
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Nathan and thanks for posting a solution.
 
Marco Bianconi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic