-
Notifications
You must be signed in to change notification settings - Fork 359
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
images are missing #103
Comments
Issue got fixed . |
Hi, To display the images/company logo, you have to keep the logo image inside the web application folder and access the same using relative path. If you want to render the PDF files using java components, you have to keep the image inside the java containers and use the same while constructing the html files. Please drop the email to vetrivel.msc@gmail.com to get more details on this. Thanks |
I am getting the issue in wildfly 10 server |
Is there any chance the URL is https and secured with letsencrypt? If so, only relatively modern releases of Java will accept the let’s encrypt certificate. Please make sure that java.net.url::openConnection returns a valid image for the URL. |
I am trying to convert my html to pdf and it has an image in it. I am getting the following error. That url is internet facing and is accessible from the browser. |
i face same issue for following URL below URL accessible from browser and not print |
I face the same problem. Im generating a PDF from HTML with an image in it. |
Same issue here |
Same here |
Did somebody resolved this issue? |
same here |
Same here, After building as jar file the image not loading. |
any further insights about this issue? |
Should make it easier to debug #103 and similar mysteries.
UPDATE: Earlier I wrote: I tried this program, firstly on Windows, then on package com.example;
import java.io.FileOutputStream;
import java.io.IOException;
import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
public class App
{
public static void main( String[] args ) throws IOException
{
//try (FileOutputStream fos = new FileOutputStream("C:\\Users\\me\\Desktop\\res.pdf")) {
try (FileOutputStream fos = new FileOutputStream("/home/res.pdf")) {
PdfRendererBuilder builder = new PdfRendererBuilder();
builder.toStream(fos);
builder.useFastMode();
builder.withHtmlContent("<body>Hello world!<img src=\"https://upload.wikimedia.org/wikipedia/commons/6/6a/Mona_Lisa.jpg\"/></body>", null);
builder.run();
}
}
} POM file: <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>1.0-SNAPSHOT</version>
<name>demo</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.openhtmltopdf</groupId>
<artifactId>openhtmltopdf-pdfbox</artifactId>
<version>1.0.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project> To build:
To run:
|
Could someone assist me with the following error com.openhtmltopdf.exception WARNING:: Bad URL given: /images/1.png In the final output I couldn't see the images are being displayed. Did several workarounds but couldn't find the exact issue |
@danfickle could you please help me with above problem ? |
If anyone wants to debug this before the next release, it would be a great help. You need to add this code before using the builder. This code will output details of the underlying exception: XRLog.setLoggerImpl(new JDKXRLogger(false, Level.INFO, new ConsoleHandler(), new Formatter(){
@Override
public String format(LogRecord record) {
String base = record.getLevel() + ":: " + record.getMessage();
if (record.getThrown() != null) {
base += " => " + record.getThrown().getClass().getName() + ":: " + record.getThrown().getMessage();
if (record.getThrown().getCause() != null) {
base += " caused by: " + record.getThrown().getCause().getClass().getName() + ":: " + record.getThrown().getCause().getMessage();
}
}
return base + '\n';
}
})); @malindux, I think you have a separate issue. You are getting that message because your url has no scheme such as If you have something like: builder.withHtmlContent(html, "https://openhtmltopdf.com/document.html"); then the relative url referenced in your document ( If the images are in your resources folder you could use something like: builder.withHtmlContent(html, SomeClass.class.getResource("/document.html").toExternalForm()); Notes:
|
@danfickle Actually what I have is a resource folder with all the images in it and I'm using Free Marker Templates to produce PDFs. Using toExternalForm() actually solved my issues. Thank you for your support. |
hey i'm getting the same problem in my server but the i have the images in a system folder like this. Should I add file as a prefix in this route to make it work? |
The path should be provided as a file URI. That would mean something like But don't build this yourself by adding prefixes etc. Just use the
|
@danfickle's advice worked :) Added this:
After that, considering I have an image in Note: it will NOT work if you try to reference it like this: Thanks! |
Yes indeed. You specify a |
Hi ,
I have integrated PdfRendererBuilder to generate pdf file from html file and its working perfectly in the text and other stuffs but images are getting missed out . And I am also getting a warning msg as follows
com.openhtmltopdf.exception WARNING:: Can't read image file; unexpected problem for URI 'https://res.cloudinary.com/dffr0nets/image/upload/2341574.png'
This is generated pdf file
A0005_170608144956GCo.pdf
And this is the html display for the same code
Can you please let me know why this is happening and whats the solution . The same works fine if i execute in junit .
This is the file generated from JUNIT .
ADM001_170608145000z3t.pdf
Please help me out .
The text was updated successfully, but these errors were encountered: