Draw into Graphics Context

  • 3 minutes to read

The PdfGraphics class contains methods (GDI+ like) that allow you to draw different shapes, lines, and images into a PDF graphics context.

Member Description
PdfGraphics.DrawLine Draws a line connecting two points on the page specified by the coordinate pairs.
PdfGraphics.DrawLines Draws a series of line segments that connect an array of PointF structures.
PdfGraphics.DrawBezier Draws a Bezier spline defined by four Point structures.
PdfGraphics.DrawBeziers Draws a series of Bezier splines from an array of PointF structures.
PdfGraphics.DrawEllipse Draws an ellipse specified by a RectangleF structure.
PdfGraphics.DrawRectangle Draws a rectangle specified by a Rectangle structure.
PdfGraphics.DrawPolygon Draws a polygon defined by an array of PointF structures.
PdfGraphics.DrawPath Draws a path on a page.
PdfGraphics.DrawString A set of overloaded methods used to draw the text string with the specified SolidBrush, Font objects and other parameters.
PdfGraphics.DrawImage Draws the specified image using the byte array or stream data at the specified location.
PdfGraphics.FillRectangle Fills the interior of a rectangle specified by a RectangleF structure.
PdfGraphics.FillPath Fills the interior of a GraphicsPath.
PdfGraphics.FillEllipse Fills the interior of an ellipse defined by a bounding rectangle specified by a RectangleF structure.
PdfGraphics.FillPolygon Fills the interior of a polygon defined by an array of points specified by PointF structures.
PdfGraphics.RotateTransform Rotates the coordinate system clockwise relative to its origin to the specified angle.
PdfGraphics.ScaleTransform Scales the coordinate system according to the specified scale factor.
PdfGraphics.TranslateTransform Translates the origin of the coordinate system to the specified point.

If you call the PdfGraphics.DrawImage method to embed multi-page TIFF images with CCITT T.4 or CCITT T.6 compression to the document, the PdfDocumentProcessor draws the first page only. Use the Image.SelectActiveFrame method to select a page that should be used.

When an image is drawn on a page using one of the overloaded PdfGraphics.DrawImage methods, the PDF Document API may produce a resulting PDF file of the large size. To reduce the size of the PDF file, use the PdfGraphics.ConvertImagesToJpeg and PdfGraphics.JpegImageQuality properties.

To customize text drawing, use the PdfGraphics.TextOrigin and PdfGraphics.UseKerning properties before calling the overloaded PdfGraphics.DrawString methods.


This example shows how to draw text lines on a page using the PdfGraphics.DrawString method.


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

static void DrawGraphics(PdfGraphics graphics) { 

    SolidBrush black = (SolidBrush)Brushes.Black; 
    using (Font font1 = new Font("Times New Roman", 32, FontStyle.Bold)) { 
                graphics.DrawString("PDF Document Processor", font1, black, 180, 150); 
    using (Font font2 = new Font("Arial", 20)) { 
                graphics.DrawString("Display, Print and Export PDF Documents", font2, black, 168, 230); 
    using (Font font3 = new Font("Arial", 10)) { 
                graphics.DrawString("The PDF Document Processor is a non-visual component " + 
                                  "that provides the application programming interface of the PDF Viewer.", font3, black, 16, 300);