首页 > 解决方案 > 使用 ngx-print 打印图像的问题

问题描述

使用 ngx-print 无法打印图像。我不确定我在这里做错了什么。

HTML

<button  type="button" printTitle="PrintVoucher" [useExistingCss]="true" 
                                        printSectionId="printVoucher" ngxPrint>
                                        Print </button>

<div row id="printVoucher" >
 <img  src="assets/images/logo.png">
</div>

但是,图像在屏幕上可见,但在打印预览部分不可见。

在此处输入图像描述

标签: javascripthtmlangularangular5

解决方案


你必须使用绝对路径,而不是相对路径

即你的路径应该是例如

http://localhost:3000/assets/images/print-logo.png ” 不是 “print-logo.png”

要了解相对路径和绝对路径之间的区别,请查看此链接

例如,要获取当前的基本 URL(“ http://localhost:3000 ”),您可以使用

让 x = window.location.origin;


推荐阅读