簡體   English   中英

在C#中從PDF文件頁面創建圖像

[英]Create images from PDF file pages in C#

我想從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);
        }
    }
}

但是當我使用這種方法時,我有異常。

ExternalException
Ghostscript轉換錯誤

在此輸入圖像描述

所以我解決了這個問題!問題在於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);
        }
    }
}

謝謝!問題已經結束。

"Example.png"替換為"Example%d.png"以獲取所有3頁。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM