How to Organize your PDFs in C#

IronPDF offers a comprehensive set of tools beyond its PDF generation capabilities, some of which can be utilized to organize the structure of your PDF document. Never before has it been easier to edit the structure of your PDF. Manipulate the structure of your PDF, add bookmarks and attachments, and create the ideal PDF layout all with the one library. With IronPDF, you'll never have to struggle with PDF organization again.

In this comprehensive tutorial, we'll explore how you can use IronPDF to organize your PDF documents better. To do this, we'll walk you through some basic examples of how these organizational features work, examining code examples and their corresponding explanations. By the end of this article, you'll be ready to dive right into using IronPDF for your PDF organization needs.

Table of Contents

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer
NuGet Install with NuGet

PM >  Install-Package IronPdf

Check out IronPDF on NuGet for quick installation. With over 10 million downloads, it’s transforming PDF development with C#. You can also download the DLL or Windows installer.

Organize your PDF Structure

Let's first take a look at some of the features IronPDF has to offer to help you take control of your PDF file's structure. Using these tools, you can easily manipulate the pages within your PDF document and control their positioning.

Manage your PDF Pages

Add new content to your PDF documents by adding new pages, deleting unnecessary pages from your files, and even copying specific pages to create duplicates. By manipulating the pages within your PDF, you can easily restructure the PDF to fit your needs.

Add Pages

Add a new page to your PDF in just a few lines of code. With IronPDF, adding new content to your PDF files is a breeze.

:path=/static-assets/pdf/content-code-examples/how-to/add-copy-delete-pages-pdf-add.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");
Imports IronPdf

' Import cover page
Private coverPage As PdfDocument = PdfDocument.FromFile("coverPage.pdf")

' Import content document
Private contentPage As PdfDocument = PdfDocument.FromFile("contentPage.pdf")

' Merge the two documents
Private finalPdf As PdfDocument = PdfDocument.Merge(coverPage, contentPage)

finalPdf.SaveAs("pdfWithCover.pdf")
$vbLabelText   $csharpLabel

This method simplifies the process of adding new pages. To add a new page at a specific index within a multi-paged PDF document, you can easily achieve this using the InsertPdf method:

:path=/static-assets/pdf/content-code-examples/how-to/add-copy-delete-pages-pdf-insert.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);
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)
$vbLabelText   $csharpLabel

Copy Pages

By copying pages within your PDF document, you can easily maintain a consistent style and transfer information across multiple PDF files. IronPDF's CopyPage and CopyPages methods offer a simple way to duplicate specific pages in your PDFs with just a few lines of code.

:path=/static-assets/pdf/content-code-examples/how-to/add-copy-delete-pages-pdf-copy.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 });
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})
$vbLabelText   $csharpLabel

Delete Pages

To delete specific pages from your PDF, you can use the RemovePage and RemovePages methods, allowing you to programmatically remove unwanted pages from your documents.

:path=/static-assets/pdf/content-code-examples/how-to/add-copy-delete-pages-pdf-delete.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 });
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})
$vbLabelText   $csharpLabel

For a more detailed explanation of the code snippets above and to explore its additional functionality, please refer to our comprehensive how-to guide.

Merge or Split PDFs

Merge PDFs

Combine multiple PDF documents into a single, easy-to-share PDF using IronPDF's merge tool. This feature is particularly useful when you want to group similar documents for easier distribution, merge individual pages into a new PDF, or carry out various other PDF merging tasks. With IronPDF's merge tool, you can automate this process effortlessly by utilizing the Merge method.

:path=/static-assets/pdf/content-code-examples/how-to/merge-or-split-pdfs-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");
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")
$vbLabelText   $csharpLabel

Split PDFs

Just as you might want to merge multiple PDFs into one singular, easy-to-share PDF document, there might also be times when you want to split a multipage PDF file into separate documents.

:path=/static-assets/pdf/content-code-examples/how-to/merge-or-split-pdfs-split.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");
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")
$vbLabelText   $csharpLabel

For a more detailed explanation of the code snippets above and to explore its additional functionality, please refer to our comprehensive how-to guide.

Split Multipage PDF

To split multipage PDFs, we will follow a similar approach to splitting single-page PDFs. In this case, we will use a for loop to accomplish the task.

: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 a more detailed explanation of the code snippet above and to explore its additional functionality, please refer to our comprehensive how-to guide.

Organization Tools

In this section, we will closely examine some of the tools that IronPDF provides to improve the organization of your PDF documents. By utilizing these tools, you can enhance your PDF documents, making it easier for readers to navigate through multipage content.

Add & Remove Attachments

Enhance your PDF file by linking supporting documents, related content, and more through attachments. By including additional materials, data, and images on specific pages, you can avoid cluttering the document with extra pages, making it easier to navigate. With IronPDF, you can effortlessly add or remove attachments, ensuring your PDF remains relevant and streamlined.

Add Attachments

:path=/static-assets/pdf/content-code-examples/how-to/add-remove-attachments-add-attachment.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");
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")
$vbLabelText   $csharpLabel

Remove Attachments

:path=/static-assets/pdf/content-code-examples/how-to/add-remove-attachments-remove-attachment.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");
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")
$vbLabelText   $csharpLabel

For a more detailed explanation of the code snippets above and to explore its additional functionality, please refer to our comprehensive how-to guide.

Outlines & Bookmarks

By using outlines in your multipage PDF documents, you can significantly enhance the document's usability and make it easier for readers to navigate to specific pages within it. With IronPDF, you can create a customized outline for your PDF, complete with bookmarks, to provide a seamless navigation experience for your readers. Likewise, you can retrieve a list of the current bookmarks within your PDF, allowing you to view the current structure of your outline quickly.

Add Bookmarks

IronPDF supports both single-layer and multi-layer bookmarks, providing complete control over the level of detail in your PDF document outline, tailored to your specific needs and the length of the PDF file.

:path=/static-assets/pdf/content-code-examples/how-to/bookmarks-single-layer-bookmark.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");
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")
$vbLabelText   $csharpLabel

Retrieve Bookmarks

To examine the existing bookmarks within your PDF document, the GetAllBookmarks tool provides a straightforward way to retrieve a comprehensive list of all bookmarks present in any given PDF file.

:path=/static-assets/pdf/content-code-examples/how-to/bookmarks-retrieve-bookmark.cs
using IronPdf;

// Load existing PDF document
PdfDocument pdf = PdfDocument.FromFile("multiLayerBookmarks.pdf");

// Retrieve bookmarks list
var 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()
$vbLabelText   $csharpLabel

For a more detailed explanation of the code snippets above and to explore its additional functionality, please refer to our comprehensive how-to guide.

Conclusion

Managing your PDFs can be straightforward with IronPDF. This tool provides a comprehensive set of features that enable you to manage pages, merge or split documents, create outlines, and handle attachments—all with clean and straightforward C# code. Whether you're creating a new document or restructuring an existing one, IronPDF makes it easy to produce polished, professional PDFs that are easy to navigate and share.

If you have questions about IronPDF or want to request a feature, please reach out to our support team. We are more than happy to assist you.

Kye Stuart
Technical Writer

Kye Stuart merges coding passion and writing skill at Iron Software. Educated at Yoobee College in software deployment, they now transform complex tech concepts into clear educational content. Kye values lifelong learning and embraces new tech challenges.

Outside work, they enjoy PC gaming, streaming on Twitch, and outdoor activities like gardening and walking their dog, Jaiya. Kye’s straightforward approach makes them key to Iron Software’s mission to demystify technology for developers globally.