Can not able to Merge Bytes of PDF file (occurs to error at red part)

byte[] buffer1 = new byte[Convert.ToInt32(fileList[0].Length)];// new byte[Convert.ToInt32(fs1.Length)];
byte[] buffer2 = new byte[Convert.ToInt32(fileList[1].Length)];// new byte[Convert.ToInt32(fs2.Length)];


// int i = 0;
//read PDF file contents into byte arrays
// fout.Read(buffer1, 0, Convert.ToInt32(buffer1.Length));
//fout.Read(buffer2, 0, Convert.ToInt32(buffer2.Length));

//now, first convert byte arrays into MemoryStreams and then concatenate those streams
using (MemoryStream pdfStream = new MemoryStream())
{
using (MemoryStream fileStream1 = new MemoryStream(buffer1))
{
using (MemoryStream fileStream2 = new MemoryStream(buffer2))
{
//create instance of PdfFileEditor class to concatenate streams
Aspose.Pdf.Facades.PdfFileEditor pdfEditor = new Aspose.Pdf.Facades.PdfFileEditor();
//concatenate both input MemoryStreams and save to putput MemoryStream
pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream);
//fileStream1.WriteTo(pdfStream);
//convert MemoryStream back to byte array
byte[] data = pdfStream.ToArray();
//create a FileStream to save the output PDF file
FileStream output = new FileStream(outMergeFile, FileMode.Create,
FileAccess.Write);
//write byte array contents in the output file stream
output.Write(data, 0, data.Length);
//close output file
output.Close();
}
}
}

Hi there,


Thanks for your inquiry. I have tested the scenario using Aspose.Pdf for .NET 11.2.0 with my sample PDF files and unable to notice any issue. Please share some more details about the issue, error details and sample PDF files here, we will look into it and guide you accordingly.

byte[] buffer1 = File.ReadAllBytes(“E:/data/HelloWorld.pdf”);//new byte[Convert.ToInt32(fileList[0].Length)];// new
byte[Convert.ToInt32(fs1.Length)];
<o:p></o:p>

byte[] buffer2 = File.ReadAllBytes("E:/data/39948.pdf");//new byte[Convert.ToInt32(fileList[1].Length)];// new byte[Convert.ToInt32(fs2.Length)];

// int i = 0;

//read PDF file contents into byte arrays

// fout.Read(buffer1, 0, Convert.ToInt32(buffer1.Length));

//fout.Read(buffer2, 0, Convert.ToInt32(buffer2.Length));

//now, first convert byte arrays into MemoryStreams and then concatenate those streams

using (MemoryStream pdfStream = new MemoryStream())

{

using (MemoryStream fileStream1 = new MemoryStream(buffer1))

{

using (MemoryStream fileStream2 = new MemoryStream(buffer2))

{

//create instance of PdfFileEditor class to concatenate streams

Aspose.Pdf.Facades.PdfFileEditor pdfEditor = new Aspose.Pdf.Facades.PdfFileEditor();

//concatenate both input MemoryStreams and save to putput MemoryStream

pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream);

//fileStream1.WriteTo(pdfStream);

//convert MemoryStream back to byte array

byte[] data = pdfStream.ToArray();

//create a FileStream to save the output PDF file

FileStream output = new FileStream("E:/data/mergedstream.pdf", FileMode.Create,

FileAccess.Write);

//write byte array contents in the output file stream

output.Write(data, 0, data.Length);

//close output file

output.Close();

}

}

}

Please feel free to contact us for any further assistance.


Best Regards,