-
大小: 9KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-05-09
- 語言: C#
- 標(biāo)簽: pdf轉(zhuǎn)圖片??
資源簡(jiǎn)介
采用Adobe Acrobat9.0的COM組件,將Pdf文件的每一頁轉(zhuǎn)換成對(duì)應(yīng)的圖片文件

代碼片段和文件信息
using?System;
using?System.Linq;
using?System.Configuration;
using?System.Drawing;
using?System.IO;
using?System.Runtime.InteropServices;
using?System.Windows.Forms;
using?System.Drawing.Imaging;
using?System.Diagnostics;
namespace?Pdf2Image?{
????public?class?Program?{
????????
????????[STAThread]
????????public?static?void?Main(string[]?args)?{
????????????//args.ToList().ForEach(p?=>?Console.WriteLine(p));
????????????//return;
????????????if?(args.Length?!=?1)?{
????????????????Console.WriteLine(“命令行格式:Pdf2Image?“);
????????????????return;
????????????}
????????????string?pdfFilePath?=?args[0];
????????????if(!System.IO.File.Exists(pdfFilePath))
????????????{
????????????????Console.WriteLine(“文件\“{0}\“不存在“?pdfFilePath);
????????????????return;
????????????}
????????????FileInfo?pdfFi?=?new?FileInfo(pdfFilePath);
????????????pdfFilePath?=?pdfFi.FullName;
????????????string?imageDirectoryPath?=?System.IO.Path.Combine(
????????????????pdfFi.DirectoryName?
????????????????pdfFi.Name.Replace(pdfFi.Extension““));
????????????try?{
????????????????ConvertPdf2Image(pdfFilePath?imageDirectoryPath?0?0?null?1);
????????????}
????????????catch?(Exception?ex)?{
????????????????Console.WriteLine(ex.ToString());
????????????}
????????????Console.Read();
????????}
????????public?static?void?ConvertPdf2Image(string?pdfFilePath?string?imageDirectoryPath
????????????int?beginPageNum?int?endPageNum?ImageFormat?format?double?zoom?=?1)?{
????????????Acrobat.CAcroPDDoc?pdfDoc?=?null;
????????????Acrobat.CAcroPDPage?pdfPage?=?null;
????????????Acrobat.CAcroRect?pdfRect?=?null;
????????????Acrobat.CAcroPoint?pdfPoint?=?null;
????????????//生成操作Pdf文件的Com對(duì)象
????????????pdfDoc?=?(Acrobat.CAcroPDDoc)Microsoft.VisualBasic.Interaction.Createobject(“AcroExch.PDDoc“?““);
????????????//檢查輸入?yún)?shù)
????????????if?(!pdfDoc.Open(pdfFilePath))?{
????????????????throw?new?FileNotFoundException(string.Format(“源文件{0}不存在!“?pdfFilePath));
????????????}
????????????if?(!Directory.Exists(imageDirectoryPath))?{
????????????????Directory.CreateDirectory(imageDirectoryPath);
????????????}
????????????if?(beginPageNum?<=?0)?{
????????????????beginPageNum?=?1;
????????????}
????????????if?(endPageNum?>?pdfDoc.GetNumPages()?||?endPageNum?<=?0)?{
????????????????endPageNum?=?pdfDoc.GetNumPages();
????????????}
????????????if?(beginPageNum?>?endPageNum)?{
????????????????throw?new?ArgumentException(“參數(shù)\“beginPageNum\“必須小于\“endPageNum\“!“);
????????????}
????????????if?(format?==?null)?{
????????????????format?=?ImageFormat.Png;
????????????}
????????????if?(zoom?<=?0)?{
????????????????zoom?=?1;
????????????}
????????????//轉(zhuǎn)換
????????????for?(int?i?=?beginPageNum;?i?<=?endPageNum;?i++)?{
????????????????//取出當(dāng)前頁
????????????????pdfPage?=?(Acrobat.CAcroPDPage)pdfDoc.AcquirePage(i?-?1);
????????????????//得到當(dāng)前頁的大小
????????????????pdfPoint?=?(Acrobat.CAcroPoint)pdfPa
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????907??2012-04-08?23:21??Pdf2ImageWithAcrobat\Acrobat.pdf2image.sln
????..A..H.?????20480??2012-04-08?23:49??Pdf2ImageWithAcrobat\Acrobat.pdf2image.suo
?????文件????????144??2012-04-08?19:09??Pdf2ImageWithAcrobat\app.config
?????文件???????4815??2012-04-08?23:48??Pdf2ImageWithAcrobat\Pdf2Image.csproj
?????文件????????599??2012-04-08?23:33??Pdf2ImageWithAcrobat\Pdf2Image.csproj.user
?????文件???????4853??2012-04-08?23:43??Pdf2ImageWithAcrobat\Program.cs
?????文件???????1349??2012-04-08?23:21??Pdf2ImageWithAcrobat\Properties\AssemblyInfo.cs
?????目錄??????????0??2012-04-08?23:50??Pdf2ImageWithAcrobat\Properties
?????目錄??????????0??2012-04-08?23:50??Pdf2ImageWithAcrobat
-----------?---------??----------?-----??----
????????????????33147????????????????????9
評(píng)論
共有 條評(píng)論