将多页文档拆分为单个 PDF
2023年一月25日
更新 2024年十二月10日
This article was translated from English: Does it need improvement?
TranslatedView the article in English
只需几行代码就能将多页 PDF 文档拆分成单个 PDF。 请参考我们的示例以在您的项目中实现它。
有了 IronPdf,将单个 PDF 文档拆分成多个文档(每个文档只包含一页)变得非常容易。
开始使用IronPDF
立即在您的项目中开始使用IronPDF,并享受免费试用。
分割 PDF 文档
将多页PDF拆分
现在您拥有IronPDF,可以将多页文档拆分为单页文档文件。 将多页PDF拆分的概念涉及使用CopyPage
或CopyPages
方法复制单页或多页。
:path=/static-assets/pdf/content-code-examples/how-to/split-multipage-pdf-split-pdf.cs
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("multiPage.pdf");
for (int idx = 0; idx < pdf.PageCount; idx++)
{
// Create new document for each page
PdfDocument outputDocument = pdf.CopyPage(idx);
string fileName = @$"multiPage - Page {idx + 1}_tempfile.pdf";
// Export to new file
outputDocument.SaveAs(fileName);
}
查看上面的代码,您可以看到它使用 for 循环遍历当前 PDF 文档的页面,然后使用 CopyPage
方法将每个页面复制到一个新的 PdfDocument 对象中。 最后,页面被导出为一个新文档。