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.

Tue Sep 14, 2021 12:53 pm

Hello!
I'm trying to compress pdfs using spire and I can't get it to compress the size.
If I compress the document through an external online page I see that it is reduced by half.
I have to generate a word, save it as pdf but compressed.


My code is similar to the next code more or less:

Document _documentFile = new Document("WordDocument.docx");
//-->change de _documentFile
//ff is the final format
_documentFile.IsUpdateFields = true;

if(ff== Spire.Doc.FileFormat.PDF)
{
MemoryStream temp = new MemoryStream();
_documentFile.SaveToStream(temp, ff);
PdfDocument pdfdoc = new PdfDocument(temp);
pdfdoc.FileInfo.IncrementalUpdate = false;
pdfdoc.CompressionLevel = PdfCompressionLevel.Best;
pdfdoc.SaveToStream(fileStream);

//FileStream have the same size with compression or without compression, but, if I use an external page the file is reduced to less than half
//if I try to use the TryCompressImage function, the application is blocked
}
else
{
_documentFile.SaveToStream(fileStream, ff);
}


How could I do this to make it work?

Thank you!

LauraNM
 
Posts: 92
Joined: Tue Feb 19, 2019 1:23 pm

Wed Sep 15, 2021 3:48 am

Hello,

Thanks for your inquiry.
Please provide your input file and we will investigate if it can be improved. You can upload it here or send it to us ([email protected]) via email. Thanks in advance for your assistance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Sep 15, 2021 5:54 am

Comprimir plantillas.rar


Actually it happens to me with all files ...
With Spire I cannot reduce them while on online pages they are compressed by half.
thank you very much for your help!

LauraNM
 
Posts: 92
Joined: Tue Feb 19, 2019 1:23 pm

Wed Sep 15, 2021 7:07 am

Hello,

Thanks for your sharing.
I tried to use our Spire.PDF to compress the PDF file you provided to us, and I did find that the compression of the file did not have much effect. I have posted this issue to our Dev team and they will do further analysis and improvement. We will inform you as soon as there is any update.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Nov 30, 2022 9:56 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.PDF 8.11.10 which fixes the issue with SPIREPDF-4641.
Please download the new version from the following links and use the following code to test.
Website download link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget download link: https://www.nuget.org/packages/Spire.Pdf/8.11.10
Code: Select all
PdfCompressor compressor = new PdfCompressor(fileName);
compressor.CompressToFIle(outputName);


Sincerely
Abel
E-iceblue support team
User avatar

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

Mon Jan 16, 2023 12:49 pm

What if want to compress and return the Stream instead of File?
I have requirement where I need to compress then upload file on AWS.
And my code is hosted on Aws serverless, where I can not save the file.

karanbodhani
 
Posts: 4
Joined: Mon Feb 08, 2016 5:34 am

Tue Jan 17, 2023 9:46 am

karanbodhani wrote:What if want to compress and return the Stream instead of File?
I have requirement where I need to compress then upload file on AWS.
And my code is hosted on Aws serverless, where I can not save the file.

Hi,

Thanks for your inquiry.
Saving to stream is not supported now, I added it as a new feature into our upgrade list with the ticket number SPIREPDF-5735. Once it is implemented, I will inform you asap.
If you have any other questions related to our products, just let us know.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Tue Jan 17, 2023 1:08 pm

Hello,

Example given in below link for compress PDf is taking aprox 20 mins for 20 MB

https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html

Can we make it faster some how ?

karanbodhani
 
Posts: 4
Joined: Mon Feb 08, 2016 5:34 am

Wed Jan 18, 2023 10:40 am

karanbodhani wrote:Hello,

Example given in below link for compress PDf is taking aprox 20 mins for 20 MB

https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html

Can we make it faster some how ?

Hi,

Thanks for your inquiry.
I simulated a pdf file, its size is about 50mb, and I used the code in our site (https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Document-Operation/How-to-Compress-PDF-Document-in-C-VB.NET.html), it cost about 30 seconds, could you please provide us with your document to help us do a further investigation? you can send it to us via email ([email protected]) or attach it here. Thanks for your assistance.
In addition, you can try our new method:
Code: Select all
PdfCompressor compressor = new PdfCompressor(fileName);
compressor.CompressToFIle(outputName);


Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Feb 15, 2023 10:44 am

karanbodhani wrote:What if want to compress and return the Stream instead of File?
I have requirement where I need to compress then upload file on AWS.
And my code is hosted on Aws serverless, where I can not save the file.

Hi,

Thanks for your patience.
Glad to inform you that we just released Spire.PDF_9.2.6, the new function “compress to stream” was implemented, see the following code for reference.
Code: Select all
           using (FileStream fileStream = new FileStream(outputFile, FileMode.Create))
            {
                PdfCompressor compressor = new PdfCompressor(inputFile);
                compressor.CompressToStream(fileStream);
                fileStream.Flush();
                fileStream.Close();
            }

Please download from the links and have a test.
Website: https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
Nuget: https://www.nuget.org/packages/Spire.PDF/9.2.6

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF