# How to Organize your PDFs in C#
IronPDF 除了具備 PDF 生成功能外,還提供一套全面的工具,其中部分工具可用於組織您的 PDF 文件結構。 編輯 PDF 檔案的結構,從未如此簡單。 透過單一函式庫,即可調整 PDF 結構、新增書籤與附件,並建立理想的 PDF 版面配置。 有了 IronPDF,您將再也不必為 PDF 檔案的整理而苦惱。
在這篇詳盡的教學中,我們將探討如何運用 IronPDF 來更有效地管理您的 PDF 文件。 為此,我們將透過一些基本範例,帶您了解這些組織功能的運作方式,並分析程式碼範例及其對應的說明。 讀完本文後,您將能立即開始使用 IronPDF 來滿足您的 PDF 管理需求。
*as-heading:2(快速入門:使用 IronPDF 輕鬆合併 PDF 檔案)*
只需幾行程式碼,即可開始使用 IronPDF 整理您的 PDF 檔案。 此範例展示如何輕鬆地使用 IronPDF 函式庫將多個 PDF 文件合併為一個。 此方法非常適合尋求快速且直觀解決方案的開發人員,可無縫整合至您的 C# 專案中,提升文件管理效率。
```cs
:title=Organize PDFs Instantly
IronPdf.PdfDocument.Merge(
IronPdf.PdfDocument.FromFile("file1.pdf"),
IronPdf.PdfDocument.FromFile("file2.pdf"))
.SaveAs("merged.pdf");
```
## 目錄
- **整理您的 PDF 結構**
- [新增、複製及刪除 PDF 頁面](#anchor-manage-your-pdf-pages)
- [新增頁面](#anchor-add-pages)
- [複製頁面](#anchor-copy-pages)
- [刪除頁面](#anchor-delete-pages)
- [合併或分割 PDF 檔案](#anchor-merge-pdfs)
- [分割多頁 PDF](#anchor-split-multipage-pdf)
- **補充資訊**
- [新增與移除附件](#anchor-add-remove-attachments)
- [新增附件](#anchor-add-attachments)
- [移除附件](#anchor-remove-attachments)
- [大綱與書籤](#anchor-outlines-bookmarks)
- [新增書籤](#anchor-add-bookmarks)
- [檢索書籤](#anchor-retrieve-bookmarks)
## 整理您的 PDF 結構
首先,讓我們來看看 IronPDF 提供哪些功能,協助您掌控 PDF 檔案的結構。 透過這些工具,您可以輕鬆操作 PDF 文件內的頁面並控制其位置。
### 管理您的 PDF 頁面
透過新增頁面、從文件中刪除不必要的頁面,甚至複製特定頁面以建立副本,為您的 PDF 文件增添新內容。 透過操作 PDF 文件內的頁面,您可以輕鬆地重新調整 PDF 結構以符合您的需求。
#### 新增頁面
只需幾行程式碼,即可在您的 PDF 中新增一頁。 使用 IronPDF,向 PDF 檔案新增內容變得輕而易舉。
```cs
using IronPdf;
// Import cover page
PdfDocument coverPage = PdfDocument.FromFile("coverPage.pdf");
// Import content document
PdfDocument contentPage = PdfDocument.FromFile("contentPage.pdf");
// Merge the two documents
PdfDocument finalPdf = PdfDocument.Merge(coverPage, contentPage);
finalPdf.SaveAs("pdfWithCover.pdf");
```
此方法簡化了新增頁面的流程。 若要在多頁 PDF 文件中的特定頁碼處新增頁面,您可以輕鬆透過 `InsertPdf` 方法達成:
```cs
using IronPdf;
// Import cover page
PdfDocument coverPage = PdfDocument.FromFile("coverPage.pdf");
// Import content document
PdfDocument contentPage = PdfDocument.FromFile("contentPage.pdf");
// Insert PDF
contentPage.InsertPdf(coverPage, 0);
```
#### 複製頁面
透過複製 PDF 文件內的頁面,您可以輕鬆維持一致的風格,並在多個 PDF 檔案間傳遞資訊。 IronPDF 的 `CopyPage` 和 `CopyPages` 方法提供了一種簡便的方式,只需幾行程式碼即可複製 PDF 中的特定頁面。
```cs
using IronPdf;
using System.Collections.Generic;
// Copy a single page into a new PDF object
PdfDocument myReport = PdfDocument.FromFile("report_final.pdf");
PdfDocument copyOfPageOne = myReport.CopyPage(0);
// Copy multiple pages into a new PDF object
PdfDocument copyOfFirstThreePages = myReport.CopyPages(new List<int> { 0, 1, 2 });
```
#### 刪除頁面
若要從 PDF 中刪除特定頁面,您可以使用 `RemovePage` 和 `RemovePages` 方法,藉此透過程式化方式從文件中移除不需要的頁面。
```cs
using IronPdf;
using System.Collections.Generic;
PdfDocument pdf = PdfDocument.FromFile("full_report.pdf");
// Remove a single page
pdf.RemovePage(0);
// Remove multiple pages
pdf.RemovePages(new List<int> { 2, 3 });
```
如需更詳細地了解上述程式碼片段,並探索其額外功能,請參閱我們的完整[操作指南](http://test.ironpdf.local/how-to/add-copy-delete-pages-pdf/)。
### 合併或分割 PDF
#### 合併 PDF
using IronPDF 的合併工具,將多個 PDF 文件合併為單一、易於分享的 PDF 檔案。 此功能特別適用於您需要將相似文件分組以便更輕鬆地分發、將單一頁面合併為新的 PDF,或執行各種其他 PDF 合併任務時。 透過 IronPDF 的合併工具,您可以利用 `Merge` 方法輕鬆自動化此流程。
```cs
using IronPdf;
// Two paged PDF
const string html_a =
@"<p> [PDF_A] </p>
<p> [PDF_A] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_A] 2nd Page</p>";
// Two paged PDF
const string html_b =
@"<p> [PDF_B] </p>
<p> [PDF_B] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_B] 2nd Page</p>";
var renderer = new ChromePdfRenderer();
var pdfdoc_a = renderer.RenderHtmlAsPdf(html_a);
var pdfdoc_b = renderer.RenderHtmlAsPdf(html_b);
// Four paged PDF
var merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
merged.SaveAs("Merged.pdf");
```
#### 分割 PDF
正如您可能希望將多個 PDF 合併為單一、易於分享的 PDF 文件,有時您也可能需要將多頁面的 PDF 檔案拆分為獨立的文件。
```cs
using IronPdf;
// We will use the 4-page PDF from the Merge example above:
var pdf = PdfDocument.FromFile("Merged.pdf");
// Takes only the first page into a new PDF
var page1doc = pdf.CopyPage(0);
page1doc.SaveAs("Page1Only.pdf");
// Take the pages 2 & 3 (Note: index starts at 0)
var page23doc = pdf.CopyPages(1, 2);
page23doc.SaveAs("Pages2to3.pdf");
```
如需更詳細地了解上述程式碼片段,並探索其額外功能,請參閱我們的完整[操作指南](https://ironpdf.com/how-to/merge-or-split-pdfs/)。
### 分割多頁 PDF
關於分割多頁 PDF 檔案,我們將採用與分割單頁 PDF 檔案類似的方法。 在此情況下,我們將使用 for 迴圈來完成這項任務。
```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);
}
```
如需更詳細地了解上述程式碼片段,並探索其額外功能,請參閱我們的完整[操作指南](https://ironpdf.com/how-to/split-multipage-pdf/)。
## 組織工具
在本節中,我們將深入探討 IronPDF 提供的一些工具,以協助您改善 PDF 文件的組織架構。 透過運用這些工具,您可以強化您的 PDF 文件,讓讀者更輕鬆地瀏覽多頁內容。
### 新增與移除附件
透過附件連結支援文件、相關內容等,以強化您的 PDF 檔案。 透過在特定頁面加入額外的資料、資料及圖片,可避免因增加頁數而使文件顯得雜亂,從而提升文件瀏覽的便利性。 透過 IronPDF,您可以輕鬆地新增或移除附件,確保您的 PDF 文件內容精準且簡潔。
#### 新增附件
```cs
using IronPdf;
using System.IO;
// Import attachment file
byte[] fileData = File.ReadAllBytes(@"path/to/file");
// Open existing PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Add attachment to the PDF
pdf.Attachments.AddAttachment("Example", fileData);
pdf.SaveAs("addAttachment.pdf");
```
#### 移除附件
```cs
using IronPdf;
using System.Linq;
// Open existing PDF
PdfDocument pdf = PdfDocument.FromFile("addAttachment.pdf");
// Add attachment to the PDF
PdfAttachmentCollection retrieveAttachments = pdf.Attachments;
// Remove attachment from PDF
pdf.Attachments.RemoveAttachment(retrieveAttachments.First());
pdf.SaveAs("removeAttachment.pdf");
```
如需更詳細地了解上述程式碼片段,並探索其額外功能,請參閱我們的完整[操作指南](https://ironpdf.com/how-to/add-remove-attachments/)。
### 大綱與書籤
透過在多頁 PDF 文件中使用目錄,您可以顯著提升文件的易用性,並讓讀者更輕鬆地導航至文件內的特定頁面。 透過 IronPDF,您可以為 PDF 建立包含書籤的自訂大綱,為讀者提供流暢的導覽體驗。 同樣地,您可以檢索 PDF 文件中當前的書籤清單,藉此快速查看大綱的當前結構。
#### 新增書籤
IronPDF 同時支援單層與多層書籤,讓您能完全掌控 PDF 文件大綱的詳細程度,並可根據您的特定需求及 PDF 檔案長度進行客製化調整。
```cs
using IronPdf;
// Create a new PDF or edit an existing document.
PdfDocument pdf = PdfDocument.FromFile("existing.pdf");
// Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0);
// Add a sub-bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1);
pdf.SaveAs("singleLayerBookmarks.pdf");
```
#### 檢索書籤
若要檢視 PDF 文件中的現有書籤,`GetAllBookmarks` 工具提供了一種簡便的方法,可擷取任何指定 PDF 檔案中所有書籤的完整清單。
```cs
using IronPdf;
// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("multiLayerBookmarks.pdf");
// Retrieve bookmarks list
var mainBookmark = pdf.Bookmarks.GetAllBookmarks();
```
如需更詳細地了解上述程式碼片段,並探索其額外功能,請參閱我們的完整[操作指南](https://ironpdf.com/how-to/bookmarks/)。
## 結論
using IronPDF 管理您的 PDF 檔案可以非常簡單。 此工具提供一套全面的功能,讓您能夠管理頁面、合併或分割文件、建立大綱,以及處理附件——所有操作皆透過簡潔直觀的 C# 程式碼完成。 無論您是建立新文件,還是重新整理現有文件,IronPDF 都能讓您輕鬆產出精緻、Professional 的 PDF 檔案,這些檔案不僅易於瀏覽,也方便分享。
若您對 IronPDF 有任何疑問或希望提出功能需求,請聯繫[我們的支援團隊](/troubleshooting/engineering-request-pdf/)。 我們非常樂意為您提供協助。
IronPDF 除了具備 PDF 生成功能外,還提供一套全面的工具,其中部分工具可用於組織您的 PDF 文件結構。 編輯 PDF 檔案的結構,從未如此簡單。 透過單一函式庫,即可調整 PDF 結構、新增書籤與附件,並建立理想的 PDF 版面配置。 有了 IronPDF,您將再也不必為 PDF 檔案的整理而苦惱。
在這篇詳盡的教學中,我們將探討如何運用 IronPDF 來更有效地管理您的 PDF 文件。 為此,我們將透過一些基本範例,帶您了解這些組織功能的運作方式,並分析程式碼範例及其對應的說明。 讀完本文後,您將能立即開始使用 IronPDF 來滿足您的 PDF 管理需求。
快速入門:使用 IronPDF 輕鬆合併 PDF 檔案
只需幾行程式碼,即可開始使用 IronPDF 整理您的 PDF 檔案。 此範例展示如何輕鬆地使用 IronPDF 函式庫將多個 PDF 文件合併為一個。 此方法非常適合尋求快速且直觀解決方案的開發人員,可無縫整合至您的 C# 專案中,提升文件管理效率。
Imports IronPdf
' Import cover page
Private coverPage As PdfDocument = PdfDocument.FromFile("coverPage.pdf")
' Import content document
Private contentPage As PdfDocument = PdfDocument.FromFile("contentPage.pdf")
' Insert PDF
contentPage.InsertPdf(coverPage, 0)
複製頁面
透過複製 PDF 文件內的頁面,您可以輕鬆維持一致的風格,並在多個 PDF 檔案間傳遞資訊。 IronPDF 的 CopyPage 和 CopyPages 方法提供了一種簡便的方式,只需幾行程式碼即可複製 PDF 中的特定頁面。
using IronPdf;using System.Collections.Generic;// Copy a single page into a new PDF objectPdfDocument myReport = PdfDocument.FromFile("report_final.pdf");PdfDocument copyOfPageOne = myReport.CopyPage(0);// Copy multiple pages into a new PDF objectPdfDocument copyOfFirstThreePages = myReport.CopyPages(new List<int> { 0, 1, 2 });
using IronPdf;
using System.Collections.Generic;
// Copy a single page into a new PDF object
PdfDocument myReport = PdfDocument.FromFile("report_final.pdf");
PdfDocument copyOfPageOne = myReport.CopyPage(0);
// Copy multiple pages into a new PDF object
PdfDocument copyOfFirstThreePages = myReport.CopyPages(new List<int> { 0, 1, 2 });
ImportsIronPdfImportsSystem.Collections.Generic' Copy a single page into a new PDF objectPrivate myReport AsPdfDocument = PdfDocument.FromFile("report_final.pdf")Private copyOfPageOne AsPdfDocument = myReport.CopyPage(0)' Copy multiple pages into a new PDF objectPrivate copyOfFirstThreePages AsPdfDocument = myReport.CopyPages(New List(OfInteger) From {0, 1, 2})
Imports IronPdf
Imports System.Collections.Generic
' Copy a single page into a new PDF object
Private myReport As PdfDocument = PdfDocument.FromFile("report_final.pdf")
Private copyOfPageOne As PdfDocument = myReport.CopyPage(0)
' Copy multiple pages into a new PDF object
Private copyOfFirstThreePages As PdfDocument = myReport.CopyPages(New List(Of Integer) From {0, 1, 2})
刪除頁面
若要從 PDF 中刪除特定頁面,您可以使用 RemovePage 和 RemovePages 方法,藉此透過程式化方式從文件中移除不需要的頁面。
using IronPdf;using System.Collections.Generic;PdfDocument pdf = PdfDocument.FromFile("full_report.pdf");// Remove a single pagepdf.RemovePage(0);// Remove multiple pagespdf.RemovePages(new List<int> { 2, 3 });
using IronPdf;
using System.Collections.Generic;
PdfDocument pdf = PdfDocument.FromFile("full_report.pdf");
// Remove a single page
pdf.RemovePage(0);
// Remove multiple pages
pdf.RemovePages(new List<int> { 2, 3 });
ImportsIronPdfImportsSystem.Collections.GenericPrivate pdf AsPdfDocument = PdfDocument.FromFile("full_report.pdf")' Remove a single pagepdf.RemovePage(0)' Remove multiple pagespdf.RemovePages(New List(OfInteger) From {2, 3})
Imports IronPdf
Imports System.Collections.Generic
Private pdf As PdfDocument = PdfDocument.FromFile("full_report.pdf")
' Remove a single page
pdf.RemovePage(0)
' Remove multiple pages
pdf.RemovePages(New List(Of Integer) From {2, 3})
using IronPDF 的合併工具,將多個 PDF 文件合併為單一、易於分享的 PDF 檔案。 此功能特別適用於您需要將相似文件分組以便更輕鬆地分發、將單一頁面合併為新的 PDF,或執行各種其他 PDF 合併任務時。 透過 IronPDF 的合併工具,您可以利用 Merge 方法輕鬆自動化此流程。
Imports IronPdf
' Two paged PDF
Private Const html_a As String = "<p> [PDF_A] </p>
<p> [PDF_A] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_A] 2nd Page</p>"
' Two paged PDF
Private Const html_b As String = "<p> [PDF_B] </p>
<p> [PDF_B] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_B] 2nd Page</p>"
Private renderer = New ChromePdfRenderer()
Private pdfdoc_a = renderer.RenderHtmlAsPdf(html_a)
Private pdfdoc_b = renderer.RenderHtmlAsPdf(html_b)
' Four paged PDF
Private merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b)
merged.SaveAs("Merged.pdf")
分割 PDF
正如您可能希望將多個 PDF 合併為單一、易於分享的 PDF 文件,有時您也可能需要將多頁面的 PDF 檔案拆分為獨立的文件。
using IronPdf;// We will use the 4-page PDF from the Merge example above:var pdf = PdfDocument.FromFile("Merged.pdf");// Takes only the first page into a new PDFvar page1doc = pdf.CopyPage(0);page1doc.SaveAs("Page1Only.pdf");// Take the pages 2 & 3 (Note: index starts at 0)var page23doc = pdf.CopyPages(1, 2);page23doc.SaveAs("Pages2to3.pdf");
using IronPdf;
// We will use the 4-page PDF from the Merge example above:
var pdf = PdfDocument.FromFile("Merged.pdf");
// Takes only the first page into a new PDF
var page1doc = pdf.CopyPage(0);
page1doc.SaveAs("Page1Only.pdf");
// Take the pages 2 & 3 (Note: index starts at 0)
var page23doc = pdf.CopyPages(1, 2);
page23doc.SaveAs("Pages2to3.pdf");
ImportsIronPdf' We will use the 4-page PDF from the Merge example above:Private pdf = PdfDocument.FromFile("Merged.pdf")' Takes only the first page into a new PDFPrivate page1doc = pdf.CopyPage(0)page1doc.SaveAs("Page1Only.pdf")' Take the pages 2 & 3 (Note: index starts at 0)Dim page23doc = pdf.CopyPages(1, 2)page23doc.SaveAs("Pages2to3.pdf")
Imports IronPdf
' We will use the 4-page PDF from the Merge example above:
Private pdf = PdfDocument.FromFile("Merged.pdf")
' Takes only the first page into a new PDF
Private page1doc = pdf.CopyPage(0)
page1doc.SaveAs("Page1Only.pdf")
' Take the pages 2 & 3 (Note: index starts at 0)
Dim page23doc = pdf.CopyPages(1, 2)
page23doc.SaveAs("Pages2to3.pdf")
關於分割多頁 PDF 檔案,我們將採用與分割單頁 PDF 檔案類似的方法。 在此情況下,我們將使用 for 迴圈來完成這項任務。
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);}
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);
}
ImportsIronPdfPrivate pdf AsPdfDocument = PdfDocument.FromFile("multiPage.pdf")For idx AsInteger = 0 To pdf.PageCount - 1 ' Create new document for each page Dim outputDocument AsPdfDocument = pdf.CopyPage(idx) Dim fileName AsString = $"multiPage - Page {idx + 1}_tempfile.pdf" ' Export to new file outputDocument.SaveAs(fileName)Next idx
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
在本節中,我們將深入探討 IronPDF 提供的一些工具,以協助您改善 PDF 文件的組織架構。 透過運用這些工具,您可以強化您的 PDF 文件,讓讀者更輕鬆地瀏覽多頁內容。
新增與移除附件
透過附件連結支援文件、相關內容等,以強化您的 PDF 檔案。 透過在特定頁面加入額外的資料、資料及圖片,可避免因增加頁數而使文件顯得雜亂,從而提升文件瀏覽的便利性。 透過 IronPDF,您可以輕鬆地新增或移除附件,確保您的 PDF 文件內容精準且簡潔。
新增附件
using IronPdf;using System.IO;// Import attachment filebyte[] fileData = File.ReadAllBytes(@"path/to/file");// Open existing PDFPdfDocument pdf = PdfDocument.FromFile("sample.pdf");// Add attachment to the PDFpdf.Attachments.AddAttachment("Example", fileData);pdf.SaveAs("addAttachment.pdf");
using IronPdf;
using System.IO;
// Import attachment file
byte[] fileData = File.ReadAllBytes(@"path/to/file");
// Open existing PDF
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Add attachment to the PDF
pdf.Attachments.AddAttachment("Example", fileData);
pdf.SaveAs("addAttachment.pdf");
ImportsIronPdfImportsSystem.IO' Import attachment filePrivate fileData() AsByte = File.ReadAllBytes("path/to/file")' Open existing PDFPrivate pdf AsPdfDocument = PdfDocument.FromFile("sample.pdf")' Add attachment to the PDFpdf.Attachments.AddAttachment("Example", fileData)pdf.SaveAs("addAttachment.pdf")
Imports IronPdf
Imports System.IO
' Import attachment file
Private fileData() As Byte = File.ReadAllBytes("path/to/file")
' Open existing PDF
Private pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Add attachment to the PDF
pdf.Attachments.AddAttachment("Example", fileData)
pdf.SaveAs("addAttachment.pdf")
移除附件
using IronPdf;using System.Linq;// Open existing PDFPdfDocument pdf = PdfDocument.FromFile("addAttachment.pdf");// Add attachment to the PDFPdfAttachmentCollection retrieveAttachments = pdf.Attachments;// Remove attachment from PDFpdf.Attachments.RemoveAttachment(retrieveAttachments.First());pdf.SaveAs("removeAttachment.pdf");
using IronPdf;
using System.Linq;
// Open existing PDF
PdfDocument pdf = PdfDocument.FromFile("addAttachment.pdf");
// Add attachment to the PDF
PdfAttachmentCollection retrieveAttachments = pdf.Attachments;
// Remove attachment from PDF
pdf.Attachments.RemoveAttachment(retrieveAttachments.First());
pdf.SaveAs("removeAttachment.pdf");
ImportsIronPdfImportsSystem.Linq' Open existing PDFPrivate pdf AsPdfDocument = PdfDocument.FromFile("addAttachment.pdf")' Add attachment to the PDFPrivate retrieveAttachments AsPdfAttachmentCollection = pdf.Attachments' Remove attachment from PDFpdf.Attachments.RemoveAttachment(retrieveAttachments.First())pdf.SaveAs("removeAttachment.pdf")
Imports IronPdf
Imports System.Linq
' Open existing PDF
Private pdf As PdfDocument = PdfDocument.FromFile("addAttachment.pdf")
' Add attachment to the PDF
Private retrieveAttachments As PdfAttachmentCollection = pdf.Attachments
' Remove attachment from PDF
pdf.Attachments.RemoveAttachment(retrieveAttachments.First())
pdf.SaveAs("removeAttachment.pdf")
透過在多頁 PDF 文件中使用目錄,您可以顯著提升文件的易用性,並讓讀者更輕鬆地導航至文件內的特定頁面。 透過 IronPDF,您可以為 PDF 建立包含書籤的自訂大綱,為讀者提供流暢的導覽體驗。 同樣地,您可以檢索 PDF 文件中當前的書籤清單,藉此快速查看大綱的當前結構。
新增書籤
IronPDF 同時支援單層與多層書籤,讓您能完全掌控 PDF 文件大綱的詳細程度,並可根據您的特定需求及 PDF 檔案長度進行客製化調整。
using IronPdf;// Create a new PDF or edit an existing document.PdfDocument pdf = PdfDocument.FromFile("existing.pdf");// Add a bookmarkpdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0);// Add a sub-bookmarkpdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1);pdf.SaveAs("singleLayerBookmarks.pdf");
using IronPdf;
// Create a new PDF or edit an existing document.
PdfDocument pdf = PdfDocument.FromFile("existing.pdf");
// Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0);
// Add a sub-bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1);
pdf.SaveAs("singleLayerBookmarks.pdf");
ImportsIronPdf' Create a new PDF or edit an existing document.Private pdf AsPdfDocument = PdfDocument.FromFile("existing.pdf")' Add a bookmarkpdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0)' Add a sub-bookmarkpdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1)pdf.SaveAs("singleLayerBookmarks.pdf")
Imports IronPdf
' Create a new PDF or edit an existing document.
Private pdf As PdfDocument = PdfDocument.FromFile("existing.pdf")
' Add a bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfBookmark", 0)
' Add a sub-bookmark
pdf.Bookmarks.AddBookMarkAtEnd("NameOfSubBookmark", 1)
pdf.SaveAs("singleLayerBookmarks.pdf")
檢索書籤
若要檢視 PDF 文件中的現有書籤,GetAllBookmarks 工具提供了一種簡便的方法,可擷取任何指定 PDF 檔案中所有書籤的完整清單。
using IronPdf;// Load existing PDF documentPdfDocument pdf = PdfDocument.FromFile("multiLayerBookmarks.pdf");// Retrieve bookmarks listvar mainBookmark = pdf.Bookmarks.GetAllBookmarks();
using IronPdf;
// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("multiLayerBookmarks.pdf");
// Retrieve bookmarks list
var mainBookmark = pdf.Bookmarks.GetAllBookmarks();
ImportsIronPdf' Load existing PDF documentPrivate pdf AsPdfDocument = PdfDocument.FromFile("multiLayerBookmarks.pdf")' Retrieve bookmarks listPrivate mainBookmark = pdf.Bookmarks.GetAllBookmarks()
Imports IronPdf
' Load existing PDF document
Private pdf As PdfDocument = PdfDocument.FromFile("multiLayerBookmarks.pdf")
' Retrieve bookmarks list
Private mainBookmark = pdf.Bookmarks.GetAllBookmarks()
using IronPDF 管理您的 PDF 檔案可以非常簡單。 此工具提供一套全面的功能,讓您能夠管理頁面、合併或分割文件、建立大綱,以及處理附件——所有操作皆透過簡潔直觀的 C# 程式碼完成。 無論您是建立新文件,還是重新整理現有文件,IronPDF 都能讓您輕鬆產出精緻、Professional 的 PDF 檔案,這些檔案不僅易於瀏覽,也方便分享。