Skip to content
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

Pictures no longer appear #24

Closed
gitfreud opened this issue Oct 8, 2020 · 21 comments
Closed

Pictures no longer appear #24

gitfreud opened this issue Oct 8, 2020 · 21 comments
Labels
parent Issue in parent project (wkhtmltopdf)

Comments

@gitfreud
Copy link

gitfreud commented Oct 8, 2020

Hello,
Since 1.3.0 version pictures (like .png) no longer appear.
I checked after just changing runtime for 0.12.5 and it works fine.

@HakanL
Copy link
Owner

HakanL commented Oct 8, 2020

I see, that's strange. Can you push a PR with a unit test that shows the issue?

@gitfreud
Copy link
Author

gitfreud commented Oct 8, 2020

Yes, it's strange but the issue is already identified. I found this

I confirm the workaround: if I remove width and height attributes, it works.

@HakanL
Copy link
Owner

HakanL commented Oct 8, 2020

Ok, thanks for confirming that it's an upstream/parent issue.

@HakanL HakanL added bug Something isn't working parent Issue in parent project (wkhtmltopdf) and removed bug Something isn't working labels Oct 8, 2020
@gitfreud
Copy link
Author

gitfreud commented Oct 8, 2020

I made a mistake about the workaround. The bug exists with or without html attributes.

I opened a PR with an unit test. The test fails with wkhtmltopdf library 0.12.16 but it's good with 0.12.5 (win-64).

@HakanL
Copy link
Owner

HakanL commented Oct 8, 2020

Ah I see. I've added your unit test, thanks for your contribution. Unfortunately I think we're completely blocked by the issue in the parent project though.

@ramakrishnaindpro
Copy link

I have same problem using 0.12.6 (and no issue on 0.12.4), any updates on this issue?

@HakanL
Copy link
Owner

HakanL commented Jan 5, 2021

@ramakrishnaindpro It looks to be an issue with the parent wkhtmltopdf project, so it's not something that can be fixed in this .NET wrapper. See this issue: wkhtmltopdf/wkhtmltopdf#4832

@Gunock
Copy link

Gunock commented Jan 27, 2021

Is there any chance this issue is with --enable-local-file-access parameter not being passed somewhere, or local file access is not set to be allowed when using this lib?
I found on stack overflow that from version 0.12.6 wkhtmltopdf does not allow for local files by default.

Here's link to this stack overflow lead:
https://stackoverflow.com/questions/62315246/wkhtmltopdf-0-12-6-warning-blocked-access-to-file

Also changelog for version 0.12.6 supports this claim:
https://github.com/wkhtmltopdf/wkhtmltopdf/releases/0.12.6/

@DanielVirta
Copy link

For me it works when first converting the image to a base64string and then including the image in the HTML in this form: src="data:image/png;base64,".

@HakanL
Copy link
Owner

HakanL commented Feb 4, 2021

Is there any chance this issue is with --enable-local-file-access parameter not being passed somewhere, or local file access is not set to be allowed when using this lib?
I found on stack overflow that from version 0.12.6 wkhtmltopdf does not allow for local files by default.

Here's link to this stack overflow lead:
https://stackoverflow.com/questions/62315246/wkhtmltopdf-0-12-6-warning-blocked-access-to-file

Also changelog for version 0.12.6 supports this claim:
https://github.com/wkhtmltopdf/wkhtmltopdf/releases/0.12.6/

Maybe, but it seems to work if width/height is removed, so doesn't seem to be related to blocked access to local files (the example in the parent ticket was using an image hosted on a web server as well, so not local file).

@johguentner
Copy link

johguentner commented Feb 25, 2021

It looks like @Gunock findings are accurate.
Yesterday I had the same problem, while trying to access local files for css/fonts/images.

If you look at the doc changes for this parameter in wkhtmltopdf:
--disable-local-file-access is (default) in 0.12.6 and
--enable-local-file-acccess is (default) in 0.12.5
https://github.com/wkhtmltopdf/wkhtmltopdf/blob/0.12.6/docs/usage/wkhtmltopdf.txt
https://github.com/wkhtmltopdf/wkhtmltopdf/blob/0.12.5/docs/usage/wkhtmltopdf.txt

