Sicos1977 / ChromiumHtmlToPdf

Convert HTML to PDF with a Chromium based browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Upgrading To Newer Version Breaks When Using Chrome

sangeethnandakumar opened this issue · comments

I loved this library and developed a FinanceProcessor app last year which converts HTML to PDF.
It worked like a charm. Code below:

image

Problem Statement

Above was last year's code.

I ran it today and worked well. (THIS MEANS OLD LIB WORKS PERFECTLY TODAY WITH CURRENT SETUP)

While upgrading my last year's app from .NET 6 to .NET 8 I thought to update the libraries also. That's when I decided to upgrade ChromeHtmlToPDF to the recent version

image

After this I just modified the classes to use new ones mentioned in ReadMe in this repo, however, it failed without giving me any info to troubleshoot or identify why.

Runs on Windows, This is a desktop app built on .NET Core WinForms (not .NET Framework)

image

Any idea @Sicos1977 ?
Do you need any further info?

Chrome Info

image

commented

Try using the old headless mode. By default the library now uses the new headless mode but for unknown reasons to me this sometimes just doesn't work.

commented
    /// <summary>
    ///     By default the Chromium based browser is started with the <c>--headless=new</c> argument.
    ///     If you don't want this then set this property to <c>true</c>
    /// </summary>
    /// <remarks>
    ///     https://developer.chrome.com/articles/new-headless/
    /// </remarks>
    public bool UseOldHeadlessMode
    {
        get => !_defaultChromiumArgument.Contains("--headless=new");
        set
        {
            for (var i = 0; i < _defaultChromiumArgument.Count; i++)
            {
                if (!_defaultChromiumArgument[i].StartsWith("--headless")) continue;
                _defaultChromiumArgument[i] = value ? "--headless" : "--headless=new";
                return;
            }
        }
    }
    #endregion

Hi @Sicos1977, Thank you for pointing it out. If this could be added somewhere in Doc it'll be very helpful