Symfony WhtmlToPdf不';不要将字体应用于PDF
我目前正在开发一个文档生成器symfony 2捆绑包,它允许生成HTML和PDF文档(如发票) 当我在浏览器中以HTML页面的形式生成文档时,一切正常,但当我生成PDF文件时,我的文档没有应用任何字体 我对这两种情况使用相同的模板。以下是我的pdf生成方法:Symfony WhtmlToPdf不';不要将字体应用于PDF,symfony,pdf,fonts,Symfony,Pdf,Fonts,我目前正在开发一个文档生成器symfony 2捆绑包,它允许生成HTML和PDF文档(如发票) 当我在浏览器中以HTML页面的形式生成文档时,一切正常,但当我生成PDF文件时,我的文档没有应用任何字体 我对这两种情况使用相同的模板。以下是我的pdf生成方法: private function generatePdfWithoutMerge($html) { $pdfService = $this->get('knp_snappy.pdf'); return $pdfSer
private function generatePdfWithoutMerge($html)
{
$pdfService = $this->get('knp_snappy.pdf');
return $pdfService->getOutputFromHtml($html);
}
$html变量是从呈现的细枝模板生成的,如前所述,如果在浏览器中将其显示为html,则没有问题
更少的文件:
@base-url: 'url-to-bucket';
@dark-grey: #555559;
@dark-pink: #970047;
@font-face {
font-family: paralucent_demi_boldregular;
src: url('@{base-url}/paradb__-webfont.eot');
src: url('@{base-url}/paradb__-webfont.eot?#iefix') format('embedded-opentype'),
url('@{base-url}/paradb__-webfont.woff') format('woff'),
url('@{base-url}/paradb__-webfont.ttf') format('truetype'),
url('@{base-url}/paradb__-webfont.svg#paralucent_demi_boldregular') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: paralucent_lightregular;
src: url('@{base-url}/paral___-webfont.eot');
src: url('@{base-url}/paral___-webfont.eot?#iefix') format('embedded-opentype'),
url('@{base-url}/paral___-webfont.woff') format('woff'),
url('@{base-url}/paral___-webfont.ttf') format('truetype'),
url('@{base-url}/paral___-webfont.svg#paralucent_lightregular') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: paralucent_thinregular;
src: url('@{base-url}/parat___-webfont.eot');
src: url('@{base-url}/parat___-webfont.eot?#iefix') format('embedded-opentype'),
url('@{base-url}/parat___-webfont.woff') format('woff'),
url('@{base-url}/parat___-webfont.ttf') format('truetype'),
url('@{base-url}/parat___-webfont.svg#paralucent_thinregular') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: paralucent_mediumregular;
src: url('@{base-url}/param___-webfont.eot');
src: url('@{base-url}/param___-webfont.eot?#iefix') format('embedded-opentype'),
url('@{base-url}/param___-webfont.woff') format('woff'),
url('@{base-url}/param___-webfont.ttf') format('truetype'),
url('@{base-url}/param___-webfont.svg#paralucent_mediumregular') format('svg');
font-weight: normal;
font-style: normal;
}
body {
color: @dark-grey;
font-family: paralucent_lightregular, Helvetica, Arial, sans-serif;
font-size: 1.2em;
line-height: 0.9em;
}
.thin {
font-family: paralucent_thinregular, Helvetica, Arial, sans-serif;
}
.bold {
font-family: paralucent_mediumregular, Helvetica, Arial, sans-serif;
}
.demibold {
font-family: paralucent_demi_boldregular, Helvetica, Arial, sans-serif;
}
.price {
font-family: Arial, sans-serif;
font-size: 0.8em;
}
.separator_unbreak_wrapper {
}
.separator_unbreak {
page-break-inside: avoid !important;
}
.city_format {
font-size: 0.75em;
}
table tr th {
border-bottom: 1px solid @dark-pink;
font-weight: normal;
font-style: normal;
}
感谢DevDonkey的评论: 我尝试使用一个很好的文件体系结构,其中子模板从一个公共父模板和一个公共LESS文件扩展而来,但是Wkhtmltopdf在这种复杂的体系结构中存在一些问题。 我必须将所有内容收集到一个HTML文件中,才能使其正常工作
非常感谢大家的帮助。您使用的是什么字体?我的字体是.eot、.woff、.ttf和.svg文件,托管在S3存储桶中,CORS设置如下:localhost GET*我不知道这个库,但如果它足够聪明,能够在HTML文档中嵌入
font-face
字体,我会印象深刻。。。可能需要手动添加它们?不过,我对这个产品一无所知。在你的例子中,这个人使用谷歌字体链接。这很好,但我有一种特殊的字体,在上面找不到:Paralucent。我有前面说过的字体文件。我将在OP.wkhtmltopdf中发布我的LESS文件,它在使用任何外部资源时都会遇到巨大的麻烦,甚至在通过内部浏览器解析它时也会遇到样式表问题。你将无法实现你想要的。你必须使用更复杂的东西。但这并不意味着Wkhtmltopdf必须解释更少的文件,对吗?它收到了要解析的常规CSS?否,因为它是使用assetic的细枝模板,render()调用将把较少的文件处理为CSS文件,并将所有细枝文件处理为HTML文件。顺便说一句,twiginclude/extends的工作方式很有魅力,因此您可以使用标记和所有CSS代码创建一个twig文件,然后将其包含在其他模板中,这样您仍然只有一个样式表需要管理。