码迷,mamicode.com
首页 > Windows程序 > 详细

C# iText split PDF C# 拆分PDF

时间:2019-07-01 19:59:20      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:readonly   string   nbsp   int   count   enum   doc   tutorial   new   

Nuget安装iText7

 

using iText.Kernel.Utils;
using iText.Kernel.Pdf;
using System.IO;

public class MyPdfSplitter : PdfSplitter
    {
        private readonly string _destFolder;
        private int _pageNumber;
        public MyPdfSplitter(PdfDocument pdfDocument, string destFolder) : base(pdfDocument)
        {
            _destFolder = destFolder;
        }

        protected override PdfWriter GetNextPdfWriter(PageRange documentPageRange)
        {
            _pageNumber++;
            return new PdfWriter(Path.Combine(_destFolder, $"pdf{_pageNumber}.pdf"));
        }
    }


static void ITextSplitPdf()
        {
            string rawPdfFile = @"C:\Users\ffu\Downloads\Essential_Javascript_--_A_Javascript_Tutorial.pdf";
            string splitPDFDir = Directory.GetCurrentDirectory() + "//";
            using (var pdfDoc = new PdfDocument(new PdfReader(rawPdfFile)))
            {
                var splitDocuments = new MyPdfSplitter(pdfDoc, splitPDFDir).SplitByPageCount(1);
                foreach (var splitDocument in splitDocuments)
                {
                    splitDocument.Close();
                }
            }
        }

 

C# iText split PDF C# 拆分PDF

标签:readonly   string   nbsp   int   count   enum   doc   tutorial   new   

原文地址:https://www.cnblogs.com/Fred1987/p/11116256.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!