【发布时间】:2017-09-29 13:07:27
【问题描述】:
如果您有解决方案,请与我分享。
但是图像尺寸应该是最小的。
谢谢。
【问题讨论】:
-
你尝试了什么,你在哪里卡住了?
-
我想比较 PDF 文件的大小。像图像文件一样转换。
如果您有解决方案,请与我分享。
但是图像尺寸应该是最小的。
谢谢。
【问题讨论】:
以下代码示例演示了如何通过降低/压缩文档中图像的质量来压缩 PDF 文档。你可以试试看。
//Loads the PDF document
PdfDocument doc = new PdfDocument("Image.pdf");
//Disables the incremental update
doc.FileInfo.IncrementalUpdate = false;
//Traverses all pages
foreach (PdfPageBase page in doc.Pages)
{
//Extracts images from page
Image[] images = page.ExtractImages();
if (images != null && images.Length > 0)
{
//Traverses all images
for (int j = 0; j < images.Length; j++)
{
Image image = images[j];
PdfBitmap bp = new PdfBitmap(image);
//Reduces the quality of the image
bp.Quality = 20;
//Replaces the old image in the document with the compressed image
page.ReplaceImage(j, bp);
}
}
}
//Saves and closes the resultant document
doc.SaveToFile("Output.pdf");
doc.Close();
注意:此示例由 Spire.PDF 提供,我是 Spire 的员工。详细信息可以查看How to Compress PDF Document in C#, VB.NET文章。
【讨论】: