我正在尝试使用PDfSharp将pdf转换为jpeg。使用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)
是返回false。我不确定应该包含哪些资源,但对于转换的其余部分似乎很重要。我从pdfSharp示例站点复制了此代码。我的PDF可能有问题吗?我使用单词2010。
任何帮助将不胜感激!
资源键应以大写'R'开头。你有没有尝试过使用**/Resources **而不是**/resources **?其他键也有错误的大写。还是以不区分大小写的方式查找PDFSharp? – mkl 2013-09-07 07:01:42