我正在使用MPDF库将HTML转换为PDF.
这是我的代码.
$HTML = '{HTML CONTENT GOES HERE}'; //HTML STRING
$MPDF->WriteHTML($html); // Converting
$MPDF->Output('preview.pdf','F'); //Saving to a File
Run Code Online (Sandbox Code Playgroud)
它可以工作,但在错误日志中产生太多错误,
ERROR - 2012-11-10 04:45:50 --> Severity: Notice --> Undefined index: BODY C:\wamp\www\crm\application\libraries\mpdf.php 14242
ERROR - 2012-11-10 04:45:50 --> Severity: Notice --> Undefined index: BODY>>ID>> C:\wamp\www\crm\application\libraries\mpdf.php 14288
ERROR - 2012-11-10 04:45:50 --> Severity: Notice --> Undefined offset: -1 C:\wamp\www\crm\application\libraries\mpdf.php 14421
ERROR - 2012-11-10 04:45:50 --> Severity: Notice --> Undefined variable: cstr C:\wamp\www\crm\application\libraries\mpdf.php 31951
ERROR - 2012-11-10 04:45:50 --> Severity: Notice --> Undefined …Run Code Online (Sandbox Code Playgroud) 我只是尝试 mPDF 按数据库制作输出表 pdf,但仍然很难做到这一点。
<?php
$html = '
<center><h3>TITLE</h3></center>
<center>
<table border="1">
<tr>
<th>COLUMN 1</th><th>COLUMN 2</th>
</tr>
<tr>
<!--how to fetch this row from DB? -->
<td>.$row[no1].</td><td>.$row[no2].</td>
</tr>
</table></center>
';
//==============================================================
//==============================================================
//==============================================================
include("../mpdf.php");
include "conn.php";
$res = mysql_query("select * from list");
if (!$res)
die("query error : ".mysql_error());
$mpdf=new mPDF('c','A4','','',32,25,27,25,16,13);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0; // 1 or 0 - whether to indent the first level of a list
// LOAD a stylesheet
$stylesheet = file_get_contents('mpdfstyletables.css');
$mpdf->WriteHTML($stylesheet,1); // The parameter 1 …Run Code Online (Sandbox Code Playgroud) 本质上,页眉和页脚仅在我手动分页后显示在第一页和第一页上。
但是由于长HTML内容,页眉和页脚不会显示在任何自然延续的其他页面上。(即没有手册的地方)
<htmlpageheader name="header">Page Hader</htmlpageheader>
<htmlpagefooter name="footer"><p>Copyright <b>blablabla</b> 1999 - <?php echo date('Y') ?></p></htmlpagefooter>
Run Code Online (Sandbox Code Playgroud)
页眉+页脚将显示在此页面上
<sethtmlpageheader name="header" page="all" value="on" show-this-page="1" />
<sethtmlpagefooter name="footer" page="all" value="on" />
<p>(PDF cover)</p>
<h1>Report</h1>
Run Code Online (Sandbox Code Playgroud)
页眉+页脚将显示在第一页上,但不会显示在后续页上
<pagebreak />
<sethtmlpageheader name="header" page="all" value="on" show-this-page="1" />
<sethtmlpagefooter name="footer" page="all" value="on" />
LONG HTML CONTENT
THAT EXCEEDS PAGE SIZE
Run Code Online (Sandbox Code Playgroud) 我正在使用mPDF库,我正在尝试编写一个代码,它将在一次调用时创建多个PDF文件(一次打开:test.php).问题:始终只下载第一个文件.我知道这个问题可能看起来很愚蠢,我试图深入谷歌,但我无法弄清楚如何解决这个问题.也许有人可以带领我走上正确的道路?
我的逻辑是:
- 我有一个包含所有订单的数组; 对于我想创建PDF的每个订单.
- 我循环数组,每次调用MPDF库
test.php的
$myorders = [
0 => array (
'FirstName' => 'Asia',
'LastName' => 'Basia',
'OrderNr' => '123'
),
1 => array (
'FirstName' => 'Madzia',
'LastName' => 'Siasia',
'OrderNr' => '456'
)
];
for ($i=0; $i < count($myorders); $i++) {
$FirstName = $myorders[$i]['FirstName'];
$LastName = $myorders[$i]['LastName'];
$OrderNr = $myorders[$i]['OrderNr'];
require 'invoice.php';
}
Run Code Online (Sandbox Code Playgroud)
invoice.php
require 'MPDF57/mpdf.php';
$mpdf=new mPDF();
$mpdf->Bookmark('Start of the document');
$mpdf->WriteHTML('test test' . $FirstName);
$mpdf->Output("filename{$OrderNr}.pdf",'D');
Run Code Online (Sandbox Code Playgroud)
仅下载filename123.pdf.是否无法下载多个文件?我究竟做错了什么?
<table>
<tr>
<td class="contentDetails">
<td class="contentDetails">
<h3 style="text-align: right;"><strong>text align right</strong></h3>
<h3 style="text-align: center;"><strong>text align center</strong></h3>
<h3 style="text-align: left;"><strong>text align left</strong></h3>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我使用黑社会
.contentDetails > h3 {display: block;}
Run Code Online (Sandbox Code Playgroud)
但是没有工作,在td之间是来自编辑器tinymce的html
来自脚本的完整代码以及何时输出找到的内容,td文本左对齐或不对齐
<?php
$html = '
<h1>mPDF</h1>
<table style="border-collapse: collapse;
font-size: 12px;
font-weight: 700;
margin-top: 5px;
border-top: 1px solid #777;
width: 100%;">
<tbody>
<tr>
<td class="contentDetails">
<h3 style="text-align: right;"><strong>text align right</strong></h3>
<h3 style="text-align: center;"><strong>text align center</strong></h3>
<h3 style="text-align: left;"><strong>text align left</strong></h3>
</td>
</tr>
</tbody>
</table>';
include("mpdf.php");
$mpdf=new mPDF('c'); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用mPDF 类创建 PDF 文件,我需要它自动调整文档高度,而不是在底部创建空白。
这是两个不同生成的 PDF 的两张图像,内容不同。左图比右图内容更多,因此底部空间更大。
我希望它根本没有空间。到目前为止,这就是我所尝试过的。
public function __construct()
{
/*
* Encoding
* Size (Array(Xmm, Ymm))
* Font-size
* Font-type
* margin_left
* margin_right
* margin_top
* margin_bottom
* margin_header
* margin_footer
* Orientation
*/
$this->mPDF = new mPDF('utf-8', array(56, 1000), 9, 'freesans', 2, 2, 2, 0, 0, 0, 'P');
}
Run Code Online (Sandbox Code Playgroud)
它以 1000 高度开始文档,以便比最初所需的长度更长。
public function write($html, $url)
{
/*
* Writing and remove the content, allows the setAutoTopMargin to work
*
* http://www.mpdf1.com/forum/discussion/621/margin-top-problems/p1
*/ …Run Code Online (Sandbox Code Playgroud) 我正在使用显示用户列表的 mpdf 创建 9 列的 pdf 在每行中,1 列用于照片。我的问题是我希望列的宽度几乎相等,但结果是,我得到了不同宽度的列。
我试图设置表格的 CSS 以及通过 mpdf 选项,但它们都不起作用。我的代码如下:
$a='<style>@page {
margin: 10pt;
}</style>';
$a .= '<table autosize="1" border="1" class="atable" style="font-family:Arial"><tr>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Sr.<br>No.</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Admission No.<br>Boarder/DayScholar<br>Admit Class<br>Admit Date<br>Exit Class<br>Exit Date</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Photograph</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Student Details<br>[Student Name<br>Father Name<br>Father Occupation<br>Mother Name<br>Mother Occupation]</th>
<th style="min-width: 60pt;max-width: 60pt; font-size:7pt">Date of Birth<br>Current Class<br>Current City<br>Board Roll No.<br>Percentage</th>
<th style="min-width: 60pt;max-width: 70pt; font-size:7pt">Old Details<br>[Address<br>Father Email<br>Father Mobile]</th>
<th style="min-width: 60pt;max-width: 75pt; font-size:7pt">Present …Run Code Online (Sandbox Code Playgroud) 我正在使用 MPDF 生成带有图像的 pdf。使用 http:// 一切正常,但是在将我的整个站点更改为 https:// 后,我只会在图像应显示的位置出现红色十字。
如果我将生成的文件作为 html 版本观看,图像都在那里,带有 https://,但在生成的 PDF 中它们没有显示。
任何提示?
更新:错误是因为 CURL(“SSL 证书问题:无法获得本地颁发者证书”)
它是通过添加curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
到 mpdf.php解决的
在这里找到答案: curl: (60) SSL 证书:无法获得本地颁发者证书
我正在使用 mPDF PHP 库生成 PDF。我能够使用默认字体配置成功生成它。但是,我想在我的 PDF 中呈现 Google 字体。我尝试使用此链接中提到的步骤,但没有奏效。下面是我使用的代码。
$mPDFO = new mPDF('utf-8', 'A4', 0, '', 10, 10, 10, 0, 0, 0, 'L');
Run Code Online (Sandbox Code Playgroud)
谁能帮我在 mPDF 中使用 Google 字体?
我正在使用 mPDF 7.x 版并尝试遵循此文档:https ://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html
我只是无法让它工作。没有错误,但字体仍然是默认的 mPDF 字体。我还尝试以另一种方式使用以下答案:
如何使用 mPDF 生成 PDF 并向其添加自定义 Google 字体?
但我想它们不起作用,因为它们可能只适用于比 7.X 旧的版本......所以这是我尝试使用 7.x 文档的信息的最新尝试。
这是我的 php 文件:
require_once __DIR__ . '/vendor/autoload.php';
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf(['tempDir' => __DIR__ . '/upload'],
['fontdata' => $fontData + [
'BentonSans' => [
'R' => 'BentonSans.ttf',
'I' => 'BentonSans-Bold.ttf',
]
],
'default_font' => 'BentonSans'
]);
$url = rawurldecode($_REQUEST['url']);
$html = file_get_contents($url); …Run Code Online (Sandbox Code Playgroud)