├── PdfComponent.Lib ├── Leadtools.Pdf.dll ├── packages.config ├── Interfaces │ └── IPdfComponentFunc.cs ├── Properties │ └── AssemblyInfo.cs ├── Components │ ├── SpirePdfComponent.cs │ ├── ITextPdfComponent.cs │ └── AsposePdfComponent.cs └── PdfComponent.Lib.csproj ├── PdfComponentDemo ├── DefaultResource │ ├── insertPage.jpeg │ └── waterMarkImg.jpeg ├── App.config ├── Properties │ ├── Settings.settings │ ├── AssemblyInfo.cs │ ├── Settings.Designer.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── packages.config ├── Program.cs ├── PdfComponentDemo.csproj ├── Form1.resx ├── Form1.cs └── Form1.Designer.cs ├── README.zh-cn.md ├── LICENSE ├── README.md ├── PdfComponentDemo.sln └── .gitignore /PdfComponent.Lib/Leadtools.Pdf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiningRush/PdfComponentComparison/HEAD/PdfComponent.Lib/Leadtools.Pdf.dll -------------------------------------------------------------------------------- /PdfComponentDemo/DefaultResource/insertPage.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiningRush/PdfComponentComparison/HEAD/PdfComponentDemo/DefaultResource/insertPage.jpeg -------------------------------------------------------------------------------- /PdfComponentDemo/DefaultResource/waterMarkImg.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ShiningRush/PdfComponentComparison/HEAD/PdfComponentDemo/DefaultResource/waterMarkImg.jpeg -------------------------------------------------------------------------------- /PdfComponentDemo/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PdfComponentDemo/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PdfComponent.Lib/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PdfComponent.Lib/Interfaces/IPdfComponentFunc.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PdfComponent.Lib.Interfaces 8 | { 9 | public interface IPdfComponentFunc 10 | { 11 | string ComponentName { get; } 12 | void ToJpeg(string absoluteFilePath, string outputPath); 13 | void ToTxt(string absoluteFilePath, string outputPath); 14 | void FromXps(string absoluteFilePath, string outputPath); 15 | void InsertPage(string absoluteFilePath, string outputPath); 16 | void AddWaterprint(string absoluteFilePath, string outputPath); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /PdfComponentDemo/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.zh-cn.md: -------------------------------------------------------------------------------- 1 | # PDF 类库比较 2 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ShiningRush/PdfComponentComparition/blob/master/LICENSE) 3 | 4 | 该Demo的目的是为了比较各个组件对Pdf文件支持功能的转化质量,性能以及语法简洁度做对比。同时大家也可以把该Demo作为一个组件使用方法的参考文档。 5 | 6 | ## 概述 7 | 8 | 该Demo目前只实现了几种类库(Aspose.Pdf, Spire.Pdf, iText7),其中包含一些商业组件,为什么不多选择一些开源免费的?其实功能最全的,都是收费了,而且开源中最有名的组件应该就属iTextSharp了吧。这里稍微解释一下,iText5是Java系里很有名的Pdf开源类库,而iTextSharp就是它的.Net版本,然后他们重写了iText5,为了拥有更简洁的语法和可修改性。所以我在开源类库中只选择了iText7作为一个研究对象。 9 | 10 | 不过本Demo的组件调用都采用了接口以达到良好的拓展性,有兴趣的同学可以自己拓展自己感兴趣的组件和想实现的功能。 11 | 12 | 只要实现 `IPdfComponentFunc` 接口,程序会自动将该实现加载到下拉列表。 13 | 14 | ## Demo用法简单介绍 15 | 16 | `UseComponent` 这个下拉列表用来选择用于转换的组件 17 | 18 | `InputFileDir` 选择你需要转换的文件所在文件夹,请注意是所在文件夹,而且不是文件 19 | 20 | `OutputFIleDir` 选择你操作后要输出的文件夹路径 21 | 22 | `ExecuteTimes` 执行次数,用于性能对比时使用,为空默认执行1次 23 | 24 | 下面几个按钮应该相当容易懂了,这里只解释一下 `AllRun` 按钮就是说将所有功能都跑一遍。 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 King Xu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PdfComponent.Lib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("PdfComponent.Lib")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("PdfComponent.Lib")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("350bdc4c-e9a8-40ea-bb10-5177df48299f")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /PdfComponentDemo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("PdfComponentDemo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("PdfComponentDemo")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("4da5e430-37ad-4d6e-9c53-6227853558fc")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /PdfComponentDemo/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace PdfComponentDemo.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PdfComponentComparition 2 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ShiningRush/PdfComponentComparition/blob/master/LICENSE) 3 | 4 | [中文介绍请点击这里](https://github.com/ShiningRush/PdfComponentComparition/blob/master/README.zh-cn.md) 5 | 6 | The repository is used for comparing different pdf handle component such as Aspose.Pdf , Spire.Pdf and iText so on,you also can consider it as a demo repository that show how to use those component. 7 | 8 | ## Summary 9 | 10 | This Demo was just implemented some library(Aspose.Pdf, Spire.Pdf, iText7), some of those is commercial component.Some people maybe asked why not to choose more open-source librabry.However the most features libraries are almost charged and the most popular open-source library is iTextSharp(iText7 is its rafactor version),so i think only choosing this one is enough. 11 | 12 | Even this demo was just implement three components,but the project is designed loosely coupled, you can realize you need component easily by implement `IPdfComponentFunc` interface, and application will add it to component's dropdownlist automatically. 13 | 14 | ## Simple Usage Of Demo 15 | 16 | `UseComponent` this list is used for selecting component 17 | 18 | `InputFileDir` select the files located directory(not path) which you need to handle 19 | 20 | `OutputFIleDir` select the directory you hope to output result 21 | 22 | `ExecuteTimes` this is used for testing component's performance, meant excute times in total. 23 | 24 | i think the blow button is easy to understand, just explain the button `AllRun` is meant excute all action. 25 | -------------------------------------------------------------------------------- /PdfComponentDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace PdfComponentDemo 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | //设置应用程序处理异常方式:ThreadException处理 18 | Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); 19 | //处理UI线程异常 20 | Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); 21 | //处理非UI线程异常 22 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 23 | 24 | Application.EnableVisualStyles(); 25 | Application.SetCompatibleTextRenderingDefault(false); 26 | Application.Run(new Form1()); 27 | } 28 | 29 | static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) 30 | { 31 | string errMsg = "执行过程中发生意料外的错误"; 32 | if (e.Exception is NotImplementedException) 33 | errMsg = "该组件不支持这样的操作"; 34 | 35 | MessageBox.Show(errMsg, "发生错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 36 | } 37 | 38 | static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) 39 | { 40 | MessageBox.Show("执行过程中发生意料外的错误", "发生错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /PdfComponentDemo/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace PdfComponentDemo.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PdfComponentDemo.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 覆盖当前线程的 CurrentUICulture 属性 56 | /// 使用此强类型的资源类的资源查找。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /PdfComponentDemo.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.8 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfComponent.Lib", "PdfComponent.Lib\PdfComponent.Lib.csproj", "{350BDC4C-E9A8-40EA-BB10-5177DF48299F}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PdfComponentDemo", "PdfComponentDemo\PdfComponentDemo.csproj", "{4DA5E430-37AD-4D6E-9C53-6227853558FC}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Debug|x64.ActiveCfg = Debug|Any CPU 23 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Debug|x64.Build.0 = Debug|Any CPU 24 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Debug|x86.ActiveCfg = Debug|Any CPU 25 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Debug|x86.Build.0 = Debug|Any CPU 26 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Release|x64.ActiveCfg = Release|Any CPU 29 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Release|x64.Build.0 = Release|Any CPU 30 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Release|x86.ActiveCfg = Release|Any CPU 31 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F}.Release|x86.Build.0 = Release|Any CPU 32 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Debug|x64.Build.0 = Debug|Any CPU 36 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Debug|x86.Build.0 = Debug|Any CPU 38 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Release|x64.ActiveCfg = Release|Any CPU 41 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Release|x64.Build.0 = Release|Any CPU 42 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Release|x86.ActiveCfg = Release|Any CPU 43 | {4DA5E430-37AD-4D6E-9C53-6227853558FC}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {2BF8A6CA-9CCF-42FB-8CC9-6780700ADE07} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /PdfComponent.Lib/Components/SpirePdfComponent.cs: -------------------------------------------------------------------------------- 1 | using PdfComponent.Lib.Interfaces; 2 | using Spire.Pdf; 3 | using Spire.Pdf.Graphics; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Drawing; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace PdfComponent.Lib.Components 13 | { 14 | public class SpirePdfComponent : IPdfComponentFunc 15 | { 16 | public string ComponentName => "Spire.Pdf"; 17 | 18 | public void AddWaterprint(string absoluteFilePath, string outputPath) 19 | { 20 | var watermarkImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "DefaultResource", "waterMarkImg.jpeg"); 21 | using (PdfDocument doc = new PdfDocument(absoluteFilePath)) 22 | using (var watermarkImg = Image.FromFile(watermarkImgPath)) 23 | { 24 | foreach (PdfPageBase aPdfPage in doc.Pages) 25 | { 26 | aPdfPage.BackgroundRegion = new RectangleF(300, 200, 80, 81); 27 | aPdfPage.BackgroundImage = watermarkImg; 28 | } 29 | 30 | doc.SaveToFile(outputPath); 31 | } 32 | } 33 | 34 | public void FromXps(string absoluteFilePath, string outputPath) 35 | { 36 | //open xps document 37 | using (PdfDocument doc = new PdfDocument()) 38 | { 39 | doc.LoadFromXPS(absoluteFilePath); 40 | //convert to pdf file. 41 | doc.SaveToFile(outputPath); 42 | } 43 | } 44 | 45 | public void InsertPage(string absoluteFilePath, string outputPath) 46 | { 47 | var insertPageImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "DefaultResource", "insertPage.jpeg"); 48 | //open xps document 49 | using (PdfDocument doc = new PdfDocument(absoluteFilePath)) 50 | { 51 | var insertPagekImg = PdfImage.FromFile(insertPageImgPath); 52 | var insertedPage = doc.Pages.Insert(1); 53 | float widthFitRate = insertPagekImg.PhysicalDimension.Width / insertedPage.Canvas.ClientSize.Width; 54 | float heightFitRate = insertPagekImg.PhysicalDimension.Height / insertedPage.Canvas.ClientSize.Height; 55 | float fitRate = Math.Max(widthFitRate, heightFitRate); 56 | float fitWidth = insertPagekImg.PhysicalDimension.Width / fitRate; 57 | float fitHeight = insertPagekImg.PhysicalDimension.Height / fitRate; 58 | insertedPage.Canvas.DrawImage(insertPagekImg, 30, 30, fitWidth, fitHeight); 59 | 60 | 61 | //convert to pdf file. 62 | doc.SaveToFile(outputPath); 63 | } 64 | } 65 | 66 | public void ToJpeg(string absoluteFilePath, string outputPath) 67 | { 68 | //open xps document 69 | using (PdfDocument doc = new PdfDocument(absoluteFilePath)) 70 | { 71 | //convert to pdf file. 72 | for (var i = 0; i < doc.Pages.Count; i++) 73 | { 74 | using (var img = doc.SaveAsImage(i)) 75 | { 76 | img.Save(Path.Combine(outputPath, i.ToString() + ".jpeg")); 77 | } 78 | } 79 | } 80 | } 81 | 82 | public void ToTxt(string absoluteFilePath, string outputPath) 83 | { 84 | using (PdfDocument doc = new PdfDocument(absoluteFilePath)) 85 | { 86 | var stringBuilder = new StringBuilder(); 87 | foreach (PdfPageBase aPdfPage in doc.Pages) 88 | { 89 | stringBuilder.Append(aPdfPage.ExtractText()); 90 | } 91 | 92 | File.WriteAllText(outputPath, stringBuilder.ToString()); 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /PdfComponent.Lib/Components/ITextPdfComponent.cs: -------------------------------------------------------------------------------- 1 | using iText.IO.Image; 2 | using iText.Kernel.Pdf; 3 | using iText.Kernel.Pdf.Canvas; 4 | using iText.Kernel.Pdf.Extgstate; 5 | using iText.Kernel.Geom; 6 | using PdfComponent.Lib.Interfaces; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | using iText.Kernel.Pdf.Canvas.Parser.Listener; 13 | using iText.Kernel.Pdf.Canvas.Parser; 14 | 15 | namespace PdfComponent.Lib.Components 16 | { 17 | public class ITextPdfComponent : IPdfComponentFunc 18 | { 19 | public string ComponentName => "iText7"; 20 | 21 | public void AddWaterprint(string absoluteFilePath, string outputPath) 22 | { 23 | var watermarkImgPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "DefaultResource", "waterMarkImg.jpeg"); 24 | using (var pdfDocument = new PdfDocument(new PdfReader(absoluteFilePath), new PdfWriter(outputPath))) 25 | { 26 | // image watermark 27 | ImageData img = ImageDataFactory.Create(watermarkImgPath); 28 | 29 | // transparency 30 | var gs1 = new PdfExtGState(); 31 | gs1.SetFillOpacity(0.3f); 32 | for (var pageIndex = 1; pageIndex < pdfDocument.GetNumberOfPages(); pageIndex++) 33 | { 34 | // properties 35 | PdfCanvas over = new PdfCanvas(pdfDocument.GetPage(pageIndex)); 36 | Rectangle pagesize = pdfDocument.GetPage(pageIndex).GetPageSize(); 37 | over.SaveState(); 38 | over.SetExtGState(gs1); 39 | over.AddImage(img, 80, 0, 0, 81, 300, (pagesize.GetTop() + pagesize.GetBottom()) - 200, true); 40 | over.RestoreState(); 41 | } 42 | } 43 | } 44 | 45 | public void FromXps(string absoluteFilePath, string outputPath) 46 | { 47 | throw new NotImplementedException(); 48 | } 49 | 50 | public void InsertPage(string absoluteFilePath, string outputPath) 51 | { 52 | var insertPageImgPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "DefaultResource", "insertPage.jpeg"); 53 | using (var pdfDocument = new PdfDocument(new PdfReader(absoluteFilePath), new PdfWriter(outputPath))) 54 | { 55 | var newPage = pdfDocument.AddNewPage(2); 56 | var newPageCanvas = new PdfCanvas(newPage); 57 | newPageCanvas.SaveState(); 58 | var imageData = ImageDataFactory.Create(insertPageImgPath); 59 | newPageCanvas.AddImage(imageData, imageData.GetWidth(), 0, 0, imageData.GetHeight(), 0, 0, true); 60 | newPageCanvas.RestoreState(); 61 | } 62 | } 63 | 64 | public void ToJpeg(string absoluteFilePath, string outputPath) 65 | { 66 | throw new NotImplementedException(); 67 | } 68 | 69 | public void ToTxt(string absoluteFilePath, string outputPath) 70 | { 71 | using (var pdfDocument = new PdfDocument(new PdfReader(absoluteFilePath))) 72 | { 73 | for (var pageIndex = 1; pageIndex <= pdfDocument.GetNumberOfPages(); pageIndex++) 74 | { 75 | using (var fos = System.IO.File.OpenWrite(outputPath)) 76 | { 77 | var strategy = new LocationTextExtractionStrategy(); 78 | var parser = new PdfCanvasProcessor(strategy); 79 | parser.ProcessPageContent(pdfDocument.GetPage(pageIndex)); 80 | var array = Encoding.UTF8.GetBytes(strategy.GetResultantText()); 81 | fos.Write(array, 0, array.Length); 82 | 83 | fos.Flush(); 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /PdfComponent.Lib/PdfComponent.Lib.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {350BDC4C-E9A8-40EA-BB10-5177DF48299F} 8 | Library 9 | Properties 10 | PdfComponent.Lib 11 | PdfComponent.Lib 12 | v4.5.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\Aspose.Pdf.17.9\lib\net40-client\Aspose.Pdf.dll 35 | 36 | 37 | ..\packages\itext7.7.0.4\lib\net40\itext.barcodes.dll 38 | 39 | 40 | ..\packages\itext7.7.0.4\lib\net40\itext.forms.dll 41 | 42 | 43 | ..\packages\itext7.7.0.4\lib\net40\itext.io.dll 44 | 45 | 46 | ..\packages\itext7.7.0.4\lib\net40\itext.kernel.dll 47 | 48 | 49 | ..\packages\itext7.7.0.4\lib\net40\itext.layout.dll 50 | 51 | 52 | ..\packages\itext7.7.0.4\lib\net40\itext.pdfa.dll 53 | 54 | 55 | ..\packages\itext7.7.0.4\lib\net40\itext.sign.dll 56 | 57 | 58 | ..\packages\Spire.PDF.3.9.462\lib\net40\Spire.License.dll 59 | 60 | 61 | ..\packages\Spire.PDF.3.9.462\lib\net40\Spire.Pdf.dll 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /PdfComponentDemo/PdfComponentDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {4DA5E430-37AD-4D6E-9C53-6227853558FC} 8 | WinExe 9 | PdfComponentDemo 10 | PdfComponentDemo 11 | v4.5.2 12 | 512 13 | true 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | ..\packages\Yiban.CoreService.Client.1.0.4.0\lib\net40\Yiban.CoreService.Client.dll 51 | 52 | 53 | 54 | 55 | Form 56 | 57 | 58 | Form1.cs 59 | 60 | 61 | 62 | 63 | Form1.cs 64 | 65 | 66 | ResXFileCodeGenerator 67 | Resources.Designer.cs 68 | Designer 69 | 70 | 71 | True 72 | Resources.resx 73 | 74 | 75 | 76 | SettingsSingleFileGenerator 77 | Settings.Designer.cs 78 | 79 | 80 | True 81 | Settings.settings 82 | True 83 | 84 | 85 | 86 | 87 | Designer 88 | 89 | 90 | 91 | 92 | {350bdc4c-e9a8-40ea-bb10-5177df48299f} 93 | PdfComponent.Lib 94 | 95 | 96 | 97 | 98 | Always 99 | 100 | 101 | Always 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /PdfComponent.Lib/Components/AsposePdfComponent.cs: -------------------------------------------------------------------------------- 1 | using Aspose.Pdf; 2 | using Aspose.Pdf.Devices; 3 | using Aspose.Pdf.Text; 4 | using PdfComponent.Lib.Interfaces; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | 12 | namespace PdfComponent.Lib.Components 13 | { 14 | public class AsposePdfComponent : IPdfComponentFunc 15 | { 16 | public string ComponentName => "Aspose.Pdf"; 17 | 18 | private const string Key = "PExpY2Vuc2U+DQogIDxEYXRhPg0KICAgIDxMaWNlbnNlZFRvPlNoYW5naGFpIEh1ZHVuIEluZm9ybWF0aW9uIFRlY2hub2xvZ3kgQ28uLCBMdGQ8L0xpY2Vuc2VkVG8+DQogICAgPEVtYWlsVG8+MzE3NzAxODA5QHFxLmNvbTwvRW1haWxUbz4NCiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+DQogICAgPExpY2Vuc2VOb3RlPkxpbWl0ZWQgdG8gMSBkZXZlbG9wZXIsIHVubGltaXRlZCBwaHlzaWNhbCBsb2NhdGlvbnM8L0xpY2Vuc2VOb3RlPg0KICAgIDxPcmRlcklEPjE2MDkwMjAwNDQwMDwvT3JkZXJJRD4NCiAgICA8VXNlcklEPjI2NjE2NjwvVXNlcklEPg0KICAgIDxPRU0+VGhpcyBpcyBhIHJlZGlzdHJpYnV0YWJsZSBsaWNlbnNlPC9PRU0+DQogICAgPFByb2R1Y3RzPg0KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0Pg0KICAgIDwvUHJvZHVjdHM+DQogICAgPEVkaXRpb25UeXBlPkVudGVycHJpc2U8L0VkaXRpb25UeXBlPg0KICAgIDxTZXJpYWxOdW1iZXI+NzM4MDNhYmUtYzZkMi00MTY3LTg2MTgtN2I0NDViNDRmOGY0PC9TZXJpYWxOdW1iZXI+DQogICAgPFN1YnNjcmlwdGlvbkV4cGlyeT4yMDE3MDkwNzwvU3Vic2NyaXB0aW9uRXhwaXJ5Pg0KICAgIDxMaWNlbnNlVmVyc2lvbj4zLjA8L0xpY2Vuc2VWZXJzaW9uPg0KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHA6Ly93d3cuYXNwb3NlLmNvbS9jb3Jwb3JhdGUvcHVyY2hhc2UvbGljZW5zZS1pbnN0cnVjdGlvbnMuYXNweDwvTGljZW5zZUluc3RydWN0aW9ucz4NCiAgPC9EYXRhPg0KICA8U2lnbmF0dXJlPm5LNVVUR3dZMWVJSEtIV0d2NW5sQUxXUy81bDEzWkFuamlvdnlBcGNqQis0ZjNGbm5yOWhjeUlzazlvVzQySWp0ZFYra2JHZlNSMUV4OUozSGlkaThCeE43aHFiR1BERXNaWGo2RlYxaGl1N2MxWmUyNEp3VGc2UnpsNUNJRHY1YVhxbDQyczBkSGw4eXpreDRBM2RTTU5KTzRiQ094a2V2OFBiOWxSaUc3ST08L1NpZ25hdHVyZT4NCjwvTGljZW5zZT4="; 19 | private static Stream LStream = (Stream)new MemoryStream(Convert.FromBase64String(Key)); 20 | public AsposePdfComponent() 21 | { 22 | SetPdfLicense(); 23 | } 24 | 25 | public void SetPdfLicense() 26 | { 27 | var l = new Aspose.Pdf.License(); 28 | //l.SetLicense(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.lic")); 29 | l.SetLicense(LStream); 30 | } 31 | 32 | 33 | public void AddWaterprint(string absoluteFilePath, string outputPath) 34 | { 35 | var watermarkImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DefaultResource", "waterMarkImg.jpeg"); 36 | using (var pdfDocument = new Document(absoluteFilePath)) 37 | using (BackgroundArtifact background = new BackgroundArtifact()) 38 | { 39 | foreach (Page aPdfPage in pdfDocument.Pages) 40 | { 41 | ImageStamp imageStamp = new ImageStamp(watermarkImgPath); 42 | imageStamp.XIndent = 300; 43 | imageStamp.YIndent = aPdfPage.PageInfo.Height - 200; 44 | imageStamp.Height = 81; 45 | imageStamp.Width = 80; 46 | aPdfPage.AddStamp(imageStamp); 47 | } 48 | 49 | 50 | pdfDocument.Save(outputPath); 51 | } 52 | } 53 | 54 | public void FromXps(string absoluteFilePath, string outputPath) 55 | { 56 | // Instantiate LoadOption object using XPS load option 57 | Aspose.Pdf.LoadOptions options = new XpsLoadOptions(); 58 | 59 | // Create document object 60 | Aspose.Pdf.Document document = new Aspose.Pdf.Document(absoluteFilePath, options); 61 | 62 | // Save the resultant PDF document 63 | document.Save(outputPath); 64 | } 65 | 66 | public void InsertPage(string absoluteFilePath, string outputPath) 67 | { 68 | var insertPageImgPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DefaultResource","insertPage.jpeg"); 69 | using (var pdfDocument = new Document(absoluteFilePath)) 70 | using (BackgroundArtifact background = new BackgroundArtifact()) 71 | { 72 | // Add a new page to document object 73 | Page page = pdfDocument.Pages.Insert(2); 74 | page.AddImage(insertPageImgPath, page.Rect); 75 | 76 | pdfDocument.Save(outputPath); 77 | } 78 | } 79 | 80 | public void ToJpeg(string absoluteFilePath, string outputPath) 81 | { 82 | using (var pdfDocument = new Document(absoluteFilePath)) 83 | { 84 | for(var i = 1; i < pdfDocument.Pages.Count + 1; i++) 85 | { 86 | 87 | using (FileStream imageStream = new FileStream(Path.Combine(outputPath, i.ToString() + ".jpeg"), FileMode.Create)) 88 | { 89 | //Quality [0-100], 100 is Maximum 90 | //create Resolution object 91 | Resolution resolution = new Resolution(300); 92 | JpegDevice jpegDevice = new JpegDevice(resolution, 100); 93 | 94 | //convert a particular page and save the image to stream 95 | jpegDevice.Process(pdfDocument.Pages[i], imageStream); 96 | 97 | //close stream 98 | imageStream.Close(); 99 | } 100 | } 101 | } 102 | } 103 | 104 | public void ToTxt(string absoluteFilePath, string outputPath) 105 | { 106 | var txtAbsorber = new TextAbsorber(); 107 | using (var pdfDocument = new Document(absoluteFilePath)) 108 | { 109 | pdfDocument.Pages.Accept(txtAbsorber); 110 | File.WriteAllText(outputPath, txtAbsorber.Text); 111 | } 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /PdfComponentDemo/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /PdfComponentDemo/Form1.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | -------------------------------------------------------------------------------- /PdfComponentDemo/Form1.cs: -------------------------------------------------------------------------------- 1 | using PdfComponent.Lib.Interfaces; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Diagnostics; 7 | using System.Drawing; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | using System.Windows.Forms; 13 | 14 | namespace PdfComponentDemo 15 | { 16 | public partial class Form1 : Form 17 | { 18 | private readonly List _pdfComponents = new List(); 19 | 20 | public Form1() 21 | { 22 | InitializeComponent(); 23 | InitComponentList(); 24 | } 25 | 26 | private void InitComponentList() 27 | { 28 | var implementedComponents = typeof(IPdfComponentFunc).Assembly.GetTypes() 29 | .Where(p => typeof(IPdfComponentFunc).IsAssignableFrom(p) && !p.IsInterface); 30 | 31 | foreach (var aComponent in implementedComponents) 32 | { 33 | var componentInstance = (IPdfComponentFunc)Activator.CreateInstance(aComponent); 34 | _pdfComponents.Add(componentInstance); 35 | cmb_Component.DisplayMember = "ComponentName"; 36 | cmb_Component.Items.Add(new { ComponentName = componentInstance.ComponentName, ComponentIns = componentInstance }); 37 | } 38 | } 39 | 40 | private void btn_SelectPdfDir_Click(object sender, EventArgs e) 41 | { 42 | if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK) 43 | { 44 | this.txt_PdfFilesDir.Text = this.folderBrowserDialog1.SelectedPath; 45 | } 46 | } 47 | 48 | private void btn_SelectOutputDir_Click(object sender, EventArgs e) 49 | { 50 | if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK) 51 | { 52 | this.txt_OutputDir.Text = this.folderBrowserDialog1.SelectedPath; 53 | } 54 | } 55 | 56 | private void btn_ToJpeg_Click(object sender, EventArgs e) 57 | { 58 | CommonWorkFlow((aPdfFile, outputDir) => 59 | { 60 | var selectCompoent = GetSelectedComponent(); 61 | 62 | selectCompoent.ToJpeg(aPdfFile, outputDir); 63 | }); 64 | } 65 | 66 | private void btn_ToTxt_Click(object sender, EventArgs e) 67 | { 68 | CommonWorkFlow((aPdfFile, outputDir) => 69 | { 70 | var selectCompoent = GetSelectedComponent(); 71 | 72 | selectCompoent.ToTxt(aPdfFile, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(aPdfFile) + ".txt")); 73 | }); 74 | } 75 | 76 | private void btn_XpsFrom_Click(object sender, EventArgs e) 77 | { 78 | CommonWorkFlow((aPdfFile, outputDir) => 79 | { 80 | var selectCompoent = GetSelectedComponent(); 81 | 82 | selectCompoent.FromXps(aPdfFile, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(aPdfFile) + "_FromXps.pdf")); 83 | },".xps"); 84 | } 85 | 86 | private void btn_InsertPage_Click(object sender, EventArgs e) 87 | { 88 | CommonWorkFlow((aPdfFile, outputDir) => 89 | { 90 | var selectCompoent = GetSelectedComponent(); 91 | 92 | selectCompoent.InsertPage(aPdfFile, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(aPdfFile) + "_InsertedPage.pdf")); 93 | }); 94 | } 95 | 96 | private void btn_AddWaterprint_Click(object sender, EventArgs e) 97 | { 98 | CommonWorkFlow((aPdfFile, outputDir) => 99 | { 100 | var selectCompoent = GetSelectedComponent(); 101 | 102 | selectCompoent.AddWaterprint(aPdfFile, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(aPdfFile) + "_AddWatermakr.pdf")); 103 | }); 104 | } 105 | 106 | private void btn_AllRun_Click(object sender, EventArgs e) 107 | { 108 | CommonWorkFlow((aPdfFile, outputDir) => 109 | { 110 | var selectCompoent = GetSelectedComponent(); 111 | if (Path.GetExtension(aPdfFile).Equals(".xps", StringComparison.OrdinalIgnoreCase)) 112 | selectCompoent.FromXps(aPdfFile, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(aPdfFile) + "_FromXps.pdf")); 113 | else 114 | { 115 | selectCompoent.ToJpeg(aPdfFile, outputDir); 116 | selectCompoent.ToTxt(aPdfFile, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(aPdfFile) + ".txt")); 117 | selectCompoent.AddWaterprint(aPdfFile, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(aPdfFile) + "_AddWatermakr.pdf")); 118 | selectCompoent.InsertPage(aPdfFile, Path.Combine(outputDir, Path.GetFileNameWithoutExtension(aPdfFile) + "_InsertedPage.pdf")); 119 | } 120 | 121 | }, ".pdf,.xps"); 122 | } 123 | 124 | private void CommonWorkFlow(Action childDeal, string fileExtensionFilter = ".pdf") 125 | { 126 | if (!CheckSelect()) 127 | return; 128 | 129 | var stopWatch = new Stopwatch(); 130 | stopWatch.Start(); 131 | 132 | int excuteTimes = 1; 133 | if (!string.IsNullOrEmpty(txt_ExecuteTimes.Text)) 134 | Int32.TryParse(txt_ExecuteTimes.Text, out excuteTimes); 135 | 136 | for (int i = 0; i < excuteTimes; i++) 137 | { 138 | var pdfFiles = Directory.GetFiles(txt_PdfFilesDir.Text); 139 | foreach (var aPdfFile in pdfFiles) 140 | { 141 | var pdfOutputDir = Path.Combine(txt_OutputDir.Text, Path.GetFileNameWithoutExtension(aPdfFile)); 142 | 143 | if (!string.IsNullOrEmpty(fileExtensionFilter) && 144 | !fileExtensionFilter.Split(',').Any(p => p.Equals(Path.GetExtension(aPdfFile), StringComparison.OrdinalIgnoreCase))) 145 | continue; 146 | 147 | if (!Directory.Exists(pdfOutputDir)) 148 | Directory.CreateDirectory(pdfOutputDir); 149 | 150 | childDeal(aPdfFile, pdfOutputDir); 151 | } 152 | } 153 | 154 | stopWatch.Stop(); 155 | MessageBox.Show($"Executed { excuteTimes } times,costed time:{stopWatch.ElapsedMilliseconds} milliseconds in total."); 156 | } 157 | 158 | private IPdfComponentFunc GetSelectedComponent() 159 | { 160 | dynamic selectedItem = cmb_Component.SelectedItem; 161 | return (IPdfComponentFunc)selectedItem.ComponentIns; 162 | } 163 | 164 | private bool CheckSelect() 165 | { 166 | if (cmb_Component.SelectedIndex == -1) 167 | { 168 | MessageBox.Show("Please Select Pdf Component"); 169 | return false; 170 | } 171 | 172 | if( string.IsNullOrEmpty(txt_PdfFilesDir.Text)) 173 | { 174 | MessageBox.Show("Please Select Input File Directory"); 175 | return false; 176 | } 177 | 178 | if (string.IsNullOrEmpty(txt_OutputDir.Text)) 179 | { 180 | MessageBox.Show("Please Select Output Directory"); 181 | return false; 182 | } 183 | 184 | int i; 185 | if (!string.IsNullOrEmpty(txt_ExecuteTimes.Text) && !Int32.TryParse(txt_ExecuteTimes.Text, out i)) 186 | { 187 | MessageBox.Show("ExecuteTimes Must Be Numberic"); 188 | return false; 189 | } 190 | 191 | return true; 192 | } 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /PdfComponentDemo/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace PdfComponentDemo 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要修改 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.btn_ToJpeg = new System.Windows.Forms.Button(); 32 | this.cmb_Component = new System.Windows.Forms.ComboBox(); 33 | this.txt_PdfFilesDir = new System.Windows.Forms.TextBox(); 34 | this.txt_OutputDir = new System.Windows.Forms.TextBox(); 35 | this.btn_SelectPdfDir = new System.Windows.Forms.Button(); 36 | this.btn_SelectOutputDir = new System.Windows.Forms.Button(); 37 | this.label1 = new System.Windows.Forms.Label(); 38 | this.label2 = new System.Windows.Forms.Label(); 39 | this.label3 = new System.Windows.Forms.Label(); 40 | this.btn_ToTxt = new System.Windows.Forms.Button(); 41 | this.btn_XpsFrom = new System.Windows.Forms.Button(); 42 | this.btn_InsertPage = new System.Windows.Forms.Button(); 43 | this.btn_AddWaterprint = new System.Windows.Forms.Button(); 44 | this.btn_AllRun = new System.Windows.Forms.Button(); 45 | this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); 46 | this.label4 = new System.Windows.Forms.Label(); 47 | this.txt_ExecuteTimes = new System.Windows.Forms.TextBox(); 48 | this.SuspendLayout(); 49 | // 50 | // btn_ToJpeg 51 | // 52 | this.btn_ToJpeg.Location = new System.Drawing.Point(22, 142); 53 | this.btn_ToJpeg.Name = "btn_ToJpeg"; 54 | this.btn_ToJpeg.Size = new System.Drawing.Size(75, 23); 55 | this.btn_ToJpeg.TabIndex = 0; 56 | this.btn_ToJpeg.Text = "ToJpeg"; 57 | this.btn_ToJpeg.UseVisualStyleBackColor = true; 58 | this.btn_ToJpeg.Click += new System.EventHandler(this.btn_ToJpeg_Click); 59 | // 60 | // cmb_Component 61 | // 62 | this.cmb_Component.FormattingEnabled = true; 63 | this.cmb_Component.Location = new System.Drawing.Point(108, 30); 64 | this.cmb_Component.Name = "cmb_Component"; 65 | this.cmb_Component.Size = new System.Drawing.Size(200, 20); 66 | this.cmb_Component.TabIndex = 1; 67 | // 68 | // txt_PdfFilesDir 69 | // 70 | this.txt_PdfFilesDir.Location = new System.Drawing.Point(107, 58); 71 | this.txt_PdfFilesDir.Name = "txt_PdfFilesDir"; 72 | this.txt_PdfFilesDir.Size = new System.Drawing.Size(273, 21); 73 | this.txt_PdfFilesDir.TabIndex = 2; 74 | // 75 | // txt_OutputDir 76 | // 77 | this.txt_OutputDir.Location = new System.Drawing.Point(107, 85); 78 | this.txt_OutputDir.Name = "txt_OutputDir"; 79 | this.txt_OutputDir.Size = new System.Drawing.Size(273, 21); 80 | this.txt_OutputDir.TabIndex = 3; 81 | // 82 | // btn_SelectPdfDir 83 | // 84 | this.btn_SelectPdfDir.Location = new System.Drawing.Point(387, 55); 85 | this.btn_SelectPdfDir.Name = "btn_SelectPdfDir"; 86 | this.btn_SelectPdfDir.Size = new System.Drawing.Size(75, 23); 87 | this.btn_SelectPdfDir.TabIndex = 4; 88 | this.btn_SelectPdfDir.Text = "Browse"; 89 | this.btn_SelectPdfDir.UseVisualStyleBackColor = true; 90 | this.btn_SelectPdfDir.Click += new System.EventHandler(this.btn_SelectPdfDir_Click); 91 | // 92 | // btn_SelectOutputDir 93 | // 94 | this.btn_SelectOutputDir.Location = new System.Drawing.Point(387, 82); 95 | this.btn_SelectOutputDir.Name = "btn_SelectOutputDir"; 96 | this.btn_SelectOutputDir.Size = new System.Drawing.Size(75, 23); 97 | this.btn_SelectOutputDir.TabIndex = 5; 98 | this.btn_SelectOutputDir.Text = "Browse"; 99 | this.btn_SelectOutputDir.UseVisualStyleBackColor = true; 100 | this.btn_SelectOutputDir.Click += new System.EventHandler(this.btn_SelectOutputDir_Click); 101 | // 102 | // label1 103 | // 104 | this.label1.AutoSize = true; 105 | this.label1.Location = new System.Drawing.Point(24, 66); 106 | this.label1.Name = "label1"; 107 | this.label1.Size = new System.Drawing.Size(77, 12); 108 | this.label1.TabIndex = 6; 109 | this.label1.Text = "InputFileDir"; 110 | // 111 | // label2 112 | // 113 | this.label2.AutoSize = true; 114 | this.label2.Location = new System.Drawing.Point(25, 33); 115 | this.label2.Name = "label2"; 116 | this.label2.Size = new System.Drawing.Size(77, 12); 117 | this.label2.TabIndex = 6; 118 | this.label2.Text = "UseComponent"; 119 | // 120 | // label3 121 | // 122 | this.label3.AutoSize = true; 123 | this.label3.Location = new System.Drawing.Point(18, 88); 124 | this.label3.Name = "label3"; 125 | this.label3.Size = new System.Drawing.Size(83, 12); 126 | this.label3.TabIndex = 6; 127 | this.label3.Text = "OutputFileDir"; 128 | // 129 | // btn_ToTxt 130 | // 131 | this.btn_ToTxt.Location = new System.Drawing.Point(103, 142); 132 | this.btn_ToTxt.Name = "btn_ToTxt"; 133 | this.btn_ToTxt.Size = new System.Drawing.Size(75, 23); 134 | this.btn_ToTxt.TabIndex = 0; 135 | this.btn_ToTxt.Text = "ToTxt"; 136 | this.btn_ToTxt.UseVisualStyleBackColor = true; 137 | this.btn_ToTxt.Click += new System.EventHandler(this.btn_ToTxt_Click); 138 | // 139 | // btn_XpsFrom 140 | // 141 | this.btn_XpsFrom.Location = new System.Drawing.Point(184, 142); 142 | this.btn_XpsFrom.Name = "btn_XpsFrom"; 143 | this.btn_XpsFrom.Size = new System.Drawing.Size(75, 23); 144 | this.btn_XpsFrom.TabIndex = 0; 145 | this.btn_XpsFrom.Text = "Xps2Pdf"; 146 | this.btn_XpsFrom.UseVisualStyleBackColor = true; 147 | this.btn_XpsFrom.Click += new System.EventHandler(this.btn_XpsFrom_Click); 148 | // 149 | // btn_InsertPage 150 | // 151 | this.btn_InsertPage.Location = new System.Drawing.Point(265, 142); 152 | this.btn_InsertPage.Name = "btn_InsertPage"; 153 | this.btn_InsertPage.Size = new System.Drawing.Size(75, 23); 154 | this.btn_InsertPage.TabIndex = 0; 155 | this.btn_InsertPage.Text = "InsertPage"; 156 | this.btn_InsertPage.UseVisualStyleBackColor = true; 157 | this.btn_InsertPage.Click += new System.EventHandler(this.btn_InsertPage_Click); 158 | // 159 | // btn_AddWaterprint 160 | // 161 | this.btn_AddWaterprint.Location = new System.Drawing.Point(346, 142); 162 | this.btn_AddWaterprint.Name = "btn_AddWaterprint"; 163 | this.btn_AddWaterprint.Size = new System.Drawing.Size(75, 23); 164 | this.btn_AddWaterprint.TabIndex = 0; 165 | this.btn_AddWaterprint.Text = "Watermark"; 166 | this.btn_AddWaterprint.UseVisualStyleBackColor = true; 167 | this.btn_AddWaterprint.Click += new System.EventHandler(this.btn_AddWaterprint_Click); 168 | // 169 | // btn_AllRun 170 | // 171 | this.btn_AllRun.Location = new System.Drawing.Point(157, 176); 172 | this.btn_AllRun.Name = "btn_AllRun"; 173 | this.btn_AllRun.Size = new System.Drawing.Size(128, 23); 174 | this.btn_AllRun.TabIndex = 0; 175 | this.btn_AllRun.Text = "AllRun"; 176 | this.btn_AllRun.UseVisualStyleBackColor = true; 177 | this.btn_AllRun.Click += new System.EventHandler(this.btn_AllRun_Click); 178 | // 179 | // label4 180 | // 181 | this.label4.AutoSize = true; 182 | this.label4.ForeColor = System.Drawing.SystemColors.ControlText; 183 | this.label4.Location = new System.Drawing.Point(24, 115); 184 | this.label4.Name = "label4"; 185 | this.label4.Size = new System.Drawing.Size(77, 12); 186 | this.label4.TabIndex = 6; 187 | this.label4.Text = "ExecuteTimes"; 188 | // 189 | // txt_ExecuteTimes 190 | // 191 | this.txt_ExecuteTimes.Location = new System.Drawing.Point(107, 112); 192 | this.txt_ExecuteTimes.Name = "txt_ExecuteTimes"; 193 | this.txt_ExecuteTimes.Size = new System.Drawing.Size(41, 21); 194 | this.txt_ExecuteTimes.TabIndex = 3; 195 | // 196 | // Form1 197 | // 198 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 199 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 200 | this.ClientSize = new System.Drawing.Size(488, 211); 201 | this.Controls.Add(this.label4); 202 | this.Controls.Add(this.label3); 203 | this.Controls.Add(this.label2); 204 | this.Controls.Add(this.label1); 205 | this.Controls.Add(this.btn_SelectOutputDir); 206 | this.Controls.Add(this.btn_SelectPdfDir); 207 | this.Controls.Add(this.txt_ExecuteTimes); 208 | this.Controls.Add(this.txt_OutputDir); 209 | this.Controls.Add(this.txt_PdfFilesDir); 210 | this.Controls.Add(this.cmb_Component); 211 | this.Controls.Add(this.btn_AllRun); 212 | this.Controls.Add(this.btn_AddWaterprint); 213 | this.Controls.Add(this.btn_InsertPage); 214 | this.Controls.Add(this.btn_XpsFrom); 215 | this.Controls.Add(this.btn_ToTxt); 216 | this.Controls.Add(this.btn_ToJpeg); 217 | this.Name = "Form1"; 218 | this.Text = "PdfDemo"; 219 | this.ResumeLayout(false); 220 | this.PerformLayout(); 221 | 222 | } 223 | 224 | #endregion 225 | 226 | private System.Windows.Forms.Button btn_ToJpeg; 227 | private System.Windows.Forms.ComboBox cmb_Component; 228 | private System.Windows.Forms.TextBox txt_PdfFilesDir; 229 | private System.Windows.Forms.TextBox txt_OutputDir; 230 | private System.Windows.Forms.Button btn_SelectPdfDir; 231 | private System.Windows.Forms.Button btn_SelectOutputDir; 232 | private System.Windows.Forms.Label label1; 233 | private System.Windows.Forms.Label label2; 234 | private System.Windows.Forms.Label label3; 235 | private System.Windows.Forms.Button btn_ToTxt; 236 | private System.Windows.Forms.Button btn_XpsFrom; 237 | private System.Windows.Forms.Button btn_InsertPage; 238 | private System.Windows.Forms.Button btn_AddWaterprint; 239 | private System.Windows.Forms.Button btn_AllRun; 240 | private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1; 241 | private System.Windows.Forms.Label label4; 242 | private System.Windows.Forms.TextBox txt_ExecuteTimes; 243 | } 244 | } 245 | 246 | --------------------------------------------------------------------------------