This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

how to combine two different PDF's and return only byte[]

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i want to combine multiple pdf's into a byte array.

what i have written the code:

PdfReader reader1 = new PdfReader("D:/take mails/ECM Files/from ECM/interactiveReport.pdf");
PdfReader reader2 = new PdfReader("D:/take mails/ECM Files/from ECM/interactiveReport.pdf");
PdfCopyFields copy = new PdfCopyFields(new FileOutputStream("concatenatedPDF.pdf"));
copy.addDocument(reader1);
copy.addDocument(reader2);

here i need to convert to byte array.

ServletOutputStream outputStream = response.getOutputStream();
// byte[] bytes2 = new String(bytes, "utf-8").concat(new String(bytes1, "utf-8")).getBytes();
outputStream.write(bytes2, CommonConstants.INITIALIZE_TO_ZERO, bytes2.length);
outputStream.flush();
outputStream.close();

Thanks in advance
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's not working?
 
purushotham podaralla
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i combined two pdf's into one pdf using
new PdfCopyFields().addDocument(reader1); new PdfCopyFields().addDocument(reader2);
aftter that i want to get byte[] from PdfCopyFields().
here i struggled to get the byte[]. please let me know how to get the byte[]. this byte array need to open in a pdf file as shown above.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need to write the combined PDF to a file? If not, this should work:

PdfCopyFields copy = new PdfCopyFields(outputStream);

If you do need it as file as well, you'll have to read the bytes from it.
 
purushotham podaralla
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my requirement i want to take two pdf files to combine to one pdf and then generate that pdf in the screen without storing in any location.

But what i provided the code is storing in one location. this should not.
let me know how to generate the report without storing in any location.
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, the approach I mentioned should work fine.
 
You can't have everything. Where would you put it?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!