Posted on
DotNetBrowser 2.4
What’s New
Printing API
The Printing API is back – improved and redesigned. Now you can print pages and documents as well as savе web pages to PDF silently from the code.
With the new Printing API you can:
- select a printer device;
- provide the required print settings such as paper size, orientation, page ranges, etc.;
- get notifications when printing is completed;
- cancel printing;
- save the currently loaded web page to a PDF document and more.
The following example demonstrates how to save the currently loaded web page as a PDF:
// Tell the Chromium engine to perform the printing programmatically.
browser.RequestPrintHandler =
    new Handler<RequestPrintParameters, RequestPrintResponse>(p =>
    {
        return RequestPrintResponse.Print();
    });
// This handler is used for printing regular web pages programmatically.
browser.PrintHtmlContentHandler 
    = new Handler<PrintHtmlContentParameters, PrintHtmlContentResponse>(p =>
    {
        string pdfFilePath = Path.GetFullPath("result.pdf");
        // Get the print job for the built-in PDF printer.
        IPrintJob<PdfPrinter.IHtmlSettings> printJob = p.Printers.Pdf.PrintJob;
        // Subscribe to its PrintCompleted event and show a message box when it's done.
        printJob.PrintCompleted += (sender, args) => 
        { 
            BeginInvoke((Action) (() => 
                { MessageBox.Show("Printing completed: \n"+pdfFilePath); }));
        };
        // Apply the necessary print settings
        printJob.Settings.Apply(s =>
        {
            // Enable printing header and footer.
            s.PrintingHeaderFooterEnabled = true;
            // Specify the path to save the result.
            s.PdfFilePath = pdfFilePath;
        });
        // Tell Chromium to use the built-in PDF printer for printing.
        return PrintHtmlContentResponse.Print(p.Printers.Pdf);
    });
// Load the web page and wait until it is loaded completely.
browser.Navigation.LoadUrl("teamdev.com").Wait();
// Initiate printing.
browser.MainFrame.Print();
.NET 5 support
DotNetBrowser is tested and proven to integrate with .NET 5 desktop applications.
Improvements
- The Print Preview dialog has been clipped off from the top of the form and positioned lower to improve user experience.
- AuthenticateParameters.Realmproperty was added to provide the realm of the authentication challenge.
Fixed issues
- Excessive CPU and GPU usage by the native process with multiple tabs with WPF BrowserViewinstances in the hardware-accelerated mode.
- WPF BrowserViewcrashing in the hardware-accelerated mode.
- Few memory leaks for registering/unregistering .NET objects via JS-.NET bridge.
- The Tab key not working properly with WPF BrowserView.
- The scrolling of a page stopping if the mouse pointer is hovered out of WPF BrowserViewcomponent in the Off-screen rendering mode.
- The focus traversal entering the infinite loop when displaying a popup.
Download DotNetBrowser 2.4
Please share your email with us, and we'll send you download instructions.
We were unable to send the email. Please try again.
If you are a registered customer you don’t need to do anything to use this update.
If you would like to evaluate the product, you need an evaluation license.
Follow @DotNetBrowser to get notified of the library updates.
Subscribe to our RSS feed to get instant updates on new releases.
Subscribe to get notifications about the latest releases.