//Loads the PDF document which c images
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Server.MapPath("../App_Data/example.pdf"));
//Disables the incremental update
loadedDocument.FileStructure.IncrementalUpdate = false;
//Iterates all the pages to replace images
foreach (PdfPageBase page in loadedDocument.Pages)
{
//Extracts the images from the document
Image[] extractedImages = page.ExtractImages();
//Iterates all the image
for (int j = 0; j < extractedImages.Count(); j++)
{
PdfBitmap img = new PdfBitmap(extractedImages[j]);
//Reduces the quality of the image
img.Quality = 50;
//Replaces the compressed image with old image in the PDF document
page.ReplaceImage(j, img);
}
} |