我一直在使用此代码取得巨大成功,以提取PDF的每个页面中找到的第一个图像.但是,由于未知原因,它现在无法使用某些新PDF.我已经使用了其他工具(Datalogics等),这些工具可以很好地利用这些新的PDF来提取图像.但是,如果我可以使用iTextSharp,我不想购买Datalogics或任何工具.任何人都可以告诉我为什么这段代码没有找到PDF中的图像?
Knowns:我的PDF每页只有1张图片,没有别的.
using iTextSharp.text;
using iTextSharp.text.pdf;
...
public static void ExtractImagesFromPDF(string sourcePdf, string outputPath)
{
// NOTE: This will only get the first image it finds per page.
PdfReader pdf = new PdfReader(sourcePdf);
RandomAccessFileOrArray raf = new iTextSharp.text.pdf.RandomAccessFileOrArray(sourcePdf);
try
{
for (int pageNumber = 1; pageNumber <= pdf.NumberOfPages; pageNumber++)
{
PdfDictionary pg = pdf.GetPageN(pageNumber);
PdfDictionary res = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.RESOURCES));
PdfDictionary xobj = (PdfDictionary)PdfReader.GetPdfObject(res.Get(PdfName.XOBJECT));
if (xobj != null)
{
foreach (PdfName name in xobj.Keys)
{
PdfObject obj = xobj.Get(name);
if (obj.IsIndirect())
{ …
Run Code Online (Sandbox Code Playgroud) 我有一个从扫描软件生成的pdf.pdf每页有1个TIFF图像.我想从每个页面中提取TIFF图像.
我正在使用iTextSharp并且我已经成功找到了图像,并且可以从该PdfReader.GetStreamBytesRaw
方法中获取原始字节.问题是,正如我之前发现的那样,iTextSharp不包含PdfReader.CCITTFaxDecode
方法.
还有什么我知道的?即使没有iTextSharp,我也可以在记事本中打开pdf并找到流,/Filter /CCITTFaxDecode
我知道/DecodeParams
它正在使用CCITTFaxDecode组4.
有没有人知道如何从我的pdf中获取CCITTFaxDecode过滤图像?
干杯,卡胡