2012-01-24 7 views
1

phpを使用してpdfファイルを別のファイルに埋め込むことはできますか? phpでない場合は、別のオープンソースソフトウェアを使用してこれを行うことはできますか?複数のpdfファイルを1つにまとめる(PHPを使用)

ユースケースは以下の通りです:

私は別のPDFファイルを動的に 満たされるべき空のスポットとtemplate.pdfファイルを持っています。

例:c.pdfb.pdfa.pdfと最後の1が dinamicallyテキストで満たされる必要があります。

私は4つの空のスロットを使用してPDFファイルを持って、firts 3は、PDFファイルの内容を に満たされる必要があります作成した。

template.pdf 

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

空のスロットは、定義された高さと幅を持つか、コンテンツとともに増加する必要がありますか? –

+0

重複していなければ密接に関連しています:[PDF出力を伴うPHP PDFテンプレートライブラリ](http://stackoverflow.com/q/4416667) –

+0

@Pekka:空のスロットは定義された幅と高さです。 – Cesar

答えて

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; 
?> 
関連する問題