DotNetBrowser API allows providing custom print settings on each print request. To provide custom print settings you must register your own implementation of the PrintHandler interface using the Browser.PrintHandler property. When Browser instance or JavaScript on the web page requests printing, the PrintHandler.OnPrint(PrintJob printJob) method will be invoked. In this method you can modify default print settings.


Custom implementation:

 C#

class MyPDFPrintHandler : PrintHandler
{
    Func<PrintSettings, PrintSettings> func;

    public MyPDFPrintHandler(Func<PrintSettings, PrintSettings> func)
    {
        this.func = func;
    }

    public PrintStatus OnPrint(PrintJob printJob)
    {
        PrintSettings printSettings = func(printJob.PrintSettings);
        printSettings.PrintToPDF = true;
        printSettings.Landscape = true;
        printSettings.PrintBackgrounds = true;
        printSettings.PageMargins = new PageMargins(20, 40, 40, 20);
        return PrintStatus.CONTINUE;
    }
}


VB.NET

Class MyPDFPrintHandler
    Implements PrintHandler

    Dim func As Func(Of PrintSettings, PrintSettings)

    public Sub New(func As Func( Of PrintSettings, PrintSettings))
        Me.func = func
    End Sub

    Public Function OnPrint(printJob As PrintJob) As PrintStatus Implements PrintHandler.OnPrint
        Dim printSettings As PrintSettings = func(printJob.PrintSettings)
        printSettings.PrintToPDF = True
        printSettings.Landscape = True
        printSettings.PrintBackgrounds = True
        printSettings.PageMargins = New PageMargins(20, 40, 40, 20)
        Return PrintStatus.CONTINUE
    End Function
End Class



Replacing current PrintHandler with the new one:

C#

browserView.Browser.PrintHandler = new MyPDFPrintHandler((printSettings) =>
        {
            printSettings.PDFFilePath = dlg.FileName;
            return printSettings;
        });


VB.NET

browserView.Browser.PrintHandler = New MyPDFPrintHandler(Function(printSettings)
    printSettings.PDFFilePath = dlg.FileName
    Return printSettings
End Function)