Not able to Merge Large PDF Files

Hi,

I am trying to merge pdf files. I succesfully merge two small pdf files. But when I try to merge large pdf files ( almost 25 mb). It not merge that files and even not giving any error. Just gives a file (0 kb) as output.

//create two file streams to read pdf files
FileStream fs1 = new FileStream(“D:\TestODT.pdf”, FileMode.Open, FileAccess.Read);
FileStream fs2 = new FileStream(“D:\TestODT.pdf”, FileMode.Open, FileAccess.Read);

//create byte arrays to keep the contents of PDF files
byte[] buffer1 = new byte[Convert.ToInt32(fs1.Length)];
byte[] buffer2 = new byte[Convert.ToInt32(fs2.Length)];


int i = 0;
//read PDF file contents into byte arrays
i = fs1.Read(buffer1, 0, Convert.ToInt32(fs1.Length));
i = fs2.Read(buffer2, 0, Convert.ToInt32(fs2.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
PdfFileEditor pdfEditor = new PdfFileEditor();
//concatenate both input MemoryStreams and save to putput MemoryStream
pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream);
//convert MemoryStream back to byte array
byte[] data = pdfStream.ToArray();
//create a FileStream to save the output PDF file
FileStream output = new FileStream(“D:\merged_output.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();

}
}
}
//close input files
fs1.Close();
fs2.Close();


Please let me know if I am done anything wrong.

Thanks

Hi,

Thanks for using our products. Can you please share the source PDF documents so that we can test the scenario at our end. I have tried replicating the issue while using the sample PDF files that I have but I am unable to notice any issue. We apologize for your inconvenience.

Hi


This is one pdf file(attached). You can use copy of this file as another file.Because I am unable to upload the another file.

Thanks

Hi,


Thanks for sharing the resource PDF document. I have tested the scenario while using the same code snippet that you have shared and as per my observations, I am unable notice any issue while merging the PDF documents. I have tested the scenario with Aspose.Pdf for.NET 6.4.2. Can you please try using the new release version and in case you still face any problem, please share some details regarding your working environment. We apologize for your inconvenience.

Hi support
Thanks for reply. With your new DLL I am able to merge the pdf files of size 28MB. But the issue is that when I tried to merge the two larger pdf files (60 MB file each), it not merge the that files. Even it not gives me any error, it only return the file with 0kb size.
We have to merge 400 files( or more than that) each have size more than 20 MB.
OR Merge two files more than 2GB in size

I am using Visual Studio 2010 ( framework 4.0)

Thanks

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your feedback.

Please share your 60 MB PDF file with us (you may share the file on some fileserver and share the path here). This will help us reproduce the issue at our end.

Sorry for the inconvenience,

Hi Support

You can merge the file 2-3 times that I have already send to you, I am doing the same.

Thanks

HI Support,

This is just a gentle reminder that I am waiting for the solution to merge files more than 60 MB in size.

Thanks

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry for a delayed response.

I just tested your scenario with two 78 MB files (by making copies of your share file) with the latest version of Aspose.Pdf for .NET v6.5 and they where concatenated into a 156 MB file successfully. Please download and try the latest version at your end and let us know about the results at your end.

Thank You & Best Regards,

Just curious if/how this was resolved. I am seeing the same issue in my environment.


I am using Aspose.Pdf v6.6.0.0 to merge multiple memory stream pdfs. The first couple concatenate calls are fine however the stream suddenly becomes 0 in length in the middle of concatenate the multiple files.

What is strange about this it works fine in my development environment through Visual Studio. When I move the compiled code to our Stage or Production server the scenario described above happens.

I am not sure how to debug this since it works fine when debugging bug does not work when compiled and by itself.

Capturing the last exception from PdfFileEditor shows the following:



<span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:“Times New Roman”;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>System.ArgumentException:
Exception occured during the processing stream: 1 —> System.IO.IOException:
An attempt was made to move the position before the beginning of the stream.

at System.IO.MemoryStream.Seek(Int64 offset, SeekOrigin loc)

at <span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Verdana;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>€<span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>…(Int64 , SeekOrigin
)

at <span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Verdana;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>€<span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>..
[1]()

at <span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Verdana;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>€<span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>.…ctor(Stream ,
String , Boolean )

at <span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-bidi-font-family:Verdana;
mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>€<span style=“font-size:7.5pt;font-family:“Verdana”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;mso-bidi-font-family:“Times New Roman”;mso-ansi-language:
EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA”>.…ctor(Stream )

at Aspose.Pdf.Document.

[1](Stream

, String )

at Aspose.Pdf.Facades.PdfFileEditor.

[1](Stream[]

)

— End of inner exception stack trace —

at Aspose.Pdf.Facades.PdfFileEditor.

[1](Stream[]

)

at Aspose.Pdf.Facades.PdfFileEditor.Concatenate(Stream[] inputStream, Stream
outputStream)


Aspose support any response?


Hi Eric,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry for the delayed response.

Please create a sample application and post it here. Also, please let us know the details of your environment i.e. OS, .NET Framework, Memory of you machine etc. This will help us re-generate the scenario at our end.

Thank You& Best Regards,

I have uploaded a sample app (with out Aspose.PDF v6.6 to save on space)

The error occurred when trying to merge the 4th sample pdf

My machine is a Win 7 64 bit OS
4gb Ram

all version of .NET Framework are installed (2-4)

The pdfs were large samples I pulled from the internet but demonstrate the same problem I was originally having.

Hi Eric,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the details and sample application.

I am able to reproduce your mentioned issue using your shared application. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-33193 for rectification. You will be notified via this forum thread regarding any update against your issue.

Sorry for the inconvenience,

Hi Eric,


Thanks for your patience.

We have further investigated this issue and have observed that the problem is occurring when trying to merge documents in trial mode. During my testing, I have observed that when tested with Aspose.Pdf for .NET 6.8.0 in licensed mode, the documents are being merged in 19 seconds and resultant PDF is being generated. Can you please try using the latest release version and in case the problem still persists or you have any further query, please feel free to contact. We are sorry for your inconvenience.

The issues you have found earlier (filed as PDFNEWNET-33193) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.