• 大小: 23.45MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2023-07-03
  • 语言: ASP
  • 标签: Asposepdf  

资源简介

使用Aspose组件文档转图片 Console.WriteLine("========文件转图片开始========"); 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("正在转换" + pdfFilePath + "文件..."); AsposeFileToImg.FileToImg(filepath); } catch (Exception) { } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine("========文件转图片结束========"); 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文件转图片
    /// 在当前文件下创建一个以文件名命名的文件夹,该文件夹的保存的是该文件生成是页图片
    /// 

    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 < pdf.Pages.Count + 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.xml
     文件    28915200  2014-02-16 22:23  PdfOrImg\PdfOrImg\Lib\Aspose.Pdf.dll
     文件     1998911  2014-02-07 00:41  PdfOrImg\PdfOrImg\Lib\Aspose.Pdf.xml
     文件    21656576  2014-02-16 22:25  PdfOrImg\PdfOrImg\Lib\Aspose.Slides.dll
     文件     1360054  2014-01-28 13:45  PdfOrImg\PdfOrImg\Lib\Aspose.Slides.xml
     文件     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.xml
     文件        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个文件信息

评论

共有 条评论

相关资源