资源简介

项目需要进行PDF压缩,没有找到太好的方法。 但经调查,PDF的原文件为word,因此采用了比较偷懒的方式 把PDF转为word,再由word转为PDF PDF文件得以最大程度的压缩,并且保证了效果。 希望大家可以借鉴。 注:需要利用adobe专业版的组件PDFMakerAPI.dll 和 Acrobat.dll

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using Aspose.Words;
using Aspose.Pdf;
using System.IO;
using Acrobat;
using System.Reflection;
using PDFMAKERAPILib;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        public void Load1()
        {
           // object path;      //文件路径

           // string strContent;    //文本内容

           //// MSWord.Application wordApp;   //word应用程序

           //// MSWord.Document wordDoc;    //word文档

           // path = @“c:\test.docx“;

           // wordApp = new MSWord.ApplicationClass();

           // if (File.Exists(path.ToString()))
           // {

           //     File.Delete(path.ToString());

           // }

           // object nothing = Missing.Value;

           // wordDoc = wordApp.Documents.Add(ref nothing ref nothing ref nothing ref nothing);

           // strContent = pdf2txt(new FileInfo(@“C:\Documents and Settings\Administrator\桌面\临时文件\qiu\WebApplication1\WebApplication1\test.pdf“));

           // wordDoc.Paragraphs.Last.Range.Text = strContent;

           // object format = MSWord.WdSaveFormat.wdFormatDocumentDefault;

           // wordDoc.SaveAs(ref path ref format ref nothing ref nothing ref nothing ref nothing ref nothing

           //           ref nothing ref nothing ref nothing ref nothing ref nothing ref nothing

           //          ref nothing ref nothing ref nothing);

           // wordDoc.Close(ref nothing ref nothing ref nothing);

           // wordApp.Quit(ref nothing ref nothing ref nothing);

    
        }


        int int_Aspose = 1;
        public void Load2(string path_s  string path_d)//Aspose  word to pdf
        {

          
            //string path = @“F:\PDF Compress\Pdf to Word\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\17M.doc“;

            Aspose.Words.Document doc = new Aspose.Words.Document(path_s);
            Aspose.Words.DocumentBuilder builder = new DocumentBuilder(doc);


            string name = path_s.Substring(path_s.LastIndexOf(‘\\‘) path_s.LastIndexOf(‘.‘) - path_s.LastIndexOf(‘\\‘));
            doc.Save(path_d + @“\“ + name + @“_“ + int_Aspose.ToString()+ @“_(Aspose Word to Pdf).pdf“ SaveFormat.Pdf);
            int_Aspose++;
            //doc.Save(“17M load2 Word to Pdf.pdf“ SaveFormat.Pdf);
            
        }

        int int_office = 1;

        public void Load3(string path_s string path_d)//office word to pdf
        {
 
            
            Microsoft.Office.Interop.Word.Application newApp=new Microsoft.Office.Interop.Word.Application();
            
            /

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-07-30 16:05  WindowsFormsApplication1\
     文件        1041  2015-07-29 11:16  WindowsFormsApplication1.sln
     文件       40960  2015-07-30 16:28  WindowsFormsApplication1.v12.suo
     文件         184  2015-07-29 15:27  WindowsFormsApplication1\App.config
     目录           0  2015-07-30 11:27  WindowsFormsApplication1\bin\
     目录           0  2015-07-30 16:08  WindowsFormsApplication1\bin\Debug\
     文件     3214336  2012-02-20 16:45  WindowsFormsApplication1\bin\Debug\Aspose.Pdf.dll
     文件      497710  2012-02-20 16:47  WindowsFormsApplication1\bin\Debug\Aspose.Pdf.xml
     文件     6597120  2012-02-01 13:35  WindowsFormsApplication1\bin\Debug\Aspose.Words.dll
     文件      745347  2012-02-20 16:47  WindowsFormsApplication1\bin\Debug\Aspose.Words.xml
     文件       26112  2015-07-30 16:15  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe
     文件         184  2015-07-29 15:27  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe.config
     文件       44544  2015-07-30 16:15  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb
     文件       24224  2015-07-30 16:17  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe
     文件         184  2015-07-29 15:27  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.config
     文件         490  2010-03-17 22:39  WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe.manifest
     文件        3259  2015-07-29 12:05  WindowsFormsApplication1\bin\Debug\代码.txt
     目录           0  2015-07-30 11:27  WindowsFormsApplication1\bin\Release\
     文件     3214336  2012-02-20 16:45  WindowsFormsApplication1\bin\Release\Aspose.Pdf.dll
     文件      497710  2012-02-20 16:47  WindowsFormsApplication1\bin\Release\Aspose.Pdf.xml
     文件     6597120  2012-02-01 13:35  WindowsFormsApplication1\bin\Release\Aspose.Words.dll
     文件      745347  2012-02-20 16:47  WindowsFormsApplication1\bin\Release\Aspose.Words.xml
     文件       14848  2015-07-29 15:04  WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.exe
     文件         187  2015-07-29 11:16  WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.exe.config
     文件       22016  2015-07-29 15:04  WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.pdb
     文件       12596  2015-07-30 16:05  WindowsFormsApplication1\Form1.cs
     文件       16143  2015-07-30 16:01  WindowsFormsApplication1\Form1.Designer.cs
     文件        6642  2015-07-30 16:01  WindowsFormsApplication1\Form1.resx
     目录           0  2015-07-30 11:27  WindowsFormsApplication1\obj\
     目录           0  2015-07-30 16:15  WindowsFormsApplication1\obj\Debug\
     文件        1317  2015-07-30 15:28  WindowsFormsApplication1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此处省略41个文件信息

评论

共有 条评论