Really without using itextSharp will be complicated, there is another library NPOI.XWPF.Usermodel, maybe this code can help you, in this example the code actually decreases the pages size, consequently decreasing the pdf size also:
const double scale = 0.5;
using (FileStream inputStream = new FileStream(@"..\..\../inputdocuments/PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read))
{
// open the source document
Document documentIn = new Document(inputStream);
// create the target document
Document documentOut = new Document();
// enumerate the pages in the source document
foreach (Page originalPage in documentIn.Pages)
{
// calculate a new size of the page
double scaledWidth = originalPage.Width * scale;
double scaledHeight = originalPage.Height * scale;
// append a scaled version of the original page to the target document
Page scaledPage = new Page(scaledWidth, scaledHeight);
documentOut.Pages.Add(scaledPage);
PageShape pageShape = new PageShape(originalPage, 0, 0, scaledPage.Width, scaledPage.Height);
scaledPage.VisualOverlay.Add(pageShape);
}
// write the target document to disk
using (FileStream outFile = new FileStream(@"..\..\output.pdf", FileMode.Create, FileAccess.Write))
{
documentOut.Write(outFile);
}
}
I saw this example on this site: http://www.tallcomponents.com/pdfkit/resize-pdf-pages
The complex here is that, because these algorithms are of intense commercial interest, it’s hard to find references that teach you how to write this type of code. At least until then I didn’t find any completely open example of C# code for this.
– Leonel Sanches da Silva
I’m also on the hunt for a free library for pdf compression in c# I’m using itextsharp but it doesn’t compress much compared to paid libs
– Rodolfo