首页 > 解决方案 > 将css添加到pdf

问题描述

我需要生成一个 pdf,并将名称放在特定位置的图像顶部。我已经编写了一个有效的 HTML 代码,但 mpdf 无法加载样式表,并且名称被打印在图像下方。

这是我的php代码:

<?php
$html = file_get_contents('index12.html');

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();
$stylesheet = file_get_contents('style.css');
$mpdf->WriteHTML($stylesheet, 1);

$mpdf->WriteHTML($html,2);
$mpdf->Output();

index12.html

<!-- <link rel="stylesheet" href="style.css"> -->

<div class="image">

      <img src="yugmak.jpg" alt="" />

      <h2>Kung Fu Panda</h2>

</div>

样式.css

@font-face {
  font-family: "Montez";
  src: url("Montez.ttf");
}

.image {
 position: relative;
 width: 100%; /* for IE 6 */
}

h2 {
 position: absolute;
 font-family: "Montez";
 font-size: 250px;
 top: 2100px;
 padding-left: 1050px;
 width: 2000px;
}

任何使css在pdf中工作的方法都会很棒。

标签: phphtmlcssmpdf

解决方案


推荐阅读