Temporary Solution:
Currently this can be solved by replacing the *.dll-files within the runtime-folder.
Just download the 0.12.5-Version for your system (https://github.com/wkhtmltopdf/wkhtmltopdf/releases/tag/0.12.5), install it, and copy the *.dll-File of the version to your runtime-folder

After digging into the code, I found, that 'BlockLocalFileAccess' in 'LoadSettings' (which can be applied to 'ObjectSettings'), can be set to 'false', which also solves the issue.

(this is not technical advice, but only the way I solved it. Downgrading to an old version might lead to bugs in previous versions, or can have security issues, which are solved in the new version)

@johguentner
Copy link

It looks like @Gunock findings are accurate.
Yesterday I had the same problem, while trying to access local files for css/fonts/images.

If you look at the doc changes for this parameter in wkhtmltopdf:
--disable-local-file-access is (default) in 0.12.6 and
--enable-local-file-acccess is (default) in 0.12.5
https://github.com/wkhtmltopdf/wkhtmltopdf/blob/0.12.6/docs/usage/wkhtmltopdf.txt
https://github.com/wkhtmltopdf/wkhtmltopdf/blob/0.12.5/docs/usage/wkhtmltopdf.txt

Temporary Solution:
Currently this can be solved by replacing the *.dll-files within the runtime-folder.
Just download the 0.12.5-Version for your system (https://github.com/wkhtmltopdf/wkhtmltopdf/releases/tag/0.12.5), install it, and copy the *.dll-File of the version to your runtime-folder
(this is not technical advice, but only the way I solved it. Downgrading to an old version might lead to bugs in previous versions, or can have security issues, which are solved in the new version)

Since the initial issue declared by @gitfreud is not directly correlated to the local-file-access-issue and the disabled local-file-access is affecting not only images, I created a new issue, with the short description for a temporary soluation. Hope that's okay. (#31)

@mortb
Copy link

mortb commented Dec 2, 2021

@johguentner Your suggestion is totally awesome!
I upgraded to this nuget from the original DinkToPdf nuget to get a later 64-bit version of wktohtml and struggled with images that would not display, but adding this small snippet to the code solved my problems
new ObjectSettings() { LoadSettings = new LoadSettings { BlockLocalFileAccess = false }, ... }

Thanks for your effort

@johguentner
Copy link

For sure @mortb! You're welcome!

@HakanL
Copy link
Owner

HakanL commented May 16, 2022

It looks like this was related to the defaults changing in the parent library from version 0.12.5 to 0.12.6. BlockLocalFileAccess is the key here.

@HakanL HakanL closed this as completed May 16, 2022
@xmontero
Copy link

xmontero commented Jul 23, 2022

Xpost here: wkhtmltopdf/wkhtmltopdf#4832 (comment)

Silly comment just in case someone is in my situation:

I've been struggling for hours without the images appearing in the PDF while they appeared if I opened the HTML in the browser.

It happened that I was opening an old "template" that pointed the images to http://whatever. While the browser did the call and got a 301 redirect to the very same image by TLS over https:// the wkhtmltopdf just did not follow those redirects and the images appeared blank in the PDF. Changing the image URLs in the template to the final ones avoiding any redirects solved the issue.

v0.12.4 was not verbose about this.

I'm not reopening this bug, even not suggesting there's a bug. Only logging this to help people googling, as a google search about [wkhtmltopdf not rendering images] will probably lead to this "Pictures no longer appear" issue.

@Sicos1977
Copy link

@Jymmy3024
Copy link

Jymmy3024 commented Mar 21, 2024

Xpost aquí: wkhtmltopdf/wkhtmltopdf#4832 (comentario)

Comentario tonto por si alguien está en mi situación:

He estado luchando durante horas sin que aparecieran las imágenes en el PDF mientras aparecían si abría el HTML en el navegador.

Sucedió que estaba abriendo una "plantilla" antigua que apuntaba las imágenes http://whatever. Si bien el navegador hizo la llamada y obtuvo una redirección 301 a la misma imagen mediante TLS, https://simplemente wkhtmltopdfno siguió esas redirecciones y las imágenes aparecieron en blanco en el PDF. Cambiar las URL de las imágenes en la plantilla a las finales evitando redirecciones resolvió el problema.

La v0.12.4 no fue detallada sobre esto.

No voy a reabrir este error, ni siquiera sugiero que haya un error. Registrar esto solo para ayudar a las personas a buscar en Google, ya que una búsqueda en Google sobre [wkhtmltopdf no representa imágenes] probablemente conducirá al problema "Las imágenes ya no aparecen".

Xpost here: wkhtmltopdf/wkhtmltopdf#4832 (comment)

Silly comment just in case someone is in my situation:

I've been struggling for hours without the images appearing in the PDF while they appeared if I opened the HTML in the browser.

It happened that I was opening an old "template" that pointed the images to http://whatever. While the browser did the call and got a 301 redirect to the very same image by TLS over https:// the wkhtmltopdf just did not follow those redirects and the images appeared blank in the PDF. Changing the image URLs in the template to the final ones avoiding any redirects solved the issue.

v0.12.4 was not verbose about this.

I'm not reopening this bug, even not suggesting there's a bug. Only logging this to help people googling, as a google search about [wkhtmltopdf not rendering images] will probably lead to this "Pictures no longer appear" issue.

How can I do it? I am using wkhtmltopdf in a project that is development in C#, aspx and javascript. In my case I get the URL of the DB but the image is hosted on amazon, the problem I have is that the image when generating the pdf if it has one page the logo is displayed normally but when it has 2 or more pages the logo in header is displayed only sometimes.

@HakanL
Copy link
Owner

HakanL commented Mar 21, 2024

@Jymmy3024 Perhaps you can proxy/cache the image in your web site so it's not a call into S3?

@Jymmy3024
Copy link

@Jymmy3024 Perhaps you can proxy/cache the image in your web site so it's not a call into S3?

I don't know if is because the proyect is old, but it don't allow me to use localStorage

@HakanL
Copy link
Owner

HakanL commented Mar 21, 2024

@Jymmy3024 Perhaps you can proxy/cache the image in your web site so it's not a call into S3?

I don't know if is because the proyect is old, but it don't allow me to use localStorage

I don't think I can help you with that, just giving you suggestions on how to potentially solve the issue with your images. Bottom line is that it's best to have everything local when generating the PDFs, especially since it's also single-threaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parent Issue in parent project (wkhtmltopdf)
Projects
None yet
Development

No branches or pull requests

10 participants