C#-合并多个PDF文档中指定页.docxVIP

  • 5
  • 0
  • 约2千字
  • 约 4页
  • 2018-06-28 发布于福建
  • 举报
C# /VB.NET合并多个PDF文档中的指定页操作要求将多个不同PDF文档中的指定页,合并成为另一个新的PDF文档使用工具Free Spire.PDF for .NET 4.3(社区版)Visual StudioPS:下载安装该组件后,注意在项目程序中添加引用Spire.PDF.dll文件操作方法:步骤1:初始化数组,数组元素为需要合并的PDF文档string[] files = { sample1.pdf, sample2.pdf };PdfDocument[] docs = newPdfDocument[files.Length];步骤2:遍历PDF文档for (inti = 0; i files.Length; i++){docs[i] = newPdfDocument();docs[i].LoadFromFile(files[i]);}步骤3:创建一个新的PDF文档并插入从原文档选取的指定页PdfDocument doc = newPdfDocument();doc.InsertPage(docs[0], 0);//指定单页(文档1的第1页)doc.InsertPageRange(docs[1], 0, 1);//指定多页(文档2的第1页和第2页)步骤4:保存并命名合并后的文档,同时运行文档doc.SaveToFile(Result.pdf);Process.Start(Result.pdf);效果对比合并前:合并后:全部代码【C#】usingSpire.Pdf;usingSystem.Diagnostics;namespaceMergeSelectedPDFpages{classProgram {staticvoid Main(string[] args) {string[] files = { sample1.pdf, sample2.pdf };PdfDocument[] docs = newPdfDocument[files.Length];for (inti = 0; i files.Length; i++) {docs[i] = newPdfDocument();docs[i].LoadFromFile(files[i]); }PdfDocument doc = newPdfDocument();doc.InsertPage(docs[0], 0);doc.InsertPageRange(docs[1], 0, 1);doc.SaveToFile(Result.pdf);Process.Start(Result.pdf); } }}VB.NETImports?Spire.PdfImports?System.DiagnosticsNamespace?MergeSelectedPDFpages????????Class?Program????????????????Private?Shared?Sub?Main(ByVal?args()?As?String)????????????Dim?files()?As?String?=?New?String()?{sample1.pdf,?sample2.pdf}????????????Dim?docs()?As?PdfDocument?=?New?PdfDocument((files.Length)?-?1)?{}????????????Dim?i?As?Integer?=?0????????????Do?While?(i??files.Length)????????????????docs(i)?=?New?PdfDocument????????????????docs(i).LoadFromFile(files(i))????????????????i?=?(i?+?1)????????????Loop????????????????????????Dim?doc?As?PdfDocument?=?New?PdfDocument????????????doc.InsertPage(docs(0),?0)????????????doc.InsertPageRange(docs(1),?0,?1)????????????doc.SaveToFile(Result.pdf)????????????Process.Start(Result.pdf)????????End?Sub????End?ClassEnd?Namespace以上内容是本次关于“如何合并PDF文档指定页”的全部介绍,如果喜欢,欢迎转载(转载请注明出处)感谢阅读!

文档评论(0)

1亿VIP精品文档

相关文档