Sicos1977 / ChromiumHtmlToPdf

Convert HTML to PDF with a Chromium based browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Converter Hanging

pamar1908 opened this issue · comments

Hi, I am trying to run the following but it hangs at the converting line. I have tried without specifying the executable path as well. Thanks for any help.

Using conv As New Converter("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe") Dim ps As New Settings.PageSettings(Enums.PaperFormat.A4) conv.ConvertToPdf(html_text, "C:\Users\User\Downloads\mypdf.pdf", ps) End Using

commented

Can you turn on logging and see in which steps the program failes?

Log:

2023-03-29T15:11:34.627 - Resetting Chrome arguments to default
2023-03-29T15:11:34.653 - Adding Chrome argument '--headless'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-gpu'
2023-03-29T15:11:34.653 - Adding Chrome argument '--hide-scrollbars'
2023-03-29T15:11:34.653 - Adding Chrome argument '--mute-audio'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-background-networking'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-background-timer-throttling'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-default-apps'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-extensions'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-hang-monitor'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-prompt-on-repost'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-sync'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-translate'
2023-03-29T15:11:34.653 - Adding Chrome argument '--metrics-recording-only'
2023-03-29T15:11:34.653 - Adding Chrome argument '--no-first-run'
2023-03-29T15:11:34.653 - Adding Chrome argument '--disable-crash-reporter'
2023-03-29T15:11:34.654 - Adding Chrome argument '--remote-debugging-port="0"'
2023-03-29T15:11:34.655 - Adding Chrome argument '--window-size="1366,768"'
2023-03-29T15:11:34.678 - Starting Chrome from location 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' with working directory 'C:\Program Files (x86)\Google\Chrome\Application'
2023-03-29T15:11:34.678 - "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --disable-gpu --hide-scrollbars --mute-audio --disable-background-networking --disable-background-timer-throttling --disable-default-apps --disable-extensions --disable-hang-monitor --disable-prompt-on-repost --disable-sync --disable-translate --metrics-recording-only --no-first-run --disable-crash-reporter --remote-debugging-port="0" --window-size="1366,768"
2023-03-29T15:11:34.870 - Chrome process started
2023-03-29T15:11:36.199 - Received Chrome error data: 'DevTools listening on ws://127.0.0.1:65120/devtools/browser/742f2bb3-0e88-4a02-bbff-82c678ecfc64'
2023-03-29T15:11:36.199 - Connecting to dev protocol on uri 'ws://127.0.0.1:65120/devtools/browser/742f2bb3-0e88-4a02-bbff-82c678ecfc64'
2023-03-29T15:11:36.229 - Creating new websocket connection to url 'ws://127.0.0.1:65120/devtools/browser/742f2bb3-0e88-4a02-bbff-82c678ecfc64'
2023-03-29T15:11:36.294 - Opening websocket connection with a timeout of 30 seconds
2023-03-29T15:11:36.350 - Websocket opened
2023-03-29T15:11:36.601 - Creating new websocket connection to url 'ws://127.0.0.1:65120/devtools/page/B4CBB6591C2E670EA264C595F76426F5'
2023-03-29T15:11:36.601 - Opening websocket connection with a timeout of 30 seconds
2023-03-29T15:11:36.611 - Websocket opened
2023-03-29T15:11:36.612 - Connected to dev protocol
2023-03-29T15:11:36.613 - Chrome started
2023-03-29T15:11:36.625 - Disabling caching

commented

For some reason it fails on the step Disabling caching, could you try not to disable the cache and see if that makes any difference?

How can I do this?

commented

You probably set it to false from the Constructor

        /// <summary>
        ///     Creates this object and sets it's needed properties
        /// </summary>
        /// <param name="chromeExeFileName">When set then this has to be the full path to the chrome executable.
        ///     When not set then then the converter tries to find Chrome.exe by first looking in the path
        ///     where this library exists. After that it tries to find it by looking into the registry</param>
        /// <param name="userProfile">
        ///     If set then this directory will be used to store a user profile.
        ///     Leave blank or set to <c>null</c> if you want to use the default Chrome user profile location
        /// </param>
        /// <param name="logger">When set then logging is written to this ILogger instance for all conversions at the Information log level</param>
        /// <param name="useCache">When <c>true</c> (default) then Chrome uses it disk cache when possible</param>
        /// <exception cref="FileNotFoundException">Raised when <see cref="chromeExeFileName" /> does not exists</exception>
        /// <exception cref="DirectoryNotFoundException">
        ///     Raised when the <paramref name="userProfile" /> directory is given but does not exists
        /// </exception>
        public Converter(string chromeExeFileName = null,
                         string userProfile = null,
                         ILogger logger = null,
                         bool useCache = true)
        {
commented

Or you called the methode

        #region ResetChromeArguments
        /// <summary>
        ///     Resets the <see cref="DefaultChromeArguments" /> to their default settings
        /// </summary>
        public void ResetChromeArguments()
        {
            WriteToLog("Resetting Chrome arguments to default");

            _defaultChromeArgument = new List<string>();
            AddChromeArgument("--headless");
            AddChromeArgument("--disable-gpu");
            AddChromeArgument("--hide-scrollbars");
            AddChromeArgument("--mute-audio");
            AddChromeArgument("--disable-background-networking");
            AddChromeArgument("--disable-background-timer-throttling");
            AddChromeArgument("--disable-default-apps");
            AddChromeArgument("--disable-extensions");
            AddChromeArgument("--disable-hang-monitor");
            AddChromeArgument("--disable-prompt-on-repost");
            AddChromeArgument("--disable-sync");
            AddChromeArgument("--disable-translate");
            AddChromeArgument("--metrics-recording-only");
            AddChromeArgument("--no-first-run");
            AddChromeArgument("--disable-crash-reporter");
            AddChromeArgument("--remote-debugging-port", "0");

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                WriteToLog("Detected Linux operating system, adding the parameter '--no-sandbox'");
                AddChromeArgument("--no-sandbox");
            }

            SetWindowSize(WindowSize.HD_1366_768);
            _useCache = false;
        }
        #endregion
commented

I just released a new nuget package, please check if that fixes your issue

The new package cannot be installed due to the following:

Unable to find a version of 'AngleSharp' that is compatible with 'AngleSharp.Css 0.17.0 constraint: AngleSharp (>= 0.17.0 && < 0.18.0)', 'HtmlSanitizer 8.0.645 constraint: AngleSharp (= 0.17.1)'.

commented

Weird, I did not get any errors when building the package... have to look into that.

commented

Should be fixed in 2.6.9 ... there was a dependency problem between the AngleSharp packages

commented

And?

Sorry we had some IT disaster today. Thank you very much for the releases. Unfortunately, it is still hanging at Enabling/Disabling Cashing (depending on setting).

@Sicos1977 Did you find anything under the hood creating this issue? Is this happening only to me?

commented

Can you try and use normale Chrome (not the portabble version) and see if that makes any difference.

I am not using the portable version. I have Chrome normally installed on my Windows PC. I specified the exe path just because it was hanging and initially thought that it couldn't find Chrome's path

commented

Ow... are u using Chrome from a windows service and is that service user running under local system?

Yes I am trying it locally on my PC.

commented

Try running the Windows Service under another user... I had a simular problem when I did the same.

I am not running it as a Windows Service. I am running a Windows Forms app. I have also tried on another PC without any luck.

Did you find any reason why I might be getting the cashing error? Any way to bypass this? I have tried portable Chrome and it does the same