[英]Create images from PDF file pages in C#
I want to get images from PDF file pages. 我想从PDF文件页面获取图像。 I know that a good solution is to use ghostscriptsharp.
我知道一个好的解决方案是使用ghostscriptsharp。 It has a special method to get a single page or multiple pages.
它有一种特殊的方法来获取单个页面或多个页面。
GeneratePageThumbs(string inputPath, string outputPath, int firstPage, int lastPage, int width, int height)
Here is my complete code: 这是我的完整代码:
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);
}
}
}
But when I use this method I have exception. 但是当我使用这种方法时,我有异常。
ExternalException
ExternalException
Ghostscript conversion errorGhostscript转换错误
So i fix this!The problem lies in the fact that 2 parameter should be the name of your image you get as a result, not a path where to save the image! 所以我解决了这个问题!问题在于2参数应该是你得到的图像的名称,而不是保存图像的路径! Here is the code works correctly:
这是代码正常工作:
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);
}
}
}
Thank you!Question is closed. 谢谢!问题已经结束。
将"Example.png"
替换为"Example%d.png"
以获取所有3页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.