-
-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSS and Images not loading(in Docker) #66
Comments
Can you check if you get these lines in your logging;
You should get them in these order and that way you know if the full page has been loaded |
Not even close, do I maybe missing logging level or something?
|
Ow you are using this method Never realised that using the As a temporary workaround you could save your html to a file and load this through the |
Yes, I forgot to mention that. I tested it now with In development still doesn't load CSS and images but I believe that has to do something with concurrent connections because on production it is working like a charm. Thanks for the help and I will keep an eye on a fix for direct HTML injection, I just find that as a more elegant solution. Now I am saving it to a file and deleting it after PDF creation. Thanks again! |
I'm already changing the code... just it is not that much work but just never realised people would use the setcontent method to load css and things like that. |
I just released a new nuget package .26 ... can you try that one and see if it will work as expected when setting the html the way you did it before? Just curious, for what are you use ChromeHtmlTopdf? |
I think it is not working properly it is stuck on Tested on both dev(5min+ just loading) and prod(after 1 min I get a timeout from the server as expected from configuration) env I am using it to generate a webshop order confirmation Let me know if I can provide some additional information |
Can you provide me your logging? |
Full log is below:
|
Is it possible to sent me the html you are using so that I can try it myself? If so then please sent it to sicos2002@hotmail.com |
I just sent it |
Thanks will look into it to see why it hangs |
Thanks, if you need anything just let me know |
I think that you get a timeout because you did not set a base url in the html content so Chrome does not know from where to get the css files ... can you try to add this --> base href (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base) |
If I add this in your html then everything seems to be working as expected when using an HTML string as input --> So my guess is right, Chrome does not know where to get the media and css files and probably just tries to load them from working directory |
I think 2.5.27 fixes your latest issue, when using setDocumentContent some events are not fired that I used to see if the page is fully loaded. Could you try this version and see if it works now? |
I get exception forgot to delete debug code here 😃 |
:-) ... oops... will fix that :-) |
2.5.28 |
Yes! The third time is a charm 😄 All working as it should, to be honest, can't believe that base is making problems as we are passing absolute URL, but okay. |
I don't think that was the problem.. just a wrong assumption from me :-) ... before I figured out that Chome was not firing the Page.Navigated event... but thanks for making this issue because it made ChromeHtmlToPdf better because never thought about adding the page loading logic to the setDocumentContent method. |
Also I liked the shop you build, it is running very fast even from the Neterlands... if I did read the info on the webpage correctly you are from Croatia? .... Netherlands overhere. |
Aha okay, no problem, thank you for providing this great library and maintaining it I am using it now for almost two years and to be honest, there is no better library than this, very simple and straightforward. Thank you very much, speed and design were top priorities when I was building it. Yes, I am. I was a few times in Amsterdam, a beautiful city. If you get a chance to come this way hit me up maybe we can grab a beer 😉 |
What I already said in the readme is that I needed a replacement for wkHtmlToPdf ... because that one sucked in the end... no support for HTML5, no bugfixes anymore, it was a great tool but now obsolete :-) Since I'm an opensource enthousiast I decided to share the code so other people could also use it. I have a lott of tools on my GitHub page that are all related to document management since I'm working in that industry |
@vitovanjak hello, do you able to work it on docker? If so do you have forked repo to share with me? |
Yes it is working, I will be on computer in 1-2h I will post my configuration |
Is it also okey that I add your configuration to the main github page for other users with the same question? |
@Sicos1977 of course, feel free... Basic info: Docker file: FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
# 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
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY Web/Web.csproj Web/
RUN dotnet restore "Web/Web.csproj"
COPY . .
WORKDIR "/src/Web"
RUN dotnet build "Web.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Web.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Web.dll"] GitLab CI file: stages:
- build
docker:
image: docker:stable
stage: build
services:
- docker:dind
only:
- master
before_script:
- docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
script:
- docker build -t ${CI_REGISTRY_IMAGE}:latest ./
- docker push ${CI_REGISTRY_IMAGE}:latest
after_script:
- docker logout ${CI_REGISTRY}
tags:
- docker C# code: var HTML = "<HTML code>";
using (Converter converter = new Converter())
using (MemoryStream stream = new MemoryStream())
{
// This is necessary when running on Docker
converter.AddChromeArgument("--no-sandbox");
// Create PDF out of HTML string
converter.ConvertToPdf(html, stream, new ChromeHtmlToPdfLib.Settings.PageSettings());
// Return file to user
return File(stream.ToArray(), "application/pdf");
} So as you can see I didn't do anything crazy and out of ordinary, I was just following available documentation. #39 this issue helped me the most but I didn't copy code from this issue I copied from forked project that is linked in that issue If any question feel free to ask... |
Hi,
First of all thanks for the great library.
When I generate PDF CSS and images are not loaded correctly.
I am using absolute URLs and when I return pure HTML CSS and images load correctly.
Here is the code snippet that I am using:
In terms of docker configuration, I added chrome install from the issue linked in readme -> #39
I suspect that PDF is generated before all resources are loaded but I am not really sure.
I am using NuGet package version 2.5.25
I tested also in IIS Express without
converter.AddChromeArgument("--no-sandbox");
but I get same resultPlease let me know if you need more info about my issue
UPDATE:
I was testing it a bit more and I found the following things
waitForWindowsStatus
totrue
but only on IIS ExpresswaitForWindowsStatus
totrue
in development and with Docker for Desktop it never workswaitForWindowsStatus
totrue
in production in Kubernetes it works but it always goes toWaitForWindowsStatusTimeout
and then sometimes it loads images and CSS but sometimes it doesn't most often on the second request everything loads as expected, like I can put timeout to 2000 ms and it works sometimes but if I put 120000ms it will wait 2 minutes and then show the file as normal, likewindows.status
never goes to true but it shouldThe text was updated successfully, but these errors were encountered: