【问题标题】:Embedd (not concat) multiple pdf into one (using php)嵌入(非连接)多个 pdf 为一个(使用 php)
【发布时间】:2012-02-18 04:27:40
【问题描述】:

是否可以使用 php 将 pdf 文件嵌入到另一个文件中? 如果不是php,可以用其他开源软件做吗?

用例如下:

我有一个 template.pdf 文件,其中包含应该动态填充的空白点 与另一个 pdf 文件。

例子:

我有一个 pdf 文件有四个空位,前三个应该被填满 pdf文件的内容:a.pdfb.pdfc.pdf,最后一个应该 用动态创建的文本填充。

template.pdf

+-----------------------+-------+-------+
|         a.pdf         | b.pdf | c.pdf |
+-----------------------+-------+-------+
|        embedded dynamic text          |
+---------------------------------------+

【问题讨论】:

  • 空槽是定义了高度和宽度还是必须随着内容增长?
  • 如果不重复则密切相关:PHP PDF template library with PDF output?
  • @Pekka:空槽具有定义的宽度和高度。
  • 那么你可能有机会!那么我的链接问题不是欺骗。
  • @Pekka:前段时间我找到了解决问题的方法。如果您有兴趣...

标签: php pdf-generation embed


【解决方案1】:

我能够使用tcpdf.phpfpdi.php 满足我的要求。

这不是最漂亮的代码,但它正在工作。

<?php

require_once dirname(__FILE__) . '/pdf-lib/tcpdf/tcpdf.php';
require_once dirname(__FILE__) . '/pdf-lib/fpdi/fpdi.php';


$my_base_path = dirname(__FILE__);


$pdf = new FPDI('P', 'mm', 'LETTER', true, 'UTF-8', false, true);


//following is the style pf the boxes
$style = array('width' => 0.3, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0,  'color' => array(0, 0, 0));

/*
 * Set the template file
 */
$pdf->setSourceFile($my_base_path . '/template.pdf');
$tplidx = $pdf->ImportPage(1);
$pdf->addPage();
$pdf->useTemplate($tplidx);

/*
 * Set file1.pdf
 * Width of a.pdf + b.pdf
 */
$pdf->setSourceFile($my_base_path . '/file1.pdf');
$pdf->setPage(1);
$tplidx = $pdf->ImportPage(1);
$size = $pdf->useTemplate($tplidx, 12.4, 25.90, 124);
$pdf->Cell(12.4, 26.67);
$pdf->Rect(80.29, 62.147, 55.919, 62.815, 'D', $style);// box around the ballot

/*
 * Set file2.pdf
 * Width of c.pdf
 */
$pdf->setSourceFile($my_base_path . '/file2.pdf');
$pdf->setPage(1);
$tplidx = $pdf->ImportPage(1);
$size = $pdf->useTemplate($tplidx, 147.29, 26.67, 56.0);
$pdf->Cell(147.29, 26.67);
$pdf->Rect(147.349, 62.147, 55.919, 62.815, 'D', $style);// box around the ballot



/*
 * Set embedded dynamic text
 */

$text = 'embedded dynamic text';

$pdf->setPage(1);
$pdf->setXY(12.6, 147.24);

//$pdf->Cell(0, 0, $text_nombre, 0, 0, 'C');
$pdf->writeHTMLCell(0, 0, 12.6, 147.24, $text, 0, 0, 0, true, 'C');


$pdf->Output('out.pdf', 'I');
exit;
?>

【讨论】:

    猜你喜欢
    • 2019-01-07
    • 2012-01-25
    • 1970-01-01
    • 2013-08-07
    • 2011-07-05
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2010-09-07
    相关资源
    最近更新 更多