如何将pdf文件转换为图像 [英] how to convert pdf files to image

查看:202
本文介绍了如何将pdf文件转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些文件。它的格式是pdf
现在有一个项目,如果pdf是多页面,这个项目需要将pdf文件转换为Image
,我只需要一个包含所有pdf页面的图像。
我从谷歌得到一些答案,但有些工具是收费

I have some files. It's format is pdf Now there is a project, this project needs convert the pdf file to Image if the pdf is Multi-page,I just need one image contains all pdf pages. I get some answer from google,but some of tools is charge

所以,如何用C#解决它?
非常感谢!

so, how to solve it with C#? thank you very much!

我知道,在C#中使用Acrobat.dll可以解决这个问题。
但必须安装adobe acrobat并且它不是免费的。

I know,use the Acrobat.dll in C# can solve this problem. but it must installation the adobe acrobat and it is not free.

推荐答案

以下主题适合您的请求。
将pdf文件转换为jpeg图像

The following thread is suitable for your request. converting pdf file to an jpeg image

一种解决方案是使用第三方库。 ImageMagick非常受欢迎,也可以免费使用。您可以在此处获取.NET包装器。最初的ImageMagick下载页面是这里

One solution is to use a third party library. ImageMagick is a very popular, freely available too. You can get a .NET wrapper for it here. The original ImageMagick download page is here.

  • http://www.codeproject.com/KB/library/pdftoimages.aspx Convert PDF pages to image files using the Solid Framework (dead link, the deleted document is available on Internet Archive)
  • http://www.print-driver.com/howto/convert_pdf_to_jpeg.html Universal Document Converter
  • http://www.makeuseof.com/tag/6-ways-to-convert-a-pdf-file-to-a-jpg-image/ 6 Ways To Convert A PDF To A JPG Image

你也可以看看在这个主题:
如何从C#中的pictureBox中的pdf文件打开页面

And you also can take a look at this thread: how to open a page from a pdf file in pictureBox in C#

如果您使用这个过程将PDF转换为tiff ,你可以使用这个类从tiff中检索位图。

If you use this process to convert a PDF to tiff, you can use this class to retrieve the bitmap from tiff.

public class TiffImage
{
    private string myPath;
    private Guid myGuid;
    private FrameDimension myDimension;
    public ArrayList myImages = new ArrayList();
    private int myPageCount;
    private Bitmap myBMP;

    public TiffImage(string path)
    {
        MemoryStream ms;
        Image myImage;

        myPath = path;
        FileStream fs = new FileStream(myPath, FileMode.Open);
        myImage = Image.FromStream(fs);
        myGuid = myImage.FrameDimensionsList[0];
        myDimension = new FrameDimension(myGuid);
        myPageCount = myImage.GetFrameCount(myDimension);
        for (int i = 0; i < myPageCount; i++)
        {
            ms = new MemoryStream();
            myImage.SelectActiveFrame(myDimension, i);
            myImage.Save(ms, ImageFormat.Bmp);
            myBMP = new Bitmap(ms);
            myImages.Add(myBMP);
            ms.Close();
        }
        fs.Close();
    }
}

使用它如下:

private void button1_Click(object sender, EventArgs e)
{
    TiffImage myTiff = new TiffImage("D:\\Some.tif");
    //imageBox is a PictureBox control, and the [] operators pass back
    //the Bitmap stored at that position in the myImages ArrayList in the TiffImage
    this.pictureBox1.Image = (Bitmap)myTiff.myImages[0];
    this.pictureBox2.Image = (Bitmap)myTiff.myImages[1];
    this.pictureBox3.Image = (Bitmap)myTiff.myImages[2];
}

这篇关于如何将pdf文件转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