• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Problem in writing concatenated byteArray to a PDF file

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have to two byte Array. I want to write them to one pdf file.
But the pdf displays only the second byte array content , i know its writing both because i concatenated the byte Arrays and written it as one byte array to the OutputStream.

my code is as follows
<code>
serverData = remoteServiceObject.doRemoteRequestProcess(clientRequest);
System.out.println("server data in tbq reports is" + serverData);
byte[] pdfReportByteArr = (byte[]) (serverData.get(0));
byte[] pdfReportByteArrDetailed = (byte[]) (serverData.get(1));

byte[] completeReport = concatenate(pdfReportByteArr,pdfReportByteArrDetailed);

System.err.println(pdfReportByteArr.length);
System.err.println(pdfReportByteArrDetailed.length);
System.err.println(completeReport.length);

response.setContentLength(completeReport.length);
response.setContentType("application/pdf");
response.setHeader("Expires", "0");
response.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");

ServletOutputStream out = response.getOutputStream();
try {
out.write(completeReport);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (Exception e) {
}
}
}

protected byte[] concatenate(byte[] a, byte[] b) {
byte[] complete = new byte[a.length + b.length];
System.arraycopy(a, 0, complete , 0, a.length);
System.arraycopy(b, 0, complete , a.length, b.length);
return complete ;
}
</code>

Any help appreciated.

Thanks,
Regards,
S.R.K.Vivek Raju.
 
Master Rancher
Posts: 43045
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does each array contain a complete PDF file? There's more to concatenating PDF pages into a document than appending their respective bytes. The iText library comes with a tool that can concatenate individual PDF files, and which can be used programmatically.

By the way, UBB code tags use square brackets, not angle brackets.
[ January 12, 2008: Message edited by: Ulf Dittmer ]
 
Vivek Raju
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Yes each array contains a complete PDF file.
How could i append them as a file without appending the bytes.

Please give some details.

Thanks,

Regards,
Vivek Raju.
 
Ulf Dittmer
Master Rancher
Posts: 43045
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
iText's com.lowagie.tools.concat_pdf class can do this. Have a look at the source code or the javadocs for more information about it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic