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 Feb 25, 2021 11:22 am

Hello

I have noticed that every time Spire.PDF saves a document, the file gets bigger even if nothing changed.
Here is my code with the current version 7.2.9 for C#:

Code: Select all
static void Main()
{
    PdfDocument doc = new PdfDocument();
    doc.SaveToFile("Test0.pdf");

    for(int i=1; i<100; i++)
    {
        doc = new PdfDocument($"Test{i-1}.pdf");
        doc.SaveToFile($"Test{i}.pdf");
    }
}


The first PDF (Test0.pdf) is 2 KB and the last (Test99) is 1891 KB big!!!!

After searching this forum I found out about the incrementalUpdate property, so I tried it with this:

Code: Select all
static void Main()
{
    PdfDocument doc = new PdfDocument();
    doc.FileInfo.IncrementalUpdate = false;
    doc.SaveToFile("Test0.pdf");

    for(int i=1; i<100; i++)
    {
        doc = new PdfDocument($"Test{i-1}.pdf");
        doc.FileInfo.IncrementalUpdate = false;
        doc.SaveToFile($"Test{i}.pdf");
    }
}


This helped a lot, the last pdf now is only 37 KB but still way bigger than the initial file.

So I have tried this same loop but using my PDF instead of creating an empty one.
The initial PDF size is 436 KB and after 99 open-and-save operations without incremental update, this PDF is now 740 KB big, which is an increase of 69%.

Is this because of how the PDF standard is defined?
Is this a bug of Spire.PDF or known behaviour which can't be changed?

Thank you for looking into this.

RicoScheller
 
Posts: 35
Joined: Tue Jul 02, 2019 10:34 am

Fri Feb 26, 2021 6:02 am

Hello,

Thanks for your inquiry!

I have tested your two cases (creating an empty PDF and using a PDF with 14.6kb to do open-and-save operations 99 times) with the code you provided with the latest Spire.PDF V7.2.9, but all files keep the original size. Here I attached my testing result screenshots.

emptysize.png

14.6kb size.png

To help us reproduce and investigate your issue, please provide us with your input file, your system information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese) for reference. Thanks in advance!

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Fri Feb 26, 2021 9:46 am

Hey

After receiving your answer I thought about why it behaves differently on my computer.
Turns out, it was the watermark that constantly got added.
After applying my license key, it now keeps the size.

I guess I should apply the license key even for testing :D

RicoScheller
 
Posts: 35
Joined: Tue Jul 02, 2019 10:34 am

Fri Feb 26, 2021 10:12 am

Hello,

Thanks for your feedback!

Yes, the watermark will continue to increase the file size. Anyway, glad to hear that your issue has been solved.

If you encounter any issues related to our product in the future, just feel free to contact us.

Have a nice day!

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.PDF