问题描述
我的代码html如下:
My code html like this :
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Print PDF</title>
<style type="text/css">
.footer { position: fixed; left: 0px; right: 0px; height: 50px;text-align: center; }
.footer .pagenum:before { content: counter(page); }
</style>
</head>
<body>
<h1>This is test</h1>
<table class="tg">
<tr>
<th class="tg-3wr7">kolom 1</th>
<th class="tg-3wr7">kolom 2</th>
<th class="tg-3wr7">kolom 3</th>
<th class="tg-3wr7">kolom 4</th>
<th class="tg-3wr7">kolom 5</th>
</tr>
@php ($row = 22)
@for($i=0;$i<$row;$i++)
<tr>
<td class="tg-rv4w">test 1</td>
<td class="tg-rv4w">test 1</td>
<td class="tg-rv4w">test 1</td>
<td class="tg-rv4w">test 1</td>
<td class="tg-rv4w">test 1</td>
</tr>
@endfor
</table>
<div class="footer">
<span class="pagenum"></span>
</div>
</body>
</html>
如果$ row = 22,它将仅显示1个页面:
If $row = 22, it will display only 1 page like this :
如果$ row = 202,它将显示7页;
If $row = 202, it will display 7 page like this ;
如果一页以上,第一页不显示页码。
When there is more than 1 page, the first page does not display the page number.
但是当只有一页时,第一页显示页码
But when there is only 1 page, first page displays page number
我想要的是:
我想在只有一页的情况下消失页码
I want to disappear the page number when there is only 1 page
我该怎么办?
推荐答案
-
因为dompdf_config.inc.php文件已被删除从此版本开始(不再引用),应在运行时设置所有dompdf选项。
Because the dompdf_config.inc.php file has been removed from this release (and is no longer referenced) all dompdf options should be set at run time.
现在,实例化FontMetrics类而不是静态类。为了简化从早期版本的dompdf
中嵌入脚本的迁移,我们通过
$ fontMetrics提供对实例化的
变量。请更新您的嵌入式脚本。以 FontMetrics
类的访问
为例, FontMetrics :: get_font('helvetica')
现在将是
$ fontMetrics-> getFont(' helvetica')
。
The FontMetrics class is now instantiated instead of static. To simplify migration of embedded scripts from earlier versions of dompdf we provide access to the instantiated FontMetrics
class via the $fontMetrics
variable. Please update your embedded scripts. For example, FontMetrics::get_font('helvetica')
would now be $fontMetrics->getFont('helvetica')
.
〜感谢
获取更新的信息。
~ Thanks to Dennis Ameling's answer for the updated information.
通过查看 dompdf_config.inc.php
文件。事实证明, DOMPDF_ENABLE_PHP
设置为 false
从而导致内联php脚本被忽略。我只是将 dompdf_config.custom.inc.php
编辑为以下内容,一切都很好,并且可以在视图。
by looking over the
dompdf_config.inc.php
file. As it turns out, DOMPDF_ENABLE_PHP
is set to false
thus causing the inline php script to be ignored. I simply edited dompdf_config.custom.inc.php
to the following and all is fine and working with the later code in the view
.
在dompdf / dompdf_config.custom.inc.php
In dompdf/dompdf_config.custom.inc.php
<?php
define("DOMPDF_ENABLE_PHP", true);
在运行时
$dompdf->set_option("isPhpEnabled", true);
然后,在我的html文件中
Then, in my html file
<body>
<script type="text/php">
if ( isset($pdf) ) {
// OLD
// $font = Font_Metrics::get_font("helvetica", "bold");
// $pdf->page_text(72, 18, "{PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(255,0,0));
// v.0.7.0 and greater
$x = 72;
$y = 18;
$text = "{PAGE_NUM} of {PAGE_COUNT}";
$font = $fontMetrics->get_font("helvetica", "bold");
$size = 6;
$color = array(255,0,0);
$word_space = 0.0; // default
$char_space = 0.0; // default
$angle = 0.0; // default
$pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
}
</script>
<div>
如果走这条路,别忘了重启Apache
If you go this route, don't forget to restart Apache
这篇关于如何不以pdf显示页码= 1? (hmtl CSS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!