Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Sep 29, 2022 5:48 pm

We have been using Spire PDF since 2015 and have always had the "Out of Memory" exception when processing to many files at once. Long story short, anything much over 50 pdf pages at once will crash the dll with an Out Of Memory exception. With this we are forced to create a ton of files instead of one big one like we want.

This issues continues with the latest 8.9.2 dll. It says it is 64 bit compatible, but based on memory use in the program when calling Spire PDF dll, it climbs up and then hovers around 2 gig before crashing, which make me believe it only running in 32bit mode.

Also, when processing like 100 pages, it will successfully create the first two 100 page files, and crash during the 3rd one, which indicates to me the .Close and .Dispose are not working as designed.

Would love to know how others if anyone has successfully used the dll to process a large amout of PDF pages. Ideally we would be wanting 1000 or so.

Thanks in advance!

jgoeke
 
Posts: 7
Joined: Thu Sep 24, 2015 5:43 pm

Fri Sep 30, 2022 9:52 am

Hello,

Thanks for your inquiry.
The "Out of Memory" exception is related to document size, document structure, RAM of the system environment, etc. To help us reproduce your issue and work out a solution for you, please offer the following messages, thanks for your assistance in advance.

1) Your input document(If any).
2) Your full test code that can reproduce your issue.
3) Your test environment, such as Win10-64bit RAM 16G.
4) Application type, such as Console App, .NET Framework 4.8.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Fri Sep 30, 2022 5:38 pm

That for the reply :-). We are loading in a PDF template and populating the pdf with values then flattening it and saving. We load the single page PDF for each employee in the database. When the number of pages exceeds 50 or so, we run into this exception. I will include the code snippet involved. Running a C# .net 4.6 windows service. Machines are all WIn 10 64bit. Using your latest dll and i selected the .net 4.6 one from the download zip file. I see no way to use it in 64 bit mode or is that automatic?

Our code does a pdf file load, populate data, merge in more pages, and then save. currentBatchList is a list of data objects we have our data in to populate the pdf template in our method, and the number of objects (emp data as in pages) is controlled by a read in var. The Generate_1095C_Print_Pdf_ByPublish1095 method populates the pdf with the emp data. Once the pdf is populated, we insert the new page into the pdfDoc which is to be the cumulative pdf to be saved. Once saved and we finish with the .Close and .Dispose we do to insure the PdfDocument object is dropped so we can start again with the next batch of employees. Ideally we want just one of these files for all employees.

Code: Select all
                   
using (PdfDocument pdfDoc = new PdfDocument())
                    {
                        PdfDocument tempPdf = null;

                        try
                        {
                            for (int i = 0; i < currentBatchList.Count; i++)
                            {
                                tempPdf = Generate_1095C_Print_Pdf_ByPublish1095(
                                    pdfTemplateByteArray,
                                    currentBatchList[i].ACAPublish1095Entity,
                                    publish.Corrected,
                                    currentBatchList[i].SequenceNumber,
                                    year);
                                pdfDoc.InsertPageRange(tempPdf, 0, tempPdf.Pages.Count - 1);
                            }

                            string tempFileName = string.Format(
                                CultureInfo.InvariantCulture,
                                Filename1095CPrintBatchFile,
                                ConfigSettings.PdfDropLocation,
                                year,
                                clientName,
                                ein,
                                timeStamp,
                                currentBatchList[0].EmployeeId,
                                currentBatchList[currentBatchList.Count - 1].EmployeeId,
                                currentBatchList[0].SequenceNumber.ToString("00000", CultureInfo.InvariantCulture));

                            pdfDoc.SaveToFile(tempFileName);

                            Logger.Log(
                                ExceptionCode.TempPrintPDFGenerated,
                                null,
                                ExceptionCode.TempPrintPDFGenerated.Message(),
                                companyId,
                                ein,
                                tempFileName);
                        }
                        finally
                        {
                            if (tempPdf != null)
                            {
                                tempPdf.Close();
                                tempPdf.Dispose();
                            }
                        }



Abel.He wrote:Hello,

Thanks for your inquiry.
The "Out of Memory" exception is related to document size, document structure, RAM of the system environment, etc. To help us reproduce your issue and work out a solution for you, please offer the following messages, thanks for your assistance in advance.

1) Your input document(If any).
2) Your full test code that can reproduce your issue.
3) Your test environment, such as Win10-64bit RAM 16G.
4) Application type, such as Console App, .NET Framework 4.8.

Sincerely
Abel
E-iceblue support team

jgoeke
 
Posts: 7
Joined: Thu Sep 24, 2015 5:43 pm

Fri Sep 30, 2022 5:43 pm

jgoeke wrote:Thanks for the reply :-). We are loading in a PDF template and populating the pdf with values then flattening it and saving. We load the single page PDF for each employee in the database. When the number of pages exceeds 50 or so, we run into this exception. I will include the code snippet involved. Running a C# .net 4.6 windows service. Machines are all WIn 10 64bit. Using your latest dll and i selected the .net 4.6 one from the download zip file. I see no way to use it in 64 bit mode or is that automatic?

Our code does a pdf file load, populate data, merge in more pages, and then save. currentBatchList is a list of data objects we have our data in to populate the pdf template in our method, and the number of objects (emp data as in pages) is controlled by a read in var. The Generate_1095C_Print_Pdf_ByPublish1095 method populates the pdf with the emp data. Once the pdf is populated, we insert the new page into the pdfDoc which is to be the cumulative pdf to be saved. Once saved and we finish with the .Close and .Dispose we do to insure the PdfDocument object is dropped so we can start again with the next batch of employees. Ideally we want just one of these files for all employees.

