问题描述
我正在使用FPDF(1.7)将TXT文件转换为PDF.我想在PDF产品中强制分页.该文本文件是使用php创建的,并成功使用了回车符(\ r).但是我无法使换页(\ f)出现在PDF中.
I am using FPDF (1.7) to convert a TXT file into PDF. I would like to force a page break in the PDF product. The text file is created using php, and successfully uses carriage returns (\r). But I cannot get form feeds (\f) to appear in the PDF.
是否有另一种方法可以通过更改原始文本文件或php代码来强制FPDF中的分页符?也许是不同的角色?现在,我有一个波浪号标记页面应该在哪里断开.
Is there another way to force a page break in FPDF by either changing the original text file or the php code? Perhaps a different character? For now, I have a tilde marking where pages should break.
如果有兴趣,我将发布用于调用FPDF的简单php:
If it is of any interest, I will post the simple php used to call FPDF:
<?php
require('fpdf.php');
$pdf = new FPDF('P','mm','A5');
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');
$pdf->SetFont('Arial','',10);
$txt = file_get_contents('comments.txt', true);
$pdf->Write(8, $txt);
$pdf->Output();
?>
感谢您的关注.
推荐答案
这里是一个主意:完整代码
Here's an idea: complete code
<?php
require('fpdf.php');
$pdf = new FPDF('P','mm','A5');
$pdf->AddPage('P');
$pdf->SetDisplayMode(real,'default');
$pdf->SetFont('Arial','',10);
$txt = file_get_contents('comments.txt', true);
$pages = explode('~', $txt);
foreach ($pages as $page) {
$pdf->Write(8, $page);
$pdf->AddPage();
}
$pdf->Output();
?>
在不清楚的情况下的简要说明:将文本分成页面",并在每个页面之间插入一个分页符.
Brief explanation in case not clear: Splits the text up into 'pages' and writes each of them with a page break in between.
可能的错误:在末尾添加额外的页面.解决方案:使用for循环而不是foreach进行迭代,并停止一页.
Possible bugs: adding extra page at the end.Solution: iterate with for loop instead of foreach and stop one page short.
另一个可能的错误:将无法再使用波浪号.(错误)解决方案:使用更复杂的字符串来表示分页符.
Another possible bug: won't be able to ever use tilde again.(Bad) solution: use a more complex string to signify a page break.
这篇关于FPDF如何强制分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!