Skip to main content
All docs
V23.2

PdfGraphics.DrawPageContent(PdfPage) Method

Draws the specified page content.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v23.2.Drawing.dll

NuGet Package: DevExpress.Pdf.Drawing

Declaration

public void DrawPageContent(
    PdfPage source
)

Parameters

Name Type Description
source PdfPage

The source page from which content is drawn.

Remarks

Use this method to add page content to a document.

To draw page content on the PDF page, use one of the following methods:

PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackground
These methods allow you to draw content on an existing page.
PdfDocumentProcessor.RenderNewPage
Draws content on a new page.

The code sample below scales source content of two document pages and draws these pages in a landscape page.

Draw Two Pages in a Landscape Page

using DevExpress.Pdf;
using System.Drawing;
//...

using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
    processor.CreateEmptyDocument();
    PdfPage page = processor.AddNewPage(PdfPaperSize.A4Rotated);
    using (PdfDocumentProcessor processor2 = new PdfDocumentProcessor()) {
        processor2.LoadDocument(@"FirstLook.pdf");

        using (PdfGraphics graphics = processor.CreateGraphics()) {
            graphics.SaveGraphicsState();

            // Obtain the first document page's boundaries.
            PdfRectangle clip = processor2.Document.Pages[0].CropBox;

            // Resize the source page content to fit half of the target page.
            graphics.ScaleTransform((float)((page.CropBox.Width / 2) / clip.Width), (float)((page.CropBox.Width / 2) / clip.Width));

            // Draw the content of the first document page.
            graphics.DrawPageContent(processor2.Document.Pages[0]);
            graphics.RestoreGraphicsState();

            // Define the position to insert the second page content to the target page.
            graphics.SaveGraphicsState();
            graphics.TranslateTransform((float)(page.CropBox.Width / 2), 0);

            // Obtain the second document page's boundaries.
            clip = processor2.Document.Pages[1].CropBox;

            // Resize the source page content to fit half of the target page.
            graphics.ScaleTransform((float)(page.CropBox.Width / clip.Width / 2), (float)(page.CropBox.Width / clip.Width / 2));

            // Draw the content of the second document page.
            graphics.DrawPageContent(processor2.Document.Pages[1]);
            graphics.RestoreGraphicsState();

            // Add graphics content to the target page.
            graphics.AddToPageForeground(page, 72, 72);
        }
        processor.SaveDocument("out2.pdf");
    }
}
See Also