用PHP进行PDF编辑? [英] PDF Editing in PHP?

查看:113
本文介绍了用PHP进行PDF编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道用PHP编辑PDF的好方法吗?最好是开源/零许可证费用方法. :)

Does anyone know of a good method for editing PDFs in PHP? Preferably open-source/zero-license cost methods. :)

我正在考虑打开PDF文件,替换PDF中的文本,然后写出PDF的修改版本吗?

I am thinking along the lines of opening a PDF file, replacing text in the PDF and then writing out the modified version of the PDF?

我过去曾经使用FPDF以编程方式创建PDF文件,但有时发现它有点笨拙.

I have programmatically created PDF files in the past using FPDF, but found it a little unwieldy at times.

推荐答案

如果采用填空"方法,则可以将文本精确地放置在页面上的任何位置.因此,将丢失的文本添加到文档中相对容易(即使不是很乏味).例如,使用Zend Framework:

If you are taking a 'fill in the blank' approach, you can precisely position text anywhere you want on the page. So it's relatively easy (if not a bit tedious) to add the missing text to the document. For example with Zend Framework:

<?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');

如果您要替换内联内容,例如"[占位符字符串]",它将变得更加复杂.尽管从技术上讲是可行的,但您很可能会弄乱页面的布局.

If you're trying to replace inline content, such as a "[placeholder string]," it gets much more complicated. While it's technically possible to do, you're likely to mess up the layout of the page.

PDF文档由一组基本绘图操作组成:此处的行,此处的图像,此处的文本块等.它不包含有关这些基元的布局意图的任何信息.

A PDF document is comprised of a set of primitive drawing operations: line here, image here, text chunk there, etc. It does not contain any information about the layout intent of those primitives.

这篇关于用PHP进行PDF编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