PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Jun 25, 2024 6:18 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Jul 06, 2012 4:09 pm 
Offline

Joined: Fri Jul 06, 2012 4:06 pm
Posts: 1
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!


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 09, 2012 8:50 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
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).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group