在 PHP 中编辑 PDF? [英] Edit PDF en PHP?

查看:84
本文介绍了在 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?

前端

推荐答案

如果您采用的是填空"方法,您可以将文本精确地放置在页面上您想要的任何位置.因此,将缺失的文本添加到文档中相对容易(如果不是有点乏味的话).例如使用 Zend 框架:

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天全站免登陆