简体   繁体   English

dompdf中的页面计数问题

[英]Pages numeration issue in dompdf

I have to produce a document in this situation: 在这种情况下,我必须生成一个文档:

page 1 <- in the footer: "page 1 of 3" 页1 <-页脚中:“第1页,共3页”

page 2 <- in the footer: "page 2 of 3" 页2 <-页脚:“第2页,共3页”

page 3 <- in the footer: "page 3 of 3" 页3 <-页脚中:“第3页,共3页”

page 5 <- no page number 第5页<-没有页码

page 6 <- no page number 第6页<-没有页码

This is an example, the total pages number can vary and also the first part of numbered pages. 这是一个示例,总页数可以变化,编号页的第一部分也可以变化。 I have tried the inline php code of dompdf FAQ link 我已经尝试了dompdf FAQ 链接的内联php代码

I failed to do it. 我没做 And I want avoid the inline php code for security reasons. 而且出于安全原因,我想避免使用内联php代码。 How can solve this issue? 如何解决这个问题?

Thanks 谢谢

You could do this using the page_script() method which is a method of running a script per-page after the document has fully rendered. 您可以使用page_script()方法执行此操作,该方法是在文档完全呈现后每页运行一个脚本的方法。 It gives you access to all the variables you need to generate the desired output. 它使您可以访问生成所需输出所需的所有变量。

You would, of course, have to write some logic to determine how many pages get the footer. 当然,您将必须编写一些逻辑来确定有多少页面获得页脚。 If you don't know how many pages need the footer in advance you could use a global variable to store a value indicating on what page to stop. 如果您不知道预先需要多少页脚,则可以使用全局变量来存储一个值,该值指示要停止的页面。

Probably the difficult aspect of this is writing code that writes code. 也许这方面的困难是编写代码。 I've mocked up a sample that I think captures what you want. 我模拟了一个示例,该示例可以捕获您想要的内容。 You can find it here: http://eclecticgeek.com/dompdf/debug.php?identifier=ed03c2020546641d3e830a7c0115c8ae 您可以在这里找到它: http : //eclecticgeek.com/dompdf/debug.php?identifier=ed03c2020546641d3e830a7c0115c8ae

Unfortunately it's not possible to generate what you want without scripting right now. 不幸的是,如果没有脚本,就无法生成所需的内容。 You could add the script via the $dompdf object rather than as inline script ( $dompdf->get_canvas()->page_script() ). 您可以通过$ dompdf对象而不是内联脚本( $dompdf->get_canvas()->page_script() )添加脚本。 Then you could filter out any inline script/PHP from the user document. 然后,您可以从用户文档中过滤掉任何内联脚本/ PHP。

(Also answered on the support group: https://groups.google.com/d/topic/dompdf/3x_8YHctCp0/discussion ) (也在支持小组上回答: https : //groups.google.com/d/topic/dompdf/3x_8YHctCp0/discussion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM