### Install Chrome on Linux Ubuntu Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Follow these steps to install the stable version of Google Chrome on Ubuntu. Ensure you have administrative privileges. ```bash wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - ``` ```bash sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' ``` ```bash sudo apt-get update ``` ```bash sudo apt-get install google-chrome-stable ``` ```bash google-chrome --version ``` ```bash google-chrome --no-sandbox --user-data-dir ``` -------------------------------- ### Install Chrome HTML to PDF via Scoop Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Use this command to install the Chrome HTML to PDF tool using the scoop package manager. Ensure you have scoop installed and configured. ```powershell scoop install https://gist.githubusercontent.com/arnos-stuff/4f9b2d92d812b25d0ee8335c543cba78/raw/cfa861ab3078a20c69157ab45daf33f26005fd63/chrome-html-to-pdf.json ``` -------------------------------- ### ChromiumHtmlToPdf Console App Usage Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Example of how to use the ChromiumHtmlToPdf console application to convert a URL to a PDF file. Ensure .NET 8.0 is installed. ```bash ChromiumHtmlToPdf --input https://www.google.nl --output c:\google.pdf ``` -------------------------------- ### Install Chrome Stable and Dependencies in Docker Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Installs Google Chrome Stable and its dependencies within a Docker environment. It purges unnecessary packages like curl and gnupg afterwards. ```Dockerfile ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn ENV DEBIAN_FRONTEND noninteractive RUN apt-get update && apt-get install -y apt-transport-https ca-certificates curl gnupg --no-install-recommends && curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && apt-get update && apt-get install -y google-chrome-stable --no-install-recommends && apt-get purge --auto-remove -y curl gnupg && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### Install Chrome Driver in Docker Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Downloads and installs the Chrome Driver executable within a Docker container. Ensure the version matches your Chrome browser version. ```Dockerfile RUN apt-get update && \ apt-get install -y unzip && \ wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip && \ unzip chromedriver_linux64.zip && \ mv chromedriver /usr/bin && rm -f chromedriver_linux64.zip ``` -------------------------------- ### Convert URL to PDF from Command Line Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Use the ChromiumHtmlToPdfConsole application to convert a URL to a PDF file directly from the command line. The exit code 0 indicates success, while 1 indicates an error. ```bash ChromiumHtmlToPdfConsole --input https://www.google.com --output c:\google.pdf ``` -------------------------------- ### Convert URL to PDF using C# Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Use this method to convert a given URL to a PDF file. Ensure the PageSettings object is properly initialized. The PDF file is automatically opened after conversion. ```csharp var pageSettings = new PageSettings() using (var converter = new Converter()) { converter.ConvertToPdf(new Uri("http://www.google.nl"), @"c:\google.pdf", pageSettings); } // Show the PDF System.Diagnostics.Process.Start(@"c:\google.pdf"); ``` -------------------------------- ### Configure ChromiumHtmlToPdf Logging Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md This C# code snippet demonstrates how to set up logging for ChromiumHtmlToPdfLib using the ILogger interface. It shows how to instantiate either a Console logger or a Stream logger for file output. ```csharp var logger = !string.IsNullOrWhiteSpace() ? new ChromiumHtmlToPdfLib.Loggers.Stream(File.OpenWrite()) : new ChromiumHtmlToPdfLib.Loggers.Console(); ``` -------------------------------- ### Convert URL to PDF asynchronously using C# Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md This asynchronous method allows for converting a URL to a PDF without blocking the main thread. The PDF file is automatically opened after conversion. ```csharp var pageSettings = new PageSettings() using var converter = new Converter(); await converter.ConvertToPdfAsync(new Uri("http://www.google.nl"), @"c:\google.pdf", pageSettings); // Show the PDF System.Diagnostics.Process.Start(@"c:\google.pdf"); ``` -------------------------------- ### Manage Chrome Instance IDs in C# Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md This class manages unique instance IDs for Chrome, ensuring each running instance has its own cache directory to avoid conflicts. It uses a concurrent stack to efficiently allocate and release IDs. ```csharp public static class InstanceId { #region Fields private static readonly ConcurrentStack ConcurrentStack; #endregion #region Constructor static InstanceId() { ConcurrentStack = new ConcurrentStack(); for(var i = 100000; i > 0; i--) ConcurrentStack.Push(i.ToString().PadLeft(6, '0')); } #endregion #region Pop /// /// Returns an instance id and pops it from the /// /// public static string Pop() { if (ConcurrentStack.TryPop(out var instanceId)) return instanceId; throw new Exception("Instance id stack is empty"); } #endregion #region Push /// /// Pushes the back on top of the /// /// public static void Push(string instanceId) { ConcurrentStack.Push(instanceId); } #endregion } ``` -------------------------------- ### Add --no-sandbox Argument in C# Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Use this argument when running in environments where Chrome might not have access to a full sandbox, such as certain Docker configurations. It is set by default on Linux. ```csharp converter.AddChromiumArgument("--no-sandbox") ``` -------------------------------- ### Add --disable-dev-shm-usage Argument in C# Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Use this argument when running in Docker containers with limited /dev/shm partition size. This prevents Chrome from using the /dev/shm partition, which can cause crashes. ```csharp converter.AddChromiumArgument("--disable-dev-shm-usage") ``` -------------------------------- ### Enable Chromium Debug Logging in C# Source: https://github.com/sicos1977/chromiumhtmltopdf/blob/master/README.md Enable this property to save Chromium's debug log to 'chrome_debug.log' in Chrome's user data directory. Logs are overwritten on each restart. Alternatively, set the CHROME_LOG_FILE environment variable for a custom log location. ```csharp /// /// Enables Chromium logging;
/// - The output will be saved to the file chrome_debug.log in Chrome's user data directory
/// - Logs are overwritten each time you restart chrome
///
/// /// If the environment variable CHROME_LOG_FILE is set, Chrome will write its debug log to its specified location.
/// Example: Setting CHROME_LOG_FILE to "chrome_debug.log" will cause the log file to be written to the Chrome process's
/// current working directory while setting it to "D:\\chrome_debug.log" will write the log to the root of your computer's D: drive. ///
public bool EnableChromiumLogging { get; set; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.