【问题标题】:Create images from PDF file pages in C#在 C# 中从 PDF 文件页面创建图像
【发布时间】:2015-01-29 10:59:57
【问题描述】:

我想从 PDF 文件页面获取图像。我知道一个好的解决方案是使用 ghostscriptsharp。它有一种特殊的方法来获取单页或多页。

GeneratePageThumbs(string inputPath, string outputPath, int firstPage, int lastPage, int width, int height)

这是我的完整代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GhostscriptSharp;

namespace GetPages
{
    class Program
    {
        static void Main(string[] args)
        {
            GhostscriptWrapper.GeneratePageThumbs(@"C:\Users\User\Downloads\English_Medium_Extra_for_WEB-2.pdf",
                @"C:\Users\User\Desktop\Test", 1, 3, 130, 130);
        }
    }
}

但是当我使用这种方法时,我遇到了异常。

外部异常
Ghostscript转换错误

【问题讨论】:

    标签: c# pdf ghostscriptsharp


    【解决方案1】:

    所以我解决了这个问题!问题在于 2 参数应该是你得到的图像的名称,而不是保存图像的路径! 这是代码正常工作:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using GhostscriptSharp;
    
    namespace GetPages
    {
        class Program
        {
            static void Main(string[] args)
            {
                GhostscriptWrapper.GeneratePageThumbs(@"C:\Users\User\Downloads\English_Medium_Extra_for_WEB-2.pdf",
                    "Example.png", 1, 3, 130, 130);
            }
        }
    }
    

    谢谢!问题已结束。

    【讨论】:

      【解决方案2】:

      "Example.png" 替换为"Example%d.png" 以获得所有3 页。

      【讨论】:

        猜你喜欢
        • 2012-11-16
        • 1970-01-01
        • 1970-01-01
        • 2014-04-16
        • 2012-01-19
        • 1970-01-01
        • 2017-10-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多