将多个 pdf 嵌入(不是连接)到一个中(使用 php)

发布于 2024-12-28 21:42:37 字数 522 浏览 2 评论 0原文

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

用例如下:

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

示例:

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

template.pdf

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

Is it possible to embedd a pdf file into another using php?
If not php, can this be made using another open source software?

The use case is the following:

I have a template.pdf file with empty spots which should be filled dynamically
with another pdf files.

Example:

I have a pdf file with four empty slots, the firts three should be filled
with the contents of pdf files: a.pdf, b.pdf, c.pdf and the last one should
be filled with text dinamically created.

template.pdf

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄想挽回 2025-01-04 21:42:37

我能够使用 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;
?>

I was able to fulfill my requirements using tcpdf.php and fpdi.php.

It's not the most beautiful code, but It's working.

<?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;
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文