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

How to render image? #620

Closed
achimmihca opened this issue Dec 17, 2020 · 3 comments
Closed

How to render image? #620

achimmihca opened this issue Dec 17, 2020 · 3 comments

Comments

@achimmihca
Copy link

From the tests I found this xhtml where img-tag is used as usual.
However, this does not seem to work. When I render my PDF, the image is always missing.

Also I wonder how this should work. The documentation does not say anything about images and the example does not make use of them.

  • Is the renderer trying load a file with this given local path?
    • If yes, then relative to which location?
  • What if my image is in a Java "resource" directory (already packed inside the JAR)?

Anyway, I also tried <img src="data:..." to provide the image data directly with the xhtml. This also has been done in #619 and is said to work. However, I still see no image in my PDF.

I don't have any error output from the renderer. The PDF is generated but without the image.
As a result, I have no idea what the problem is. Is there a way to get more verbose output to find the root cause?

OpenHtmlToPDF Version: 1.0.5

@achimmihca
Copy link
Author

achimmihca commented Dec 17, 2020

To test this, I used the following:

<html>
<head>
    <style>
        @page {
            size: A4;
        }
    </style>
</head>

<body>
    Hello world!
    <img style="width: 2cm; height: 2cm;"
         src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAE2klEQVRoge2Za0xbZRjH/x0wbmMggzIQmFTAYYjD6WSr2eUD29R42eIy2eYlojHTaEycuuiSRWN08QNZBJIZx2VGg1GJjhh1cZMi47K5sDBXx7gOCi1QbqVSRunaxw/zAuSc95z3LeZI0t+n5rz/5/k///a05/Q9OiLCYmaJ1gP4SyCA1gQCaE0ggNYs+gDBIkWuUbScxFgvHFZ4PQrioBDEGZCQieQc6DNE7JjouK/EDiuqDsBYgJV3IDoJQSEKeu8MRq5hqA29zbC3IzgUGZuxLh8h4cJDz4G46DxLZXtouIuvajZeDzV/Tcd3U0M5zUyJ9/kbngAddfTps+R2+e/6b4xznxH5/Omk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QXvnEJXvo7YakVoZ+AMQUWMFnS7krrKaqTSfeptFHOXhf0Jzk1NHEBaFLS+rElsvw1SE4FA88BZibhWxk0c0ANRlIB/qP4Htdzx0GFHxgkZM/AgA4Pt3EZ+O+/bNPz45jP7f0HMeNjNW58FY4M+IbPwL4JnGz0fRd3HOEzufF5GxWLUOSdlIXev/iGz8C/A/YNE/6A4E0JpAAK0JBNCaQACtCQTQmkAArQkE0Jo/AaHeXcfZZth5AAAAAElFTkSuQmCC"
         alt="Smiley"/>
</body>
</html>

This works in a browser.

@achimmihca
Copy link
Author

Found a solution:

it works when using an absolute path to the image and file:// protocol (but you have to use three slashes also on Windows, so file:///)

<img src="file:///D:/repos/local-projects/ExportExperiments/smiley.png" alt="Smiley"/>

@syjer
Copy link
Contributor

syjer commented Dec 17, 2020

hi @achimmihca , for the base64 image:

data:image/png;base64, iVB, if you remove the space after the , , it will work.

For the file, you can use relative path if you want, but you must pass the base uri.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants