Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to discrard base uri when using withHTMLContent openHTmlToPDF

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)
like image 948
HMT Avatar asked Oct 14 '25 14:10

HMT


1 Answers

baseDocumentUri can be null if there are no relative resources.

    builder.withHtmlContent(template, null);
like image 151
Brendan Avatar answered Oct 17 '25 04:10

Brendan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!