Create images from PDF file pages in C#

你说的曾经没有我的故事 提交于 2020-02-20 05:49:31

问题


I want to get images from PDF file pages. I know that a good solution is to use 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
Ghostscript conversion error


回答1:


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! 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.




回答2:


replace "Example.png" by "Example%d.png" to get all 3 Pages.



来源:https://stackoverflow.com/questions/28213012/create-images-from-pdf-file-pages-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!