Hello,
Thanks for your patience!
After further investigate in your project, I found the reason caused the memory increase and the generated file big.
For the memory increase issue. In your code, you generated the many Font, PdfTrueTypeFont, PdfSolidBrush, PdfPen in each page loop, but did not dispose them after using. This caused the memory these objects use never release and just stacked in memory. The more the pages you generate, the more the memory is consumed.
For the Font object instance from System.Drawing, I just recommend that you can release them after using it by "font.Dispose();". But for the PdfTrueTypeFont, PdfSolidBrush, PdfPen objects from our Spire.PDF, sorry that we do not have the dispose method for them now, but we have the development plan for this. Due to the underlying problem here is very complex, I am afraid that we cannot provide this method for a short period of time. As a temporary method, you can use the following code to save the PDF every 100 pages, release the PdfDocument object, and then reload it. Our product will release the memory of PdfDocument, PdfTrueTypeFont, PdfSolidBrush, PdfPen used each load and close. Here I also attached the compare result about memory use between your original project and the project I changed. You can see that it decrease almost 15% memory use. Since the dispose method is still in developing, I am afraid that this is the better way to decrease the memory use.
- Code: Select all
if (pageNumber % 100 == 0)
{
pdfDoc.SaveToFile(filePath);
pdfDoc.Dispose();
pdfDoc.Close();
pdfDoc = new Spire.Pdf.PdfDocument(filePath);
pdfDoc.FileInfo.IncrementalUpdate = false;
pdfDoc.FileInfo.Version = (Spire.Pdf.PdfVersion)PdfVersion;
pdfDoc.DocumentInformation.Author = "Arthur Informatica s.r.l.";
pdfDoc.CompressionLevel = (Spire.Pdf.PdfCompressionLevel)PdfCompressionLevel;
}
For the generated file size too large issue. Even in eyes see that the generated file is completely empty, but each time the project called page.Canvans.DarwXXX method will add data to the PDF document, and after more than 3000 pages, this size is normal. Hope you can understand.
I also attached the project after change via email, please refer it on your side.
Sincerely,
Marcia
E-iceblue support team