我希望能夠使用PHP在現有的pdf文檔上書寫/覆蓋文本。我希望能做的是有一個可以作爲模板的PDF文檔,並通過打開模板文檔,覆蓋相關文本並將結果作爲新文檔提供給他們來填補空白。模板文檔是單頁,因此頁面合併/操作不是必需的。在PHP中使用PDF模板文檔進行書寫/繪圖
有沒有免費的圖書館可以做到這一點?我應該看的任何地方?我所做的大多數搜索似乎都處理合並文檔/添加頁面,而不是將內容覆蓋在現有頁面上。
感謝。
*編輯: 這裏是我做過什麼: 1.下載FPDF 2.下載FPDI + FPDF_TPL從
http://www.setasign.de/products/pdf-php-solutions/fpdi/downloads/
這裏是任何未來的娃兒一些示例代碼(改編自樣本在www.setasign.de):
<?php
include('fpdf.php');
include('fpdi.php');
// initiate FPDI
$pdf =& new FPDI();
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile('templatedoc.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page as the template
$pdf->useTemplate($tplIdx, 0, 0);
// now write some text above the imported page
$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(25, 25);
$pdf->Write(0, "This is just a simple text");
$pdf->Output('newpdf.pdf', 'D');
?>
很高興你在答案的例子中編輯過,爲此+1,容易不是嗎? :-) – Orbling 2010-11-29 02:13:00
是的!而且在幾周內我會忘記我已經完成的工作並再次尋找它,這也會對我有所幫助:P(對於我的項目還沒有實現它,只是發現瞭如何)。 – 2010-12-02 03:14:09
你有沒有找到任何方法來追加圖像在現有的文件,而不是寫文字? – 2014-10-15 06:52:13