Skip to content

baseUri in withHtmlContent not working as expected #566

Closed
@NehalDamania

Description

@NehalDamania

When we use

 String baseUri = new ClassPathResource("templates").getURL().toExternalForm();
 System.out.println("baseUri :" + baseUri);
 PdfRendererBuilder builder = new PdfRendererBuilder();
 builder.useFastMode()
	.withHtmlContent(html, baseUri)

The "templates" folder is under "src/main/resources". And, the templates folder contains the HTML, CSS and fonts

However, when searching for fonts and css file, openhtmlpdf searches under classes folder instead of templates and gives the error as such

com.openhtmltopdf.load INFO:: Requesting stylesheet: file:/D:/development/project-1/target/classes/resume.css
com.openhtmltopdf.exception WARNING:: Item at URI file:/D:/development/project-1/target/classes/resume.css not found

The baseUri is printed correctly as

baseUri: file:/D:/development/project-1/target/classes/templates

I assumed it should have used the templates folder as base as below.
D:/development/project-1/target/classes/templates/resume.css

Same errors for fonts, they are not found as they are inside src/main/resources/templates
Now, if I move all my html, css and fonts directly under src/main/resources folder, everything works fine.
So, somehow the baseUri seems not to be working as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions