{S0}简介
这篇文章是关于从PDF文件中提取图像文件。我一直在寻找一个免费的解决方案转换为PDF文件,图像文件,但我没有找到一个简单和免费的解决方案。因此,我想,直到我发现一个免费的解决方案使用的quot;的Adobe Acrobat COM componentquot;和使用的CAcroPDDoc类。先决条件
你必须有"使用Adobe Acrobat Readerquot,您的系统上安装。我的系统已安装的Adobe Acrobat 9.0。使用的代码和说明
首先,我添加的Adobe Acrobat COM组件的引用。
然后我写了PDFConvertor类,名为转换成(....)一个方法,该方法转换。这里是我的类中的代码用于访问PDF文档:
CAcroPDDoc类是为PDF文件CAcroPDPage类是在PDF文件中的页面CAcroRect和AcroPoint类是定义页面的尺寸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
这里是我打开一个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,在我的项目的源中存在的进展。
享受!