Save pdf to jpeg using c#

后端 未结 3 1588
北恋
北恋 2020-12-02 09:49

I need to convert a pdf file into jpeg using c#. And the solution(library) have to be free.

I have searched a lot of information but seems that I dont get nothing cl

3条回答
  •  隐瞒了意图╮
    2020-12-02 10:42

    The library pdfiumviewer might be helpful here. It is also available as nuget.

    1. Create a new winforms app. Add nuget "PdfiumViewer" to it.
    2. This will also add two native dll's named "pdfium.dll" in folders x86 and x64 to your project. Set "Copy to Output Directory" to "Copy Always".
    3. Try out the following code (change paths to suit your setup).

          try
          {
              using (var document = PdfiumViewer.PdfDocument.Load(@"input.pdf"))
              {
                  var image = document.Render(0, 300, 300, true);
                  image.Save(@"output.png", ImageFormat.Png);
              }
          }
          catch (Exception ex)
          {
              // handle exception here;
          }
      

      Edit 2: Changed code to show that page index is 0 based as pointed out in comment by S.C. below

    Edit 1: Updated solution Have you tried pdfsharp?

    This link might be helpful

提交回复
热议问题