This sample shows how to draw a PDF page on the drawing surface of a System.Drawing.Graphics.

Please note that resolution of a PdfPage is usually less than resolution of the drawing surface of a Graphics.

For PdfPage the resolution is usually equal to 72 DPI. The resolution of a Graphics depends on the resolution of its underlying device context or image. I.e for Graphics objects based on an image or a screen context the resolution is usually equal to 96 DPI. For Graphics objects based on a printer context the resolution is usually even bigger (e.g. 300 or 600 DPI).

It means that if you create Graphics based on a System.Drawing.Bitmap the size of the bitmap should be scaled. The scale factor is the quotient of bitmap resolution and PDFPage resolution.

This example shows how to create Graphics based on the bitmap with resolution equal to 300 DPI and draw a PdfPage on the drawing surface of that Graphics.

Drawing of PDF on a System.Drawing.Graphics is not supported in version for .NET Standard.

C#
using System.Diagnostics;
using System.Drawing;

using BitMiracle.Docotic.Pdf;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class DrawPageOnGraphics
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToImage = "DrawPageOnGraphics.png";

            using (PdfDocument pdf = new PdfDocument(@"Sample Data\jfif3.pdf"))
            {
                const float TargetResolution = 300;

                PdfPage page = pdf.Pages[0];
                double scaleFactor = TargetResolution / page.Canvas.Resolution;

                using (Bitmap bitmap = new Bitmap((int)(page.Width * scaleFactor), (int)(page.Height * scaleFactor)))
                {
                    bitmap.SetResolution(TargetResolution, TargetResolution);

                    using (Graphics gr = Graphics.FromImage(bitmap))
                        page.Draw(gr);

                    bitmap.Save(pathToImage);
                }
            }

            Process.Start(pathToImage);
        }
    }
}
VB
Imports System.Diagnostics
Imports System.Drawing

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class DrawPageOnGraphics
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToImage As String = "DrawPageOnGraphics.png"

            Using pdf As New PdfDocument("Sample Data\jfif3.pdf")
                Const TargetResolution As Single = 300

                Dim page As PdfPage = pdf.Pages(0)
                Dim scaleFactor As Double = TargetResolution / page.Canvas.Resolution

                Using bitmap As New Bitmap(CInt(page.Width * scaleFactor), CInt(page.Height * scaleFactor))
                    bitmap.SetResolution(TargetResolution, TargetResolution)

                    Using gr As Graphics = Graphics.FromImage(bitmap)
                        page.Draw(gr)
                    End Using

                    bitmap.Save(pathToImage)
                End Using
            End Using

            Process.Start(pathToImage)
        End Sub
    End Class
End Namespace