2

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);
    }
}
Govinda Rajbhar
  • 2,926
  • 6
  • 37
  • 62
  • What do you mean by "split to images"? Are you rasterizing it? What image type do you use, what colour depth, compression etc.? You might get more hints if you post the full ghostscript command and also describe what the input file contains - only black/white text? JPEG photos? All this would be relevant for your question, – Stefan Hegny Nov 10 '16 at 08:00
  • Removing C# and asp.net-mvc tags because no sign of relevance. – Richard Nov 10 '16 at 08:04
  • @StefanHegny "Split to Images" means I have pdf file which contains number of pages and I am converting each page to Image. And I am saving it as png images. And this all things I am performing in C# with MVC Using Ghostscript.net – Govinda Rajbhar Nov 10 '16 at 08:21
  • Please follow this link https://www.sejda.com/visually-combine-reorder-pdf I have done same thing. But only facing File size issue. – Govinda Rajbhar Nov 10 '16 at 08:26
  • Won't look until I see your ghostscript parameters in the question... you could also briefly describe what's expected in the pdf – Stefan Hegny Nov 10 '16 at 08:36
  • @StefanHegny Now please take a look – Govinda Rajbhar Nov 10 '16 at 08:40
  • @Richard Sorry but i have to put C# tag – Govinda Rajbhar Nov 10 '16 at 08:42
  • Hm, but now I don't see ghostscript but PdfReader, sorry never heard of that... maybe I should have stayed out of a .net thing from start - good luck – Stefan Hegny Nov 10 '16 at 09:51
  • No problem: C# is now (after your edit) relevant. – Richard Nov 10 '16 at 10:04

1 Answers1

1

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.

KenS
  • 30,202
  • 3
  • 34
  • 51