Edit this page
Available for: UI for ASP.NET AJAX | UI for ASP.NET MVC | UI for WPF | UI for WinForms | UI for Silverlight

Overview

The PdfPageSource class represents the page content of an existing PDF file.

Using PdfPageSource

Create an Instance

An instance of the PdfPageSource class can be obtained using the Pages property of PdfFileSource.

[C#] Example 1: Obtain an instance of PdfPageSource

using (PdfFileSource fileSource = new PdfFileSource(File.OpenRead(path)))
{
    foreach (PdfPageSource pageSource in fileSource.Pages)
    {
        // ...                  
    }
}

Members

PdfPageSource exposes the two properties to give you information about the pages - Size and Orientation.

Example 2 shows how you can use PdfPageSource to merge the pages of several documents into a single one.

[C#] Example 2: Merge the pages of several documents

// Create a PdfStreamWriter instance, responsible to write the document into the specified file
using (PdfStreamWriter fileWriter = new PdfStreamWriter(File.OpenWrite(resultFile)))
{
    // Iterate through the files you would like to merge
    foreach(string documentName in documentsToMerge)
    {
        // Open each of the files
        using (PdfFileSource fileToMerge = new PdfFileSource(File.OpenRead(documentName)))
        {
            // Iterate through the pages of the current document
            foreach(PdfPageSource pageToMerge in fileToMerge.Pages)
            {
                // Append the current page to the fileWriter, which holds the stream of the result file
                fileWriter.WritePage(pageToMerge);
            }
        }
    }
}

See Also