Back to Devexpress

PdfGraphics.DrawPageContent(PdfPage) Method

officefileapi-devexpress-dot-pdf-dot-pdfgraphics-dot-drawpagecontent-x28-devexpress-dot-pdf-dot-pdfpage-x29.md

latest5.6 KB
Original Source

PdfGraphics.DrawPageContent(PdfPage) Method

Draws the specified page content.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public void DrawPageContent(
    PdfPage source
)
vb
Public Sub DrawPageContent(
    source As PdfPage
)

Parameters

NameTypeDescription
sourcePdfPage

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.AddToPageBackgroundThese methods allow you to draw content on an existing page.PdfDocumentProcessor.RenderNewPageDraws content on a new page.

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

csharp
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.CreateGraphicsWorldSystem()) {
            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);
        }
        processor.SaveDocument("out2.pdf");
    }
}
vb
Imports DevExpress.Pdf
Imports System.Drawing
'...

Using processor As New PdfDocumentProcessor()
    processor.CreateEmptyDocument()
    Dim page As PdfPage = processor.AddNewPage(PdfPaperSize.A4Rotated)
    Using processor2 As New PdfDocumentProcessor()
        processor2.LoadDocument("FirstLook.pdf")

        Using graphics As PdfGraphics = processor.CreateGraphicsWorldSystem()
            graphics.SaveGraphicsState()

            ' Obtain the first document page's boundaries.
            Dim clip As PdfRectangle = processor2.Document.Pages(0).CropBox

            ' Resize the source page content to fit half of the target page.
            graphics.ScaleTransform(CSng((page.CropBox.Width \ 2) \ clip.Width), CSng((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(CSng(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(CSng(page.CropBox.Width \ clip.Width \ 2), CSng(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)
        End Using
        processor.SaveDocument("out2.pdf")
    End Using
End Using

See Also

PdfGraphics Class

PdfGraphics Members

DevExpress.Pdf Namespace