• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

merging byte array of pdf

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic