我正在尝试使用 PDFsharp 将 pdf 转换为 jpeg。
这是我的代码:
PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(doc);
PdfSharp.Pdf.PdfPage page = document.Pages[0];
// get resources dictionary
PdfSharp.Pdf.PdfDictionary resources = page.Elements.GetDictionary("/resources");
if (resources != null)
{
// get external objects dictionary
PdfSharp.Pdf.PdfDictionary xobjects = resources.Elements.GetDictionary("/xobject");
if (xobjects != null)
{
ICollection<PdfSharp.Pdf.PdfItem> items = xobjects.Elements.Values;
// iterate references to external objects
foreach (PdfSharp.Pdf.PdfItem item in items)
{
PdfSharp.Pdf.Advanced.PdfReference reference = item as PdfSharp.Pdf.Advanced.PdfReference;
if (reference != null)
{
PdfSharp.Pdf.PdfDictionary xobject = reference.Value as PdfSharp.Pdf.PdfDictionary;
// is external object an image?
if (xobject != null && xobject.Elements.GetString("/subtype") == "/image")
{
ExportJpegImage(xobject);
}
}
}
}
}
行:if (resources != null)
返回错误。我不确定resources
应该包含什么,但它似乎对其余的转换很重要。我从 PDFsharp 示例站点复制了这段代码。我的PDF可能有问题吗?我是用 Word 2010 制作的。