Govinda Rajbhar
Govinda Rajbhar

Reputation: 3034

Ghostscript increases file size after split PDF

I am splitting PDF file to Images and it is working fine, But issue is that I have PDF file it's size is 2.5 MB after splitting this file into images total size increases to 8 MB. So I don't want to increase these images size because this is storage issue on server.

Code

using (var pdfReader = new PdfReader(fileSavePath))
{
    var imagelst = new Pdf2Image(fileSavePath).GetImages(1, pdfReader.NumberOfPages);
    foreach (var image in imagelst)
    {
        imageModal = new ImageModel();
        imageModal.FileName = Guid.NewGuid().ToString() + ".png";
        image.Save(dirPath + "\\" + imageModal.FileName);       
        //Using below commented code I can decrease Image size 50 % percent but it creates Image quality problem. 
        //int newWidth = (int)(image.Width * 0.5);
        //int newHeight = (int)(image.Height * 0.5);
        //var newImage = ImageHelper.ResizeImage(image, newWidth, newHeight);
        //newImage.Save(dirPath + "\\" + imageModal.FileName);
        imageModelList.Add(imageModal);
    }
}

Upvotes: 2

Views: 639

Answers (1)

KenS
KenS

Reputation: 31141

PDF files are vector descriptions of a page layout. Image files are bitmaps. One of the reasons vector descriptions are popular is because they are more compact than bitmaps.

If your bitmaps are too large then you can reduce the resolution at which you render them, obviously this reduces quality.

Other than that, your expectations seem unrealistic. An image file is almost always going to be larger than a vector file.

Upvotes: 1

Related Questions