'PrintDocument: Fit to page

I am using PdfiumViewer in order to print a PDF file:

using (PdfDocument document = PdfDocument.Load(pdfFileName))
{
    using (PrintDocument printDocument = document.CreatePrintDocument())
    {
        printDocument.BeginPrint += PrintDocument_BeginPrint;
        printDocument.EndPrint += PrintDocument_EndPrint;
        printDocument.PrintPage += PrintDocument_PrintPage;
        printDocument.QueryPageSettings += PrintDocument_QueryPageSettings;

        printDocument.PrintController = new StandardPrintController();
        printDocument.Print();
    }
}

In my printDocument BeginPrint, EndPrint, PrintPage and QueryPageSettings events I am not doing anything, only making some logs to a file.

The PDF file is printed but the left and right margins of each page of the document are being cut off so I am trying to fit each PDF document page to the current default selected paper size in the default printer. How can I do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source