Hi
We have size restrictions on a page level.
I tried to open the PDF file, loop over each page, optimize each page, add the optimized page to a new PDF document, and after I have looped over all the pages I saved the new PDF document, but the size of the document is now larger than the original PDF document.
Can you please assist me?
public void Method(string pdf)
{
Document optimizedDoc = new Document();
using (var originalDocument = new Document(pdf))
{
foreach (var page in originalDocument.Pages)
{
Document newPageDoc = new Document();
newPageDoc.Pages.Add(page);
newPageDoc.Save();
newPageDoc.OptimizeResources(new OptimizationOptions
{
RemoveUnusedObjects = true,
ImageCompressionOptions =
{
CompressImages = true,
ImageQuality = 50,
ResizeImages = true
},
RemoveUnusedStreams = true,
MaxResoultion = 150,
UnembedFonts = true,
RemovePrivateInfo = true,
AllowReusePageContent = true,
LinkDuplcateStreams = true
});
newPageDoc.Save();
optimizedDoc.Pages.Add(newPageDoc.Pages.FirstOrDefault());
}
optimizedDoc.Save(@"C:\blah1.pdf");
}
}
file-example_PDF_1MB.pdf (1017.7 KB)
image.png (23.3 KB)