資源簡介
使用Aspose組件文檔轉(zhuǎn)圖片
Console.WriteLine("========文件轉(zhuǎn)圖片開始========");
try
{
ArrayList alist = new ArrayList();
alist.Add("temp_pdf.pdf");
alist.Add("temp_ppt.ppt");
alist.Add("temp_pptx.pptx");
alist.Add("temp_doc.doc");
alist.Add("temp_docx.docx");
alist.Add("temp_xls.xls");
alist.Add("temp_xlsx.xlsx");
for (int i = 0; i < alist.Count; i++)
{
try
{
string pdfFilePath = alist[i].ToString();
FileInfo pdfFi = new FileInfo(pdfFilePath);
string filepath = pdfFi.FullName;
Console.WriteLine("正在轉(zhuǎn)換" + pdfFilePath + "文件...");
AsposeFileToImg.FileToImg(filepath);
}
catch (Exception)
{
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("========文件轉(zhuǎn)圖片結(jié)束========");
Console.Read();
}
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.IO;
using?System.Drawing;
using?System.Drawing.Imaging;
using?System.Reflection;
using?System.Threading;
using?System.Drawing;
using?System.Runtime.InteropServices;
using?System.Diagnostics;
using?Aspose.Cells;
namespace?PdfOrImg
{
????///?
????///?功能:
????///?pdfdocdocxpptpptxxlsxlsx文件轉(zhuǎn)圖片
????///?在當前文件下創(chuàng)建一個以文件名命名的文件夾,該文件夾的保存的是該文件生成是頁圖片
????///?
????public?class?AsposeFileToImg
????{
????????private?static?string?imageDirectoryPath?=?““;
????????public?static?void?FileToImg(string?filePath)
????????{
????????????if?(File.Exists(filePath))
????????????{
????????????????FileInfo?pdfFi?=?new?FileInfo(filePath);
????????????????string?filename?=?pdfFi.Name.Replace(pdfFi.Extension?““);
????????????????imageDirectoryPath?=?System.IO.Path.Combine(pdfFi.DirectoryName?filename);
????????????????if?(!Directory.Exists(imageDirectoryPath))
????????????????{
????????????????????Directory.CreateDirectory(imageDirectoryPath);
????????????????}
????????????????string?a?=?Path.GetExtension(filePath).ToLower();
????????????????if?(a?==?“.pdf“)
????????????????{
????????????????????PdfToImg(filePath);
????????????????}
????????????????else
????????????????{
????????????????????if?(a?==?“.doc“?||?a?==?“.docx“)
????????????????????{
????????????????????????DocToImg(filePath);
????????????????????}
????????????????????else
????????????????????{
????????????????????????if?(a?==?“.ppt“)
????????????????????????{
????????????????????????????PptToImg(filePath);
????????????????????????}
????????????????????????else?if?(a?==?“.pptx“)
????????????????????????{
????????????????????????????PptxToImg(filePath);
????????????????????????}
????????????????????????else
????????????????????????{
????????????????????????????if?(a?==?“.xls“?||?a?==?“.xlsx“)
????????????????????????????{
????????????????????????????????XlsToImg(filePath);
????????????????????????????}
????????????????????????}
????????????????????}
????????????????}
????????????}
????????}
????????private?static?void?PdfToImg(string?filePath)
????????{
????????????string?filename?=?Path.GetFileNameWithoutExtension(filePath).ToLower();
????????????FileStream?docStream?=?new?FileStream(filePath?FileMode.Open);
????????????var?pdf?=?new?Aspose.Pdf.Document(docStream);
????????????for?(int?i?=?1;?i?????????????{
????????????????try
????????????????{
????????????????????string?imgpath?=?imageDirectoryPath?+?“/“?+?filename?+?“_“?+?i?+?“.jpg“;
????????????????????if?(!File.Exists(imgpath))
????????????????????{
????????????????????????using?(FileStream?imageStream?=?new?FileStream(imgpath?FileMode.Create))
????????????????????????{
????????????????????????????Aspose.Pdf.Devices.Resolution?resolution?=?new?Aspose.Pdf.Devices.Resolution(300);
????????????????????????????Aspose.Pdf.Devices.Jpe
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\
?????目錄???????????0??2015-09-19?23:18??PdfOrImg\PdfOrImg\
?????文件??????474018??2015-08-27?16:39??PdfOrImg\PdfOrImg\Aspose.Words.idl
?????文件????????6702??2015-08-28?15:35??PdfOrImg\PdfOrImg\AsposeFileToImg.cs
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\PdfOrImg\Lib\
?????文件?????7397888??2014-02-16?22:08??PdfOrImg\PdfOrImg\Lib\Aspose.Cells.dll
?????文件?????1543317??2014-02-13?20:04??PdfOrImg\PdfOrImg\Lib\Aspose.Cells.xm
?????文件????28915200??2014-02-16?22:23??PdfOrImg\PdfOrImg\Lib\Aspose.Pdf.dll
?????文件?????1998911??2014-02-07?00:41??PdfOrImg\PdfOrImg\Lib\Aspose.Pdf.xm
?????文件????21656576??2014-02-16?22:25??PdfOrImg\PdfOrImg\Lib\Aspose.Slides.dll
?????文件?????1360054??2014-01-28?13:45??PdfOrImg\PdfOrImg\Lib\Aspose.Slides.xm
?????文件?????6597120??2012-02-01?13:35??PdfOrImg\PdfOrImg\Lib\Aspose.Words.dll
?????文件??????474018??2012-02-20?16:46??PdfOrImg\PdfOrImg\Lib\Aspose.Words.idl
?????文件??????322948??2012-02-20?16:46??PdfOrImg\PdfOrImg\Lib\Aspose.Words.tlb
?????文件??????745347??2012-02-20?16:47??PdfOrImg\PdfOrImg\Lib\Aspose.Words.xm
?????文件????????5743??2015-08-28?15:18??PdfOrImg\PdfOrImg\PdfOrImg.csproj
?????文件?????????523??2015-08-28?15:18??PdfOrImg\PdfOrImg\PdfOrImg.csproj.user
?????文件????????1759??2015-08-28?15:26??PdfOrImg\PdfOrImg\Program.cs
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\PdfOrImg\Properties\
?????文件????????1348??2015-08-25?10:09??PdfOrImg\PdfOrImg\Properties\AssemblyInfo.cs
?????文件?????????144??2015-08-25?10:58??PdfOrImg\PdfOrImg\app.config
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\PdfOrImg\bin\
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\PdfOrImg\bin\Debug\
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\PdfOrImg\bin\Debug\temp_docx\
?????文件???????48473??2015-08-28?15:30??PdfOrImg\PdfOrImg\bin\Debug\temp_docx\temp_docx_1.jpg
?????文件???????48443??2015-08-28?15:30??PdfOrImg\PdfOrImg\bin\Debug\temp_docx\temp_docx_2.jpg
?????文件???????11595??2015-08-28?12:12??PdfOrImg\PdfOrImg\bin\Debug\temp_docx.docx
?????文件?????????866??2015-08-25?10:10??PdfOrImg\PdfOrImg.sln
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\PdfOrImg\obj\
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\PdfOrImg\obj\x86\
?????目錄???????????0??2015-09-03?00:52??PdfOrImg\PdfOrImg\obj\x86\Debug\
............此處省略15個文件信息
- 上一篇:ASP網(wǎng)頁教程視頻類
- 下一篇:VESTA-win64.zip
評論
共有 條評論