关于c#iText7:c#iText 7-遍历pdf图像并更改大小和dpi

c# iText7 - interate throuh pdf images and change size and dpi

我有很多很大的PDF文件,其中包含巨大的图像(扫描图)。
目的是打开PDF,阅读所有图像,更改dpi,分辨率并压缩它。

如何使用Itex7进行管理?
通常,如何遍历PDF中的所有图像?

1
2
3
4
5
6
7
8
9
10
11
using (iText.Kernel.Pdf.PdfReader pdfReader = new iText.Kernel.Pdf.PdfReader(inputPdfFile))
{
    using (iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(pdfReader))
    {
        //??
        //foreach (var image in pdfDocumentImagesList)
        //{
            //  //image.SetNewDPI()                
        //}
    }
}

如何浏览所有PDF图像?

https://github.com/itext/i7js-book/blob/develop/src/test/java/com/itextpdf/samples/book/part4/chapter15/Listing_15_30_ExtractImages.java
https://github.com/itext/i7js-book/blob/develop/src/test/java/com/itextpdf/samples/book/part4/chapter15/Listing_15_31_MyImageRenderListener.java

如何更改图像的dpi和分辨率?

这不是iText功能的一部分,因为iText是PDF而不是图像处理库。我建议您使用其他一些工具处理提取的图像,然后将其放入新文档或替换PDF中的图像。后者不是很容易。可能的下一个SO答案可能会对此有所启发:http://stackoverflow.com/questions/26580912/pdf-convert-to-black-and-white-png
(其代码,但在iText7中:https://github.com/itext/i7js-examples/blob/develop/src/test/java/com/itextpdf/samples/sandbox/images/ReplaceImage.java)

如何压缩图像?

https://github.com/itext/i7js-book/blob/develop/src/test/java/com/itextpdf/samples/book/part3/chapter10/Listing_10_12_CompressImage.java

希望那会有用!