继续使用 DocNET: https://github.com/GowenGit/docnet
Nuget:
Install-Package Docnet.Core
切分 PDF
注意,DocNET 的 Split 方法的索引是从 0 开始的,所以我们认为的获取 PDF 的第三到第五页,在 DocNET 的 Split 方法其实是从第二到第四页…
public static bool SplitPdf(string inputPath,int pageFrom,int pageTo, string outputPath) { bool result = false; try { using (var docnet = DocLib.Instance) { var bytes = docnet.Split(inputPath, pageFrom - 1, pageTo - 1); File.WriteAllBytes(outputPath, bytes); } result = true; } catch (Exception e) { Console.WriteLine($"error:{e}"); } return result; }
调用下看看效果:
public IActionResult Index() { bool result = PdfHelper.SplitPdf("F:\\pdf\\compressed.tracemonkey-pldi-09.pdf",3,5, "F:\\pdf\\compressed.tracemonkey-pldi-10.pdf"); return Content(result.ToString()); }
合并PDF
合并就比较简单
public static bool MergePdf(string inputPath1, string inputPath2, string outputPath) { bool result = false; try { using (var docnet = DocLib.Instance) { var bytes = docnet.Merge(inputPath1, inputPath2); File.WriteAllBytes(outputPath, bytes); } result = true; } catch (Exception e) { Console.WriteLine($"error:{e}"); } return result; }标签:Core,ASP,string,bytes,docnet,bool,result,PDF From: https://www.cnblogs.com/sun8134/p/18093958