如何在使用 withHTMLContent 的 openHTMLToPDF 函数时丢弃基本 URI。

huangapple go评论57阅读模式
英文:

how to discrard base uri when using withHTMLContent openHTmlToPDF

问题

我正在使用 openHTMLtoPDF 将我的 HTML 转换为 PDF。我已经为我的图片提供了完整的路径,因此我不希望该库使用基础路径。

例如:我的图片路径是: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;

我得到以下错误:

尝试使用基础 URI(file:) 加载 uri(C:\Users\hmt\Desktop\pdf\email_icon.png) 时,一个或两个 URI 都无效。
com.openhtmltopdf.load 信息:: URI 解析器拒绝加载位于 (C:\Users\hmt\Desktop\pdf\email_icon.png) 的图像。

英文:

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

得分: 3

baseDocumentUri如果没有相关资源,可以为null。

    builder.withHtmlContent(template, null);
英文:

baseDocumentUri can be null if there are no relative resources.

    builder.withHtmlContent(template, null);

huangapple
  • 本文由 发表于 2020年10月1日 15:28:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/64150842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定