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 12, 2019 12:36 pm

Hello,

We currently use Spire.PDF 5.8.16 in .NET Core. We use it to clean incoming PDFs for potentially malicious content by:
1) Load the input PdfDocument into memory and create a new output PdfDocument
2) Processing each page of the input file, saving it as a Drawing.Image in memory (200 dpi)
3) Loading a PdfBitMap from that image and calculating whether it needs to be resized
4) Using PdfPageBase.Canvas.DrawImage to draw the image loaded into memory
5) Save the output PdfDocument to a file

I have a scanned ~600KB PDF with about 50 pages that when cleaned this way, the output file size explodes to ~50MB. Way too much. When processing this file as described above, no resizing is done - the images are simply drawn in the original size of the document.

Now, I've looked into the ways you suggest compression, i.e. following your "C# How to compress PDF images" article on MSDN, but...:
* TryCompressImage doesn't seem available in either the newest version of Spire or in the .NET Core version.
* Reducing the quality of the images to 20 compromises the image quality quite a bit.

I've also looked at doc.CompressionLevel = PdfCompressionLevel.Best; - but that doesn't do much significant.

My question is, can this be done without compromising image quality too much? Or do you have any other suggestions for cleaning PDFs?

Thanks in advance.

daladala
 
Posts: 1
Joined: Thu Sep 12, 2019 12:21 pm

Fri Sep 13, 2019 5:26 am

Hi,

Thanks for your inquiry.
In order to help us investigate accurately and solve your issue soon, could you please share your input pdf file and used code?
You also could send the requested info to [email protected].
Thanks for your assistance in advance.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Fri Sep 13, 2019 10:38 am

Hi Daniel,

I received your email and got your files. Thanks for your sharing.
After investigating, I am sorry to tell you that now there is no effective way to reduce output PDF size to match the original PDF size while maintaining high resolution of the image(e.g.200 dpi). Even if converting to images at the default resolution(96 dpi), it only be able to reduce the file size by about a third, it's about 13 MB ( 200 dpi, about 36 MB).

Could you please tell us what file size you expect? Then I will forward it to our developer to do further research to find possible solutions.

Look forward to your reply.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Mon Sep 16, 2019 8:47 am

Hi Daniel,

After further investigating, the method page.TryCompressImage(0) is able to compress the image to a smaller size without affecting the quality of the image. At present, the method has not been added to .net core dll. I have requested our dev team to add it ASAP. I will inform you when it is supported in .net core.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Mon Sep 23, 2019 4:08 am

Hi Daniel,

Thanks for your waiting.
Glad to tell you that our developer just has finished adding page.TryCompressImag() feature on .NET Core version. Next, we will build a new version to verify it.
We will inform you once new version is released.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Mon Sep 30, 2019 9:41 am

Hi Daniel,

Thanks for waiting.
The new version, Spire.PDF Pack(Hot Fix) Version:5.9.16 has been released. Welcome to download and test page.TryCompressImag() feature on .NET Core version.
Downloading link on our website: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.PDF/5.9.16

Sincerely,
Amy
E-iceblue support team
User avatar

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

Return to Spire.PDF

cron