返回首页


{S0}简介
这篇文章是关于从PDF文件中提取图像文件。我一直在寻找一个免费的解决方案转换为PDF文件,图像文件,但我没有找到一个简单和免费的解决方案。因此,我想,直到我发现一个免费的解决方案使用的quot;的Adobe Acrobat COM componentquot;和使用的CAcroPDDoc类。先决条件
你必须有"使用Adobe Acrobat Readerquot,您的系统上安装。我的系统已安装的Adobe Acrobat 9.0。使用的代码和说明
首先,我添加的Adobe Acrobat COM组件的引用。

然后我写了PDFConvertor类,名为转换成(....)一个方法,该方法转换。这里是我的类中的代码用于访问PDF文档:

Acrobat.CAcroPDPage pdfPage = null;//the pdf page

Acrobat.CAcroRect pdfRect = new Acrobat.AcroRect();//the pdf region

Acrobat.AcroPoint pdfPoint =new Acrobat.AcroPoint();//the pdf point
CAcroPDDoc类是为PDF文件CAcroPDPage类是在PDF文件中的页面CAcroRect和AcroPoint类是定义页面的尺寸
这里是我打开一个PDF文档:{C}
打开一个指定的PDF文件,我使用的pdfDoc对象的open()方法,它在一个错误的情况下返回false。
pageCount = pdfDoc.GetNumPages();//get the count of pdf pages

pdfDoc.GetNumPages()读取的页数后,我再读取页面。
pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i); //reading current page

然后,我使用pdfDoc.AcquirePage在PDF文件中提取一个网页(i)和它分配的pdfPage对象;变量i表示当前页码。
然后,我得到pdfPage.GetSize(页大小),并把它成一个pdfPoint对象。这是必需的指定区域复制到剪贴板页PDF页面。
pdfPage.CopyToClipboard(pdfRect, 0, 0, 100);//coping region to clipboard

确保pdfPage没有任何方法保存为引用的页面。 pdfPage.CopyToClipboard(pdfRect,0,0,100),可以帮助我们。它有四个参数:第一个是以前讨论页面RECT,第二个和第三个是x,y偏移的页面通常是0,四是变焦%。
Clipboard.GetImage().Save(outimg, outPutImageFormat);// saving clipboard image

最后,Clipboard.GetImage()。保存(...),我们可以节省输出的图像。
这里是我的类的转换方法的代码:
#region Convert

/// 

/// Converting PDF Files TO Specified Image Format

/// 

/// sourceFileName : Source PDF File Path

/// DestinationPath : Destination PDF File Path

/// outPutImageFormat: Type Of Exported Image

/// Returns Count Of Exported Images

public int Convert(string sourceFileName, 

       string DestinationPath, ImageFormat outPutImageFormat)

{

    if (pdfDoc.Open(sourceFileName))

    {

        // pdfapp.Hide();

        pageCount = pdfDoc.GetNumPages();



        for (int i = 0; i < pageCount; i++)

        {

            pdfPage = (Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i);



            pdfPoint = (Acrobat.AcroPoint)pdfPage.GetSize();

            pdfRect.Left = 0;

            pdfRect.right = pdfPoint.x;

            pdfRect.Top = 0;

            pdfRect.bottom = pdfPoint.y;



            pdfPage.CopyToClipboard(pdfRect, 500, 110, 100);



            string outimg = "";

            string filename=sourceFileName.Substring(

                       sourceFileName.LastIndexOf("\\")); 



            if (pageCount == 1)

                outimg = DestinationPath + "\\" + filename + 

                  "." + outPutImageFormat.ToString();

            else

                outimg = DestinationPath + "\\" + filename + 

                  "_" + i.ToString() + "." + outPutImageFormat.ToString();

            

            Clipboard.GetImage().Save(outimg, outPutImageFormat);



            ////////////Firing Progress Event 

            OnExportProgressChanging(outimg);

        }



          Dispose();

    }

    else

    {

        Dispose();

        throw new System.IO.FileNotFoundException(sourceFileName + 

                  " Not Found!");

    }

    return pageCount;

}

#endregion

我也实施一类,说明事件的处理程序ProgressChangingEventHandler,在我的项目的源中存在的进展。
享受!

回答

评论会员:RubyPdf 时间:2012/01/25
安装Adobe Acrobat Reader不支持{A2}
评论会员:ScratchFish 时间:2012/01/25
您好,

在我看来,一个伟大的PDF和Acrobat库工作startingpoint。
我测试YOUT programm和Windows XP上,它工作得很好。但我的笔记本电脑与Windows 7,我得到了thise异常:"System.Runtime.InteropServices.ComException(0x80040154)"。你也许知道,问题出在哪里呢?

亲切的问候ScratchFish

p.s.
这些笔记本电脑上安装使用Acrobat Reader 9
评论会员:zendehdel 时间:2012/01/25
也许是因为Windows 7的安全设置,防止运行的COM组件,
尝试运行管理员权限
评论会员:ScratchFish 时间:2012/01/25
THX你的答复。我解决了这个问题。使用Adobe图书馆的,你要安装的Acrobat Pro
评论会员:。显微成像 时间:2012/01/25
我使用Visual Studio 2008,和Adobe Acrobat Reader 8.2.0我没有杂技演员的COM
我是否需要安装Adobe Acrobat Distiller来获得COM类
评论会员:?zendehdel 时间:2012/01/25
。只有6.0版以上的系统上安装的Acrobat Reader为你做这个有没有任何其他程序的需要{ BR}
评论会员:zendehdel 时间:2012/01/25
嘿家伙!让我们我
我初学代码项目
评论会员:戴夫Kreskowiak 时间:2012/01/25
我觉得别人说这一切... ...
评论会员:标记Nischalke 时间:2012/01/25
你有没有代码的讨论,也没有背后的概念{BR }