Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dears,

I have two array of bytes each one of them represents a report of one page.
i want to to merge them and generates a pdf report of two pages.

how can i do that?

What I have tried:

C#
byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension1, out streamIds, out warnings);
byte[] bytes1 = ReportViewer2.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension1, out streamIds, out warnings);

byte[] newByteArray2 = bytes.Concat(bytes1).ToArray();

System.IO.File.WriteAllBytes("C://MyNewReport.pdf", newByteArray2);
Posted
Updated 27-Jun-16 4:50am
Comments
[no name] 27-Jun-16 10:45am    
http://stackoverflow.com/questions/114692/reportviewer-localreport-merge-reports
[no name] 27-Jun-16 11:24am    
Or you can create like your sample above and producing 2 PDF files, then merge it using iTextSharp : http://weblogs.sqlteam.com/mladenp/archive/2014/01/10/simple-merging-of-pdf-documents-with-itextsharp-5-4-5.aspx

1 solution

Just concatenating byte arrays won't do anything useful - DPF is a "container" format, so just "bolting" two containers together doesn't produce one big container. Any more than stapling two bags of sugar together would create a bigger bag full of twice as much sugar...

Have a look at this: Splitting and Merging PDF Files in C# Using iTextSharp[^]
 
Share this answer
 
Comments
_ProgProg_ 28-Jun-16 5:38am    
Couldn't i merge the two byte arrays and then save them???
OriginalGriff 28-Jun-16 5:46am    
No.
They don't just contain the page text, but the "whole package" which makes up a PDF document. If you just cram the two arrays together you get two different packages one after the other, and the PDF reader doesn't know what to do with them both.
What you have to do is create a new document which contains both pages.
_ProgProg_ 28-Jun-16 5:50am    
Yes this is what i want which is to create a new document contains the both pages without creating pdf for each byte array. I mean using the two byte arrays directly to generate the new document.
Is that applicable?
OriginalGriff 28-Jun-16 6:00am    
Follow the link and start reading!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900