I am attempting to convert a pdf to jpeg using PDfSharp.
Here is my code:
Code:
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);
}
}
}
}
}
The line:
Code:
if (resources != null)
is returning false. I am not sure what resources is supposed to contain, but it seems to be important for the rest of the conversion. I copied this code from the pdfSharp example site. Could there be an issue with my PDF? I made it using word 2010.
Any help would be greatly appreciated!