2009-09-15 72 views
3

在我的PDF中,我有一个包含10个图像的页面。使用c#2008将PDF文件拆分为图像文件?

我想将PDF文件分成10个独立的图像文件,并将它们保存在一个单独的文件夹中。

请给我一个想法或样本解决方案。

进出口使用C#2008

回答

1

我不知道这是不是还有一年后,有关的,但我只是做了它最近我自己,所以我想我只是回答反正。首先,你需要Ghostscript(http://sourceforge.net/projects/ghostscript/)一个古老的PS/PDF解析/渲染/转换引擎。安装完成后,请前往%PROGRAMDATA\gs\bin\(或x86,如果您正在运行x64系统)并抓取gsdll32.dll并将其复制到/ bin文件夹中。

然后您就需要所谓的超级转换PDF2Imagehttp://www.softwaresigloxxi.com/downloading_superPDF2ImageConverter.html)封闭源代码的PDF库,抓住从.zip文件的Pdf2Image.dll并将其复制到你的/ bin文件夹。

下面是有关如何使用这两个库的多个PDF页面转换为图像一个简单的例子:

using Pdf2Image; 

-

const string _filename = "/3.pdf"; 
    // Instantiate the component 
    var p2i = new Pdf2ImageConverter(_filename); 

    // Get page count of a PDF file 
    int pages = p2i.GetPageCount(); 
    Response.Write(pages); 

    // loops through each page 
    for (int i = 1; i < pages; i++) 
    { 
    // Get size of any page 
    int width, height; 
    p2i.GetPageSize(i, out width, out height); 

    // converts the page to PNG format (returns bitmap object with original size) 
    var pdfimage = p2i.GetImage(i, width, Pdf2ImageFormat.PNG); 
    pdfimage.Save(string.Format("/{0}.png",i)); 
    pdfimage.Dispose(); 
    } 

根据您的硬件,它不应该采取任何长于几页秒每页。

1

我假设你想要从PDF文件中的特定页面提取图像并将这些图像保存到单独的文件中。

如果我是对的,那么你可能想看看Docotic.Pdf library。这里展示了如何提取从PDF页面图像到指定文件夹中的示例:

static void ExtractImagesFromPdfPageIntoFolder() 
{ 
    string pathToPdf = ""; 
    int pageIndex = 0; 
    string outputFolder = ""; 
    using (PdfDocument pdf = new PdfDocument(pathToPdf)) 
    { 
     for (int i = 0; i < pdf.Pages[pageIndex].Images.Count; i++) 
     { 
      string imageName = string.Format("image{0}", i); 
      string outputName = Path.Combine(outputFolder, imageName); 
      string savedPath = pdf.Pages[pageIndex].Images[i].Save(outputName); 
     } 
    } 
} 

声明:我位奇迹,该库的供应商合作。