我使用mPDF将HTML+css内容添加到已生成/创建的PDF中。HTML内容已成功添加,但其中不存在css内容。也就是说,它应该显示一个圆形进度条(如下所示),但不幸的是它没有生成它。我的假设是它不接受css输入,即使我试图像他们的文档中提到的那样导入它。这里的问题是什么?
编辑:我甚至在这里将样式表添加到html代码中,但它仍然不接受输入。
<?php
use setasign\Fpdi\Fpdi;
session_start();
ob_start();
require_once __DIR__ . '/vendor/autoload.php';
require_once('FPDI/autoload.php');
require_once('FPDI/Fpdi.php');
$pdf = new \Mpdf\Mpdf();
$pdf->AddPage();
$pdf->setSourceFile('file.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 0, 0, 297, 420, true);
$html = "
<style>
.flex-wrapper {
display: flex;
flex-flow: row nowrap;
}
.single-chart {
width: 33%;
justify-content: space-around;
}
.circular-chart {
display: block;
margin: 10px auto;
max-width: 80%;
max-height: 250px;
}
.circle-bg {
fill: none;
stroke: #eee;
stroke-width: 3.8;
}
.circle {
fill: none;
stroke-width: 2.8;
stroke-linecap: round;
}
.circular-chart.orange .circle {
stroke: #ff9f00;
}
.percentage {
fill: #666;
font-family: sans-serif;
font-size: 0.5em;
text-anchor: middle;
}
</style>
<div class='html-content'>
<div class='flex-wrapper'>
<div class='single-chart'>
<svg viewBox='0 0 36 36' class='circular-chart orange'>
<path class='circle-bg' d='M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831' />
<path class='circle' stroke-dasharray='12, 100' d='M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831' />
<text x='18' y='20.35' class='percentage'>12%</text>
</svg>
</div>
</div>
</div>
";
$pdf->WriteHTML($html);
$pdf->Output("$file_new.pdf", "D");
ob_end_flush();
?>在php标签之外,下面是分别给出的html和css代码:
.flex-wrapper {
display: flex;
flex-flow: row nowrap;
}
.single-chart {
width: 33%;
justify-content: space-around;
}
.circular-chart {
display: block;
margin: 10px auto;
max-width: 80%;
max-height: 250px;
}
.circle-bg {
fill: none;
stroke: #eee;
stroke-width: 3.8;
}
.circle {
fill: none;
stroke-width: 2.8;
stroke-linecap: round;
}
.circular-chart.orange .circle {
stroke: #ff9f00;
}
.percentage {
fill: #666;
font-family: sans-serif;
font-size: 0.5em;
text-anchor: middle;
}<div class="html-content">
<div class="flex-wrapper">
<div class="single-chart">
<svg viewBox="0 0 36 36" class="circular-chart orange">
<path class="circle-bg" d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831" />
<path class="circle" stroke-dasharray="56, 100" d="M18 2.0845
a 15.9155 15.9155 0 0 1 0 31.831
a 15.9155 15.9155 0 0 1 0 -31.831" />
<text x="18" y="20.35" class="percentage">56%</text>
</svg>
</div>
</div>
</div>
此进度条不会在PDF中生成。
发布于 2021-04-07 20:33:13
最好的解决方案是使用样式表。如下例所示:
<?php
$html = $divPrint;
include('mpdf.php'); // including mpdf.php
$mpdf=new mPDF();
$stylesheet = file_get_contents('pdf.css'); //this is ur external css
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html,2);
$mpdf->Output();
exit;
?>在$mpdf中分配html,然后将其包含在mpdf.php文件中
希望它能工作!!如果没有,告诉我们我们在这里提供更多的解决方案!!
https://stackoverflow.com/questions/66985784
复制相似问题