Attach a Cover Page

When working with PDF documents, adding a cover page provides a method for increasing the visual appeal of the PDF itself. It gives developers like yourself a space to add branding to the PDF, or simply attract more readers with a cover page that stands out. IronPDF makes it easy to add cover pages to your PDFs in just a couple of lines of code, thanks to its merge tool.

5 Steps to Adding Cover Pages to Your PDFs

using IronPdf;

// Step 1: Create a PDF renderer
var renderer = new ChromePdfRenderer();

// Step 2: Render HTML for the cover page
var cover = renderer.RenderHtmlAsPdf("<h1>This is a Cover Page</h1>");

// Step 3: Set rendering options
// Make page numbering start from 2 for the main content
renderer.RenderingOptions.FirstPageNumber = 2;

// Step 4: Render the main PDF content from a URL
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/");

// Step 5: Insert the cover page at the beginning of the PDF
pdf.InsertPdf(cover, 0);

// Save the combined PDF document
// Save the final merged PDF document to the specified file location
pdf.SaveAs("combined.pdf");
using IronPdf;

// Step 1: Create a PDF renderer
var renderer = new ChromePdfRenderer();

// Step 2: Render HTML for the cover page
var cover = renderer.RenderHtmlAsPdf("<h1>This is a Cover Page</h1>");

// Step 3: Set rendering options
// Make page numbering start from 2 for the main content
renderer.RenderingOptions.FirstPageNumber = 2;

// Step 4: Render the main PDF content from a URL
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/");

// Step 5: Insert the cover page at the beginning of the PDF
pdf.InsertPdf(cover, 0);

// Save the combined PDF document
// Save the final merged PDF document to the specified file location
pdf.SaveAs("combined.pdf");
Imports IronPdf

' Step 1: Create a PDF renderer
Private renderer = New ChromePdfRenderer()

' Step 2: Render HTML for the cover page
Private cover = renderer.RenderHtmlAsPdf("<h1>This is a Cover Page</h1>")

' Step 3: Set rendering options
' Make page numbering start from 2 for the main content
renderer.RenderingOptions.FirstPageNumber = 2

' Step 4: Render the main PDF content from a URL
Dim pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/")

' Step 5: Insert the cover page at the beginning of the PDF
pdf.InsertPdf(cover, 0)

' Save the combined PDF document
' Save the final merged PDF document to the specified file location
pdf.SaveAs("combined.pdf")
$vbLabelText   $csharpLabel

For today's example, we will be converting an HTML string to PDF; however, you can load in an existing PDF document that contains the cover page you want to attach to your PDF file. To do this, we must create a new ChromePdfRenderer object. This class handles HTML to PDF conversion, allowing you to render pixel-perfect PDF documents from HTML, CSS, and JavaScript content.

Then, we create our cover page by rendering our HTML string to PDF format using RenderHtmlAsPdf. If you're working with a pre-existing PDF document as your cover, you would need to load in your PDF using PdfDocument.FromFile. Next, we configure the renderer with custom rendering options. We set the first-page number to 2, which ensures that when we render our main PDF document, the page numbering will start at 2 instead of the default (1).

Next, we need to render our main PDF. Here, we are rendering web content from a URL into a PDF document. At this point, we have two PDF objects, one containing our PDF cover and the second containing our PDF from the URL.

Now, it's time to attach our cover page to our core PDF document. We can do this in just one easy line of code. InsertPdf(cover, 0) inserts the cover PDF at page index 0, which is the beginning of the PDF document. Now, the pdf object is one PDF document that contains the cover page and the URL content. Then, using SaveAs, we save the final merged PDF document to the specified file location.

Click here to view the How-to Guide, including examples, sample code, and files >