c# - Ghostscript 在拆分 PDF 后增加文件大小

标签 c# image pdf ghostscript.net

我正在将 PDF 文件拆分为图像并且工作正常,但问题是我的 PDF 文件在将此文件拆分为图像后大小为 2.5 MB,总大小增加到 8 MB。所以我不想增加这些图像的大小,因为这是服务器上的存储问题。

代码

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);
    }
}

最佳答案

PDF 文件是页面布局的矢量描述。图像文件是位图。矢量描述流行的原因之一是因为它们比位图更紧凑。

如果您的位图太大,那么您可以降低渲染它们的分辨率,显然这会降低质量。

除此之外,您的期望似乎不切实际。图像文件几乎总是比矢量文件大。

关于c# - Ghostscript 在拆分 PDF 后增加文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40521917/

相关文章:

c# - 是否有在 C# (Unity) 中编写异步委托(delegate)的优雅解决方案

c# - 即使 Azure 函数并行运行,为什么 Azure Eventhub 批量消息处理比单个消息处理更快?

c# - "Intelligent"将 double 转换为两个不同格式的字符串?

ios - 如何从 effectView 中删除 imageView

html - 将固定的 HTML 表格转换为相关表格 - 保持尺寸

c# - 在不重定向或重新加载页面的情况下单击 html 元素时执行代码

html - 想从我的背景图片中删除默认边框

javascript - 在 javascript 中插入 img 源

python - 如何使用python电报机器人将pdf文件发送回用户?

html - 在嵌入的 pdf 中添加 s3 签名的 url 不起作用