none
PDF To PNG File missing RRS feed

  • Question

  • Hi,

    I was trying to find how to convert the PDF file to PNG format. I checked in MSDN forun - looks like the path defined for different libraries are missing. Could you please help?

    Thanks in advance.

    Tuesday, September 2, 2014 2:15 AM

Answers

  • Try this code, remember to reference Spire.PDF dll to your project

    using System.Drawing;
    using System.Drawing.Imaging;
    using Spire.Pdf;
    
    
    namespace Pdf2Png
    {
        class Program
        {
            static void Main(string[] args)
            {
                PdfDocument doc = new PdfDocument();
                doc.LoadFromFile("sample.pdf");
                Image image = null;
                for (int i = 0; i < doc.Pages.Count; i++)
                {
                    image = doc.SaveAsImage(i);
                    image.Save(string.Format("img-{0}.png", i), ImageFormat.Png);
                }
    
                //image.Save("result.png", ImageFormat.Png);
                   //System.Diagnostics.Process.Start("result.png");
            }
    
        }
    }

    Wednesday, November 19, 2014 1:57 AM
  • Seriously, I do not think .NET framework comes with this library. You can use 3rd party like the one below

    http://www.rasteredge.com/how-to/csharp-imaging/pdf-convert-jpeg/

    convert from jpg to png should be easier.

    chanmm


    chanmm

    Tuesday, September 2, 2014 8:23 AM
  • Hi MSDN Key,

    Yes, I agree with chanmm. So you can use third-party as below

    There is a convert tool from the ImageMagick bundle can do this.

    In its simplest form, it's just

    convert myfile.pdf myfile.png
    For more information, please check Here

    Have a nice day!

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, September 3, 2014 7:50 AM
    Moderator

All replies

  • Seriously, I do not think .NET framework comes with this library. You can use 3rd party like the one below

    http://www.rasteredge.com/how-to/csharp-imaging/pdf-convert-jpeg/

    convert from jpg to png should be easier.

    chanmm


    chanmm

    Tuesday, September 2, 2014 8:23 AM
  • Hello

    try this sample project

    http://code.msdn.microsoft.com/Operate-PDF-file-in-C-585605ef

    If you want to run the sample code by yourself, you need to add its dll which is available on Codeplex

    https://freepdf.codeplex.com/

    Wednesday, September 3, 2014 1:30 AM
  • Hi MSDN Key,

    Yes, I agree with chanmm. So you can use third-party as below

    There is a convert tool from the ImageMagick bundle can do this.

    In its simplest form, it's just

    convert myfile.pdf myfile.png
    For more information, please check Here

    Have a nice day!

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, September 3, 2014 7:50 AM
    Moderator
  • Try this code, remember to reference Spire.PDF dll to your project

    using System.Drawing;
    using System.Drawing.Imaging;
    using Spire.Pdf;
    
    
    namespace Pdf2Png
    {
        class Program
        {
            static void Main(string[] args)
            {
                PdfDocument doc = new PdfDocument();
                doc.LoadFromFile("sample.pdf");
                Image image = null;
                for (int i = 0; i < doc.Pages.Count; i++)
                {
                    image = doc.SaveAsImage(i);
                    image.Save(string.Format("img-{0}.png", i), ImageFormat.Png);
                }
    
                //image.Save("result.png", ImageFormat.Png);
                   //System.Diagnostics.Process.Start("result.png");
            }
    
        }
    }

    Wednesday, November 19, 2014 1:57 AM
  • I find a much cheaper library: http://www.xspdf.com/guide/pdf-png-converting/, it's easy to convert pdf to png in c# directly.
    Tuesday, August 8, 2017 2:23 AM
  • Hi, this library is not free....
    Friday, February 14, 2020 9:29 PM
  • Hi, this library is not free....

    This thread is more than 5 years old

    No need of external library now, it is done with PdfDocument Class


    • Edited by Castorix31 Friday, February 14, 2020 9:43 PM
    Friday, February 14, 2020 9:36 PM
  • Can you link an example of how to use. I didn't see any, also in all of my research previously this didn't come up. I always get suggestions like ghostScript and ImageMagick. Thank You.
    Monday, February 17, 2020 1:56 PM
  • Can you link an example of how to use. I didn't see any, also in all of my research previously this didn't come up. I always get suggestions like ghostScript and ImageMagick. Thank You.
    Start a new thread because this one has already been answered
    Monday, February 17, 2020 2:22 PM