• Post Reply Bookmark Topic Watch Topic
  • New Topic

merging byte array of pdf  RSS feed

 
sand will
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am receiving 2 byte array of pdf. I want to merge these to bye array in to single byte array so that I can display single pdf.
I have written below code but I give error message that "The File is damaged and could not be repaired"
I tried with one byte array at a time and it does generate pdf properly.
What is wrong if I combine byte arrays.

byte[] pdfBytes1 = eFormsService.renderNewEForm("t01b3l7", formSpecId, getBaseUrl(request), getLoggedInUser());
byte[] pdfBytes2 = eFormsService.renderNewEForm("t01b3l7", 17, getBaseUrl(request), getLoggedInUser());
byte[] combined = new byte[pdfBytes1.length + pdfBytes2.length];
System.arraycopy(pdfBytes1,0,combined,0 ,pdfBytes1.length);
System.arraycopy(pdfBytes2,0,combined,pdfBytes1.length,pdfBytes2.length);

response.setContentType("application/pdf");
response.setContentLength(combined.length);

response.setHeader("Content-disposition", "inline; filename=" + formSpecId + ".pdf");
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, no-store, post-check=0, pre-check=0");
//response.getOutputStream().write(pdfBytes1);
response.getOutputStream().write(combined);
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't simply append structured document formats in the way you would do with text files. But there's no shortage of libraries that will merge PDF documents for you; check out Apache PDFBox.
 
sand will
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply "Ulf Dittmer". Actually client has asked us not to use any third party tool or API.So I was wondering if there is a way to play with byte array to merge the pdf documents.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't. PDF is a very complex format, without a library that knows the format very well you'll get nowhere.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!