Sicos1977/ChromiumHtmlToPdf

Running from docker throws exception

zhengfu1229 opened this issue · 6 comments

Hi,

I have a .net core project that is using ChromeHtmlToPdf. It works fine locally on windows. But it throws "no process is associated with this object" exception when running from docker container (which is linux based image).

The code is below:

var localPath = System.AppDomain.CurrentDomain.BaseDirectory + "testpage.html";
converter.ConvertToPdf(new ConvertUri(localPath), output, setting);

Does the project support docker?

Sorry for the late respone but I never tested this project in a docker container. ChromeHtmlToPdf should run on Linux so it should be possible to run it in a docker container.

It run in docker good.
You need to install Google browser.
This installation command works for me:

# Suppress an apt-key warning about standard out not being a terminal. Use in this script is safe.
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=DontWarn

# export DEBIAN_FRONTEND="noninteractive"
ENV DEBIAN_FRONTEND noninteractive

# Install deps + add Chrome Stable + purge all the things
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/*

# Chrome Driver
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

You may need to set google chrome args in your code:

using (var converter = new Converter())
{
       converter.AddChromeArgument("--no-sandbox");
       converter.ConvertToPdf(new ConvertUri(url), @".\Output\output.pdf", new PageSettings());
}

Thanks for adding this

Hello, can you provide full dockerfile for building the application?

Thanks very much