C#(PDF Compression)
Big PDF file to Small PDF.
Can you help me.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Samet Deniz2 reputationPosted Jul 15, 2015, 6:56 AM EDT
http://www.codeproject.com/Questions/244973/How-to-optimize-pdf-using-csharp
This post uses LEADTOOLS to do PDF compression:
http://support.leadtools.com/SupportPortal/CS/forums/44358/ShowPost.aspx
Rajeesh MenothRank #118 · 18.4K reputationPosted Jul 15, 2015, 8:21 AM EDT
Anurag SarkarRank #1,049 · 1.8K reputationPosted Mar 31, 2015, 4:09 AM EDT
https://www.google.co.in/#q=c%23+compress+pdf+size
http://stackoverflow.com/questions/13719553/compress-existing-pdf-using-c-sharp-programming-using-freeware-libraries
Please try this code:-
List pagesToReplace = new List(); PdfImageCollection pagesToEncode = new PdfImageCollection(); using (Document doc = new Document(sourceStream, password)) { for (int i=0; i doc.Pages.Count; i++) { Page page = doc.Pages[i]; if (page.SingleImageOnly) { pagesToReplace.Add(i); // a PDF image encapsulates an image an compression parameters PdfImage image = ProcessImage(sourceStream, doc, page, i); pagesToEncode.Add(i); } } PdfEncoder encoder = new PdfEncoder(); encoder.Save(tempOutStream, pagesToEncode, null); // re-encoded pages tempOutStream.Seek(0, SeekOrigin.Begin); sourceStream.Seek(0, SeekOrigin.Begin); PdfDocument finalDoc = new PdfDocument(sourceStream, password); PdfDocument replacementPages = new PdfDocument(tempOutStream); for (int i=0; i pagesToReplace.Count; i++) { finalDoc.Pages[pagesToReplace[i]] = replacementPages.Pages[i]; } finalDoc.Save(finalOutputStream);new link