• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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: 43016
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: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, the approach I mentioned should work fine.
 
Don't play dumb with me! But you can try this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic