Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, we explore the process of adding, copying, and deleting pages in PDF files using the Iron PDF library in C#. We begin by installing Iron PDF through the NuGet package manager, followed by configuring the license key for its functionality. The tutorial demonstrates importing a cover page and a content document, merging them into a single PDF, and saving the result. We then cover inserting a cover page at the start of a document using the insert PDF method. Copying pages is next, with instructions on copying a single page or multiple pages from an existing PDF into a new document. The tutorial also explains the removal of pages using the remove page and remove pages methods, allowing for the deletion of specific pages. Throughout the tutorial, confirmation messages are printed to the console to indicate successful operations. By the end of the tutorial, viewers will be able to manipulate PDF documents efficiently, enhancing their document management capabilities. A call to action encourages viewers to subscribe for more tutorials and to try Iron PDF by signing up for a trial via a provided link.
// Ensure you have installed the IronPDF NuGet package, and replace "your-license-key" with your actual license key.
using IronPdf;
using System;
class PdfManipulationTutorial
{
static void Main()
{
// Register your IronPDF license key
IronPdf.License.LicenseKey = "your-license-key";
// Load the cover page and content document
var coverPage = PdfDocument.FromFile("cover.pdf");
var contentDocument = PdfDocument.FromFile("content.pdf");
// Merge the cover page and content document into a single PDF file
var mergedDocument = PdfDocument.Merge(coverPage, contentDocument);
Console.WriteLine("Successfully merged cover and content into a single PDF.");
// Save the merged PDF to a file
mergedDocument.SaveAs("mergedDocument.pdf");
// Insert the cover page at the start of the content document
contentDocument.InsertPdf(coverPage, 0);
Console.WriteLine("Inserted cover page at the start of the content document.");
// Save the new arrangement to a file
contentDocument.SaveAs("contentWithCover.pdf");
// Copy a single page from the content document and save it as a new document
var singlePageCopy = contentDocument.CopyPage(1);
singlePageCopy.SaveAs("singlePageCopy.pdf");
Console.WriteLine("Copied page 1 to a new PDF document.");
// Remove a specific page from the content document
contentDocument.RemovePage(1);
Console.WriteLine("Removed page 1 from the document.");
// Save the document after removing a page
contentDocument.SaveAs("contentWithoutPage1.pdf");
// Example of copying multiple pages and saving
var multiplePagesCopy = contentDocument.CopyPages(new int[] { 2, 3 });
multiplePagesCopy.SaveAs("multiplePagesCopy.pdf");
Console.WriteLine("Copied pages 2 and 3 to a new PDF document.");
// Example of removing specific pages
contentDocument.RemovePages(new int[] { 2, 3 });
Console.WriteLine("Removed pages 2 and 3 from the document.");
// Save the document after removing the pages
contentDocument.SaveAs("finalDocument.pdf");
}
}
// Ensure you have installed the IronPDF NuGet package, and replace "your-license-key" with your actual license key.
using IronPdf;
using System;
class PdfManipulationTutorial
{
static void Main()
{
// Register your IronPDF license key
IronPdf.License.LicenseKey = "your-license-key";
// Load the cover page and content document
var coverPage = PdfDocument.FromFile("cover.pdf");
var contentDocument = PdfDocument.FromFile("content.pdf");
// Merge the cover page and content document into a single PDF file
var mergedDocument = PdfDocument.Merge(coverPage, contentDocument);
Console.WriteLine("Successfully merged cover and content into a single PDF.");
// Save the merged PDF to a file
mergedDocument.SaveAs("mergedDocument.pdf");
// Insert the cover page at the start of the content document
contentDocument.InsertPdf(coverPage, 0);
Console.WriteLine("Inserted cover page at the start of the content document.");
// Save the new arrangement to a file
contentDocument.SaveAs("contentWithCover.pdf");
// Copy a single page from the content document and save it as a new document
var singlePageCopy = contentDocument.CopyPage(1);
singlePageCopy.SaveAs("singlePageCopy.pdf");
Console.WriteLine("Copied page 1 to a new PDF document.");
// Remove a specific page from the content document
contentDocument.RemovePage(1);
Console.WriteLine("Removed page 1 from the document.");
// Save the document after removing a page
contentDocument.SaveAs("contentWithoutPage1.pdf");
// Example of copying multiple pages and saving
var multiplePagesCopy = contentDocument.CopyPages(new int[] { 2, 3 });
multiplePagesCopy.SaveAs("multiplePagesCopy.pdf");
Console.WriteLine("Copied pages 2 and 3 to a new PDF document.");
// Example of removing specific pages
contentDocument.RemovePages(new int[] { 2, 3 });
Console.WriteLine("Removed pages 2 and 3 from the document.");
// Save the document after removing the pages
contentDocument.SaveAs("finalDocument.pdf");
}
}
Further Reading: How to Add, Copy, and Delete Pages in PDFs