C#拆分单页PDF

   using iTextSharp.text;
using iTextSharp.text.pdf;
...


   // 目标分割pdf文件
    string inputFilePath = @"623.pdf";

    // 创建输出文件所在文件夹
    string outputFolder = "NewFile";
    string rootPath = System.IO.Directory.GetCurrentDirectory();
    string folderAll = Path.Combine(rootPath, outputFolder);
    if (!Directory.Exists(folderAll))
    {
        Directory.CreateDirectory(folderAll);
    }

    // 操作pdf分割
    using (PdfReader reader = new PdfReader(inputFilePath))
    {
        for (int i = 1; i <= reader.NumberOfPages; i++)
        {
            string newFilePath = Path.Combine(outputFolder, $"page_{i}.pdf");

            using (Document document = new Document())
            using (PdfCopy copy = new PdfCopy(document, new FileStream(newFilePath, FileMode.Create)))
            {
                document.Open();
                PdfImportedPage pp = copy.GetImportedPage(reader, i);
                copy.AddPage(pp);
                document.Close();
            }
        }
    }

    Console.WriteLine("PDF 分割完成!");

相关推荐

  1. C#PDF

    2024-07-17 11:04:01       23 阅读
  2. 为什么pdf出几之后大小几乎没有变化

    2024-07-17 11:04:01       36 阅读
  3. 应用的构建优化-按entry构建

    2024-07-17 11:04:01       26 阅读
  4. python-pdf的合并与

    2024-07-17 11:04:01       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-17 11:04:01       50 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-17 11:04:01       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-17 11:04:01       43 阅读
  4. Python语言-面向对象

    2024-07-17 11:04:01       54 阅读

热门阅读

  1. TCP/IP、UDP、HTTP 协议介绍比较和总结

    2024-07-17 11:04:01       19 阅读
  2. js | 原型链

    2024-07-17 11:04:01       21 阅读
  3. baomidou @DS注解

    2024-07-17 11:04:01       19 阅读
  4. arkts中状态管理

    2024-07-17 11:04:01       22 阅读
  5. mac如何查看cpu和显卡温度

    2024-07-17 11:04:01       21 阅读
  6. 关于HBase、Phoenix、Flume、Maxwell 和 Flink

    2024-07-17 11:04:01       21 阅读
  7. 银河麒麟如何部署QtMqtt(入门案例教程)

    2024-07-17 11:04:01       20 阅读
  8. Android中ContentProvider学习记录

    2024-07-17 11:04:01       20 阅读
  9. IPython 宏魔法:%macro 命令的高效使用指南

    2024-07-17 11:04:01       22 阅读
  10. 五、python列表

    2024-07-17 11:04:01       22 阅读