Comments (21)
@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.
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.
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.
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.
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.txtTemporary 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.
For sure @mortb! You're welcome!
from wkhtmltopdf-dotnet.
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.
I see, that's strange. Can you push a PR with a unit test that shows the issue?
from wkhtmltopdf-dotnet.
Ok, thanks for confirming that it's an upstream/parent issue.
from wkhtmltopdf-dotnet.
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.
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.
I have same problem using 0.12.6 (and no issue on 0.12.4), any updates on this issue?
from wkhtmltopdf-dotnet.
@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.
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.
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.
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-fileAlso 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.
https://github.com/Sicos1977/ChromeHtmlToPdf
from wkhtmltopdf-dotnet.
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://
simplementewkhtmltopdf
no 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 overhttps://
thewkhtmltopdf
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.
@Jymmy3024 Perhaps you can proxy/cache the image in your web site so it's not a call into S3?
from wkhtmltopdf-dotnet.
@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.
@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)
- Not reading settings on alpine HOT 2
- HTML tags removed HOT 3
- Reporting a vulnerability HOT 1
- In Linux CentOS 7, there was an error: Unable to load native library. The platform may be missing native dependencies (libjpeg62, etc). Or the current platform is not supported. HOT 3
- Memory overflow HOT 2
- The wkhtmltopdf project that is used, is no longer maintained HOT 3
- Display flex is not working HOT 1
- Unable to load native library - Windows 10/11 HOT 16
- How to directly pass parameters to wkhtmltopdf without using objects HOT 1
- You can only download the pdf once HOT 2
- How can I include CSS like Bootstrap in my HTML so that I can observe the applied styles when generating a PDF? HOT 6
- Unable to load native library on .NET8 HOT 29
- n/a
- GlobalSettings not respected on debian 11 HOT 3
- With Multiple requests fails HOT 15
- Not working on Azure Web App 32 bits HOT 7
- add cover command HOT 2
- PdfTools.GetConversionResult doesn't frees memory HOT 3
- HTML字符串转换为PDF报错System.ExecutionEngineException HOT 1
- 将HTML字符串转换为PDF文件,抛出异常System.ExecutionEngineException(重复,需要删除) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wkhtmltopdf-dotnet.