Code: Select all
                   
using (PdfDocument pdfDoc = new PdfDocument())
                    {
                        PdfDocument tempPdf = null;

                        try
                        {
                            for (int i = 0; i < currentBatchList.Count; i++)
                            {
                                tempPdf = Generate_1095C_Print_Pdf_ByPublish1095(
                                    pdfTemplateByteArray,
                                    currentBatchList[i].ACAPublish1095Entity,
                                    publish.Corrected,
                                    currentBatchList[i].SequenceNumber,
                                    year);
                                pdfDoc.InsertPageRange(tempPdf, 0, tempPdf.Pages.Count - 1);
                            }

                            string tempFileName = string.Format(
                                CultureInfo.InvariantCulture,
                                Filename1095CPrintBatchFile,
                                ConfigSettings.PdfDropLocation,
                                year,
                                clientName,
                                ein,
                                timeStamp,
                                currentBatchList[0].EmployeeId,
                                currentBatchList[currentBatchList.Count - 1].EmployeeId,
                                currentBatchList[0].SequenceNumber.ToString("00000", CultureInfo.InvariantCulture));

                            pdfDoc.SaveToFile(tempFileName);

                            Logger.Log(
                                ExceptionCode.TempPrintPDFGenerated,
                                null,
                                ExceptionCode.TempPrintPDFGenerated.Message(),
                                companyId,
                                ein,
                                tempFileName);
                        }
                        finally
                        {
                            if (tempPdf != null)
                            {
                                tempPdf.Close();
                                tempPdf.Dispose();
                            }
                        }



Abel.He wrote:Hello,

Thanks for your inquiry.
The "Out of Memory" exception is related to document size, document structure, RAM of the system environment, etc. To help us reproduce your issue and work out a solution for you, please offer the following messages, thanks for your assistance in advance.

1) Your input document(If any).
2) Your full test code that can reproduce your issue.
3) Your test environment, such as Win10-64bit RAM 16G.
4) Application type, such as Console App, .NET Framework 4.8.

Sincerely
Abel
E-iceblue support team

jgoeke
 
Posts: 7
Joined: Thu Sep 24, 2015 5:43 pm

Mon Oct 03, 2022 1:14 pm

Hello,

Thanks for your more sharing.
I can’t reproduce your issue due to lack of staff information, please offer a simulated employee information and the code of Generate_1095C_Print_Pdf_ByPublish1095 method. Thanks for your assistance in advance.


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Oct 03, 2022 9:40 pm

I could continue to feed you code and such but frankly i think the issue will happen with any pdf that you load in and merge 100 pages or so, as in you don't even need to populate the PDF, just read in 200 pages, one at a time, and then try to save it as one large file. you should see the issue.

jgoeke
 
Posts: 7
Joined: Thu Sep 24, 2015 5:43 pm

Tue Oct 04, 2022 10:00 am

Hello,

Thanks for your feedback.
I used the following code to merge 200 Pdf files to one, and I didn’t reproduce your scenario and the program consumed about 2G memory. My test environment is win10 RAM 12G.
In addition, our product is 64 bit compatible, but you need to make sure the platform target of your program is X64, as shown in the screenshot below.

To help us do further investigation, please offer the following message. Thanks for your assistance.
1) Your system information (E.g. Win7, 64 bit, RAM:8GB) and the region setting (E.g. China, Chinese).
2) You can offer us a test demo project that can reproduce your issue, since forum has the size limitation for attachment. You could upload it to the DropBox or OneDrive and then share the download link with us.

Code: Select all
using (PdfDocument pdfDoc = new PdfDocument())
            {
                PdfDocument tempPdf = null;

                try
                {
                 
                    for (int i = 0; i < 200; i++)
                    {
                        tempPdf = new PdfDocument();
                        tempPdf.LoadFromFile(@"../../data/ACA1095C-Print-Template.pdf");
                        pdfDoc.InsertPage(tempPdf,0, tempPdf.Pages.Count - 1);
                    }

                    string tempFileName = @"../../output/result1.pdf";
                    pdfDoc.SaveToFile(tempFileName,FileFormat.PDF);

               
                }
                finally
                {
                    if (tempPdf != null)
                    {
                        tempPdf.Close();
                        tempPdf.Dispose();
                    }
                }
            }


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Tue Oct 04, 2022 8:48 pm

Wow thanks! Didn't think to try the build setting for x64. I did that and retested and it works great! Processed 1542 employees no problem. Took an hour and a half, but it finished :-).
So we have a license for your product, but the pdfs are showing up as evaluation red marked. The previous version of the dll works with the license, the the new one appears to not. What do i need to fix that?

jgoeke
 
Posts: 7
Joined: Thu Sep 24, 2015 5:43 pm

Wed Oct 05, 2022 1:35 am

Hello,

I checked your license was expired in 2016. So it is invalid for the dlls which were released after 2016. To remove the evaluation red marked, please contact our [email protected].

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Fri Oct 07, 2022 3:45 pm

Ok thanks. Will have someone do that :-)

jgoeke
 
Posts: 7
Joined: Thu Sep 24, 2015 5:43 pm

Sat Oct 08, 2022 1:46 am

Thanks for your notice.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3043
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF

cron