PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Converting PDF to Jpeg - Issue with example from site
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2076
Page 1 of 1

Author:  paulfrancis [ Fri Jul 06, 2012 4:09 pm ]
Post subject:  Converting PDF to Jpeg - Issue with example from site

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!

Author:  Thomas Hoevel [ Mon Jul 09, 2012 8:50 am ]
Post subject:  Re: Converting PDF to Jpeg - Issue with example from site

The sample code exports JPEG images included in a PDF file as JPEG files. It does not convert PDF pages to JPEG files (and I guess that is what you expect).

You can use other tools, e.g. GhostScript, for that purpose.
PDFsharp includes a wrapper class for GhostScript that allows you to create PNGs from PDF pages (but it can easily be modified to return JPEG files).

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/