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 分割完成!");
C#拆分单页PDF
最新推荐文章于 2024-09-30 19:57:49 发布