將多頁文件拆分成單個 PDF
2023年1月25日
已更新 2024年12月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);
}
Imports IronPdf
Private pdf As PdfDocument = PdfDocument.FromFile("multiPage.pdf")
For idx As Integer = 0 To pdf.PageCount - 1
' Create new document for each page
Dim outputDocument As PdfDocument = pdf.CopyPage(idx)
Dim fileName As String = $"multiPage - Page {idx + 1}_tempfile.pdf"
' Export to new file
outputDocument.SaveAs(fileName)
Next idx
$vbLabelText $csharpLabel
查看上面的代碼,您可以看到它使用了一個 for 迴圈來遍歷當前 PDF 文件的頁面,然後使用 CopyPage
方法將每個頁面複製到一個新的 PdfDocument 對象中。 最後,這些頁面被導出為一個新文件。