我想从PDF文件页获得图像。我知道一个很好的解决方案就是使用鬼怪脚本。它有一种特殊的方法来获取一个或多个页面。
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);
}
}
}但是当我使用这种方法时,我会有异常。
ExternalException Ghostscript转换错误

发布于 2015-01-29 12:50:54
因此,我修正了这个问题!问题在于,这两个参数应该是您得到的图像的名称,而不是保存图像的路径!下面是正确工作的代码:
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);
}
}
}谢谢!问题结束了。
发布于 2018-04-08 18:04:06
将"Example.png"替换为"Example%d.png",以获得所有3页。
https://stackoverflow.com/questions/28213012
复制相似问题