任何人都不会知道的一个很好的方法进行编辑Pdf在PHP?好的开放源/零许可证成本的方法。:)

我想到的是沿线的开PDF文件,替代文本的PDF格式,并随后写出的修改版本PDF?

我编程的方式创建的PDF文件在过去使用FPDF,但发现它有点笨拙的时候。

有帮助吗?

解决方案

如果你把一个'在填补空白的方法,可以精确定位的文本的任何你想要的一页。所以它是相对比较容易(如果不是有点乏味的)添加所缺文本的文件。例如,与Zend框架:

<?php
require_once 'Zend/Pdf.php';

$pdf = Zend_Pdf::load('blank.pdf');
$page = $pdf->pages[0];
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
$page->setFont($font, 12);
$page->drawText('Hello world!', 72, 720);
$pdf->save('zend.pdf');

如果你试图取代联内容,如"[符串的]",它变得更加复杂。虽然这在技术上可以做到的,你可能会搞砸了的布局的网页。

PDF文档中包含一套原始绘图行动:线在这里,像在这里,文本块在那里,等等。它并不包含任何有关信息的布局的意图的那些元。

其他提示

有一个免费的和易于使用PDF类创造的PDF文件。这就是所谓 FPDF.在结合与FPDI(http://www.setasign.de/products/pdf-php-solutions/fpdi)它甚至可以编辑的PDF文件。以下代码显示如何使用FPDF和FPDI,以填补一个现有的礼券的用户数据。

require_once('fpdf.php'); 
require_once('fpdi.php'); 
$pdf = new FPDI();

$pdf->AddPage(); 

$pdf->setSourceFile('gift_coupon.pdf'); 
// import page 1 
$tplIdx = $this->pdf->importPage(1); 
//use the imported page and place it at point 0,0; calculate width and height
//automaticallay and ajust the page size to the size of the imported page 
$this->pdf->useTemplate($tplIdx, 0, 0, 0, 0, true); 

// now write some text above the imported page 
$this->pdf->SetFont('Arial', '', '13'); 
$this->pdf->SetTextColor(0,0,0);
//set position in pdf document
$this->pdf->SetXY(20, 20);
//first parameter defines the line height
$this->pdf->Write(0, 'gift code');
//force the browser to download the output
$this->pdf->Output('gift_coupon_generated.pdf', 'D');

如果你需要真正简单的Pdf文件,然后Zend或 FPDF 是好的。但是我找到他们困难和令人沮丧的工作。此外,由于API工作,有没有好的方法来单独内容的演示,从业务逻辑。

出于这一原因,我用 dompdf, 自动转换HTML和CSS PDF文件。你可以制定出一个模板只是因为你会为一个HTML网页和使用标准HTML语法。你甚至可以包括外部CSS文件。图书馆是不完美的和非常复杂的标记或css有时会错位,但是我还没有找到任何其他工作。

Zend框架可以负载和编辑现有的PDF文件。我认为,它支持修订。

我用它来创建文档中的一个项目,以及它的伟大工程。从来没有编辑之一。

检查的医生 在这里,

不知道如果这是一个选项,但它的工作非常相似Zend's pdf库,但你不需要一堆的额外的代码(zend框架)。它仅仅延伸FPDF.

http://www.setasign.de/products/pdf-php-solutions/fpdi/

在这里你基本上可以做同样的事情。载PDF,写在它的顶部,然后保存到一个新的PDF。在FPDI你基本上插入PDF作为一个像这样你可以把任何你想要超过它。

但同样,这里使用FPDF,所以如果你不想使用,那么它不会的工作。

PDF/pdflib extension documentation in PHP是疏(东西已经注意到在bugs.php.net)-我建议你使用Zend图书馆。

Tcpdf也是一个很好的liabrary产生pdf在php http://www.tcpdf.org/

我真的很高的希望dompdf(这是一个很酷的想法),但定位问题是一个主要因素在我的使用fpdf.虽然繁琐,为每一个元素都是集;它是强大的,因为所有出去。

我躺在一个图像下面我的工作区的文件把我的布局上的配合。它一直是足够的,甚至对于列(需要一点点的php string计算,但没有太令人兴奋).

好运气。

我们使用 pdflib 创建PDF文件,从我们的轨道应用程序。它已经绑定PHP,一吨的其他语言。

我们使用的商业版本,但他们也有一个 自由/开放源代码版本 其中有一些限制。

不幸的是,这只允许建立PDF。

如果你想开的"编辑"现有的文件,提供pdflib 一种产品,不这个这个, 但成本 很多

<?php

//getting new instance
$pdfFile = new_pdf();

PDF_open_file($pdfFile, " ");

//document info
pdf_set_info($pdfFile, "Auther", "Ahmed Elbshry");
pdf_set_info($pdfFile, "Creator", "Ahmed Elbshry");
pdf_set_info($pdfFile, "Title", "PDFlib");
pdf_set_info($pdfFile, "Subject", "Using PDFlib");

//starting our page and define the width and highet of the document
pdf_begin_page($pdfFile, 595, 842);

//check if Arial font is found, or exit
if($font = PDF_findfont($pdfFile, "Arial", "winansi", 1)) {
    PDF_setfont($pdfFile, $font, 12);
} else {
    echo ("Font Not Found!");
    PDF_end_page($pdfFile);
    PDF_close($pdfFile);
    PDF_delete($pdfFile);
    exit();
}

//start writing from the point 50,780
PDF_show_xy($pdfFile, "This Text In Arial Font", 50, 780);
PDF_end_page($pdfFile);
PDF_close($pdfFile);

//store the pdf document in $pdf
$pdf = PDF_get_buffer($pdfFile);
//get  the len to tell the browser about it
$pdflen = strlen($pdfFile);

//telling the browser about the pdf document
header("Content-type: application/pdf");
header("Content-length: $pdflen");
header("Content-Disposition: inline; filename=phpMade.pdf");
//output the document
print($pdf);
//delete the object
PDF_delete($pdfFile);
?>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top