且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用c#将pdf保存到jpeg

更新时间:2023-02-12 21:15:31

图书馆 pdfiumviewer 可能会对您有所帮助。它也可以作为nuget使用。

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


  1. 创建一个新的winforms应用程序。添加nugetPdfiumViewer。

  2. 这也将在文件夹x86和x64中将两个名为pdfium.dll的本机dll添加到您的项目中。将复制到输出目录设置为始终复制。

  3. 尝试以下代码(更改路径以适合您的设置)。

  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;
    }

编辑2:更改代码以显示页面索引为0正如SC下面的评论所指出的

编辑1:更新解决方案
你试过pdfsharp吗?

Edit 1: Updated solution Have you tried pdfsharp?

此链接可能会有所帮助