Coder Social home page Coder Social logo

Comments (21)

mortb avatar mortb commented on July 19, 2024 2

@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

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024 2

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.

from wkhtmltopdf-dotnet.

gitfreud avatar gitfreud commented on July 19, 2024 1

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.

from wkhtmltopdf-dotnet.

johguentner avatar johguentner commented on July 19, 2024 1

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)

from wkhtmltopdf-dotnet.

johguentner avatar johguentner commented on July 19, 2024 1

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)

from wkhtmltopdf-dotnet.

johguentner avatar johguentner commented on July 19, 2024 1

For sure @mortb! You're welcome!

from wkhtmltopdf-dotnet.

xmontero avatar xmontero commented on July 19, 2024 1

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.

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

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

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

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

from wkhtmltopdf-dotnet.

gitfreud avatar gitfreud commented on July 19, 2024

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).

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

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.

from wkhtmltopdf-dotnet.

ramakrishnaindpro avatar ramakrishnaindpro commented on July 19, 2024

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

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

@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

from wkhtmltopdf-dotnet.

Gunock avatar Gunock commented on July 19, 2024

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/

from wkhtmltopdf-dotnet.

DanielVirta avatar DanielVirta commented on July 19, 2024

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,".

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

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).

from wkhtmltopdf-dotnet.

Sicos1977 avatar Sicos1977 commented on July 19, 2024

https://github.com/Sicos1977/ChromeHtmlToPdf

from wkhtmltopdf-dotnet.

Jymmy3024 avatar Jymmy3024 commented on July 19, 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.

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 2024

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

from wkhtmltopdf-dotnet.

Jymmy3024 avatar Jymmy3024 commented on July 19, 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

from wkhtmltopdf-dotnet.

HakanL avatar HakanL commented on July 19, 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.

from wkhtmltopdf-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.