The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

Page Manipulation

  • 5 min to read

The topic describes the following page manipulation capabilities:

Copy pages from one document to another PDF

To copy pages:

Example

This example shows how to copy a page from one PDF document to another PDF.

Imports DevExpress.Pdf

Namespace CopyPage
    Friend Class Program
        Shared Sub Main(ByVal args() As String)

            Using source As New PdfDocumentProcessor()
                source.LoadDocument("..\..\Document1.pdf")
                Using target As New PdfDocumentProcessor()
                    target.LoadDocument("..\..\Document2.pdf")
                    target.Document.Pages.Insert(3, source.Document.Pages(0))
                    target.SaveDocument("..\..\Result.pdf")
                End Using
            End Using
        End Sub
    End Class
End Namespace

Add/Insert a new page into a document

To add a new page to the end of a document, call the PdfDocumentProcessor.AddNewPage method with the specified page size, as shown below.

To insert a new page into a document, call the PdfDocumentProcessor.InsertNewPage method with the page number where the new page should be inserted and the page size.

To save the resulting document, call the PdfDocumentProcessor.SaveDocument overload method.

The following code shows how to add a new page to a document:


using DevExpress.Pdf;

namespace PdfExample {

    class Program {
        static void Main(string[] args) {

            using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
                processor.LoadDocument("..\\..\\Document.pdf");
                processor.AddNewPage(PdfPaperSize.A4);                
                processor.SaveDocument("..\\..\\Result.pdf");         
            }
        }
    }
}

The graphics content (for example, an image or string) can be added to an existing page's foreground/background by calling the PdfGraphics.AddToPageForeground or PdfGraphics.AddToPageBackground overload method.

The PDF graphics is represented by an instance of the PdfGraphics class. To access this class, you need to reference the DevExpress.Pdf.Drawing assembly. See the Adding Graphics Content to a Page topic to learn more.

Render a new page with graphics

The PdfDocumentProcessor class contains the PdfDocumentProcessor.RenderNewPage overload methods that render a new page with graphics content.

See the PDF Graphics section to learn more about PDF Graphics.

Delete a page from a document

To delete a particular page from a document, call the PdfDocumentProcessor.DeletePage method with the number of the page that should be deleted.

Example

This example shows how to delete odd-numbered pages in the document, starting from the last odd-numbered page.

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T114310.


using DevExpress.Pdf;
// ...

    class Program {
        static void Main(string[] args) {
            using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor()) {
                pdfDocumentProcessor.LoadDocument("..\\..\\TextDelete.pdf");
                for (int i = pdfDocumentProcessor.Document.Pages.Count / 2; i >= 0; i--)
                    pdfDocumentProcessor.DeletePage(i * 2 + 1);
                pdfDocumentProcessor.SaveDocument("..\\..\\Deleted.pdf");
            }
        }
    }

Rotate a page in a document

To rotate a page at a specified angle:

Example

This example illustrates how to use the PDF Document API component to rotate pages.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/how-to-rotate-pdf-pages-t114305

using DevExpress.Pdf;

namespace PdfPageRotationExample
{

    class Program {
        static void Main(string[] args)
        {
            using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
            {
                pdfDocumentProcessor.LoadDocument("..\\..\\docs\\TextRotate.pdf");
                int angle = 0;
                foreach (PdfPage page in pdfDocumentProcessor.Document.Pages) {
                    angle = (angle + 90) % 360;
                    page.Rotate = angle;
                }
                pdfDocumentProcessor.SaveDocument("..\\..\\docs\\Rotated.pdf");
            }
        }
    }
}