我无法使用SVG内容生成pdf保持设计。 SVG在html中链接,并使用html生成pdf。但是工作不正常。
这是代码:
$dompdf = new DOMPDF();
//HTML Content
$html = <<<EOD
<html>
<head>
<style type="text/css">
html {
margin: 1%;
padding: 0;
}
.header,
.footer {
width: 100%;
text-align: center;
position: fixed;
font-size: 26px;
}
.header {
top: 0px;
}
.footer {
bottom: 18px;
}
.center {
margin: 0 auto;
}
.divTable{
display: table;
width: 100px;
text-align: center;
margin: 0 auto;
}
.divTableRow {
display: table-row;
}
.divTableHeading {
margin: 0 auto;
}
.divTableCell, .divTableHead {
display: table-cell;
padding: 0 33px;
}
.bottom .divTableCell {
padding-top: 30px;
}
.divTableHeading {
display: table-header-group;
font-weight: bold;
}
.divTableFoot {
display: table-footer-group;
font-weight: bold;
}
.divTableBody {
display: table-row-group;
}
div.img-border img {
border: 2px solid #eb0089;
}
</style>
</head>
<body>
<div class="center">
<div class="divTable top">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell" style="padding-left:0px;"><div class="img-border"><img src="$small_image"></div></div>
<div class="divTableCell"><div class="img-border"><img src="$small_image"></div></div>
<div class="divTableCell" style="padding-right:0px;"><div class="img-border"><img src="$small_image"></div></div>
</div>
</div>
</div>
<div class="divTable bottom">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell" style="padding-left:0px;"><div class="img-border"><img src="$large_image"></div></div>
<div class="divTableCell" style="padding-right:0px;"><div class="img-border"><img src="$large_image"></div></div>
</div>
</div>
</div>
</div>
<div class="footer">
$customer_title - $customer_order_number
</div>
</body>
</html>
EOD;
//PDF Options
$dompdf->set_option( 'dpi' , '300' );
$dompdf->load_html($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->set_option( 'isRemoteEnabled', true );
$dompdf->render();
$output = $dompdf->output();
file_put_contents('path-to-pdf/new.pdf);
这是html视图(包括svg):view here
然而,当我使用PNG图像时,它工作正常。 这就是生成的pdf的样子(使用png):
不确定我做错了什么!
答案 0 :(得分:1)
我已经使用Svg生成了一些演示PDF并且工作正常,您只需要为图像标记添加内嵌宽度和高度
<img width="400" src="yourpath/au.svg" />
P.S 不要设置宽度,只需像这样写宽度=&#34; 400&#34;内联img标签
答案 1 :(得分:0)
它对我有用:
魔法是base64_encode
控制器:
$qrCode = base64_encode(QrCode::format('png')->size(150)->generate('hello qrcode'));
$pdf->loadView('myfiles.pdf', compact('qrCode'));
查看:
<img src="data:image/png;base64, {{ $qrCode }}">