how to discrard base uri when using withHTMLContent openHTmlToPDF

2.1k Views Asked by At

I am using openHTMLtoPDF to convert my HTML to PDF. I have given full path to my images therefore , I don't want teh library to use a base path.

Ex: path of my image is: C:\Users\hmt\Desktop\pdf\email_icon.png

 PdfRendererBuilder builder = new PdfRendererBuilder();
                builder.useFastMode();
                builder.withHtmlContent(template, "file:\\");
                builder.toStream(baos);
                builder.run();
                return baos;
            }

I am getting the following error:

When trying to load uri(C:\Users\hmt\Desktop\pdf\email_icon.png) with base  URI(file:\), one or both were invalid URIs.
com.openhtmltopdf.load INFO:: URI resolver rejected loading image at (C:\Users\hmt\Desktop\pdf\email_icon.png)
1

There are 1 best solutions below

0
On

baseDocumentUri can be null if there are no relative resources.

    builder.withHtmlContent(template, null);