Tcpdf自动设置了表格

时间:2017-02-16 09:44:07

标签: php pdf tcpdf

我使用tcpdf成功生成了pdf 现在我想在一张纸上将这一页翻到4页

enter image description here

脚本没有问题...我只是想让它自动设置persheet 4所以用户不必每次都要打印时配置设置..有没有办法做到这一点,所以我不必改变我的编码

如建议的那样,我使用fpdi

             $pdf->Output($st.'/TEST.PDF', 'F');
            require_once(APPPATH.'libraries/FPDI/fpdf_tpl.php');
            require_once(APPPATH.'libraries/FPDI/fpdi.php');


            $filename = $st.'/TEST.PDF';

            $pdfx = new FPDI();


            //exit();

            $pageCount = $pdfx->setSourceFile($filename);


            //echo $pageCount;
            //exit();

            $w = $pdfx->GetPageWidth() / 2 - 15;
            $h = 0;

            $_x = $x = 10;
            $_y = $y = 10;

            $pdfx->AddPage();
            for ($n = 1; $n <= $pageCount; $n++) {
                $tplIdx = $pdfx->importPage($n);

                $size = $pdfx->useTemplate($tplIdx, $x, $y, $w);
                $pdfx->Rect($x, $y, $size['w'], $size['h']);
                $h = max($h, $size['h']);
                if ($n % 2 == 0) {
                    $y += $h + 10;
                    $x = $_x;
                    $h = 0;
                } else {
                    $x += $w + 10;
                }

                if ($n % 4 == 0 && $n != $pageCount) {
                    $pdfx->AddPage();
                    $x = $_x;
                    $y = $_y;
                }
            }

            $pdfx->Output('thumbnails.pdf', 'F');

但是我收到了错误消息

遇到PHP错误

严重性:警告

消息:fopen():不支持远程主机文件访问,file://thumbnails.pdf

文件名:include / tcpdf_static.php

行号:2466 遇到PHP错误

严重性:警告

消息:fopen(file://thumbnails.pdf):无法打开流:找不到合适的包装器

文件名:include / tcpdf_static.php

行号:2466 TCPDF错误:无法创建输出文件:thumbnails.pdf

这是codeignighter中的冲突库吗?我加载tcpdf然后我需要一次fpdi库

哦,我想我知道问题是关于保存位置...没关系我重新编辑我的输出 $ pdfx-&gt;输出(&#39; thumbnails.pdf&#39;,&#39; I&#39;);

1 个答案:

答案 0 :(得分:1)

有一个印前术语 - imposition - 用于你所谈论的内容。我猜TCPDF本身并没有拼版工具。

您可以在TCPDF生成的文件上使用FPDI编写一个简单的拼版工具(检查this example out),或者查看另一个名为PDFlib的库,具体来说,  该库的pdfimpose脚本。