I've generated two PDFs byte array and combined both of those arrays into one byte array. Now when I render the PDF through ActionMethod
in Controller
, it generates the PDF only for the second byte[]
passed in the Combine()
method.
Eg:
1)
public ActionResult ShowPdf(string id1, string id2)
{
byte[] pdfBytes1 = CreatePdf1(id1);
byte[] pdfBytes2 = CreatePdf2(id2);
byte[] combinedPdfData = Combine(pdfBytes1, pdfBytes2);
return File(combinedPdfData, "application/pdf");
}
If I write the above code, it generates the PDF only with the pdfBytes2
array data and pdfBytes1
array data is overwritten.
2) Now if change the order and write:
public ActionResult ShowPdf(string id1, string id2)
{
byte[] pdfBytes1 = CreatePdf1(id1);
byte[] pdfBytes2 = CreatePdf2(id2);
byte[] combinedPdfData = Combine(pdfBytes2, pdfBytes1);
return File(combinedPdfData, "application/pdf");
}
This method generates the PDF only with the pdfBytes1
array data.
My Combine() method code is:
public static byte[] Combine(byte[] first, byte[] second)
{
byte[] ret = new byte[first.Length + second.Length];
Buffer.BlockCopy(first, 0, ret, 0, first.Length);
Buffer.BlockCopy(second, 0, ret, first.Length, second.Length);
return ret;
}
While debugging I can see that combinedPdfData
array contains total bytes ie. pdfBytes1[] + pdfBytes2[]
but while printing it prints the data only for the one array. Please let me know where I'm doing wrong.