List icon 目录

发布日期 2021年03月02日

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.Realm property 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 BrowserView instances in the hardware-accelerated mode.
  • WPF BrowserView crashing 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 BrowserView component in the Off-screen rendering mode.
  • The focus traversal entering the infinite loop when displaying a popup.

Request evaluation license
Download DotNetBrowser 2.4 (.NET Framework)
Download DotNetBrowser 2.4 (.NET Core)

Go Top