修改 DOC(非 .docx)文件中的文本
我已阅读 PDF 编辑 PHP?,但还没有找到我想要的内容为了。
基本上我需要获取一个 DOC(读取:not .docx)文件,该文件将用作模板,找到某些字符串(例如,[患者编号]、[站点编号]等)替换我将从数据库中检索它们的值,然后将该文件另存为 .pdf 文件。
以下是重要的一点,
- 我宁愿避免使用 zend 框架(或任何框架),以保持应用程序的软件轻便,并且不必在该项目中维护另一个第三方代码段(jquery、jquery-UI、jqGrid 等)
- 我无法使用 DOCX,因为我的工作计算机上没有安装该版本的 Office。我最终会的,但我不知道什么时候会发生,我需要尽快完成编码
- 。最后转换为 PDF 是可选的。我希望它尽可能具有互操作性。我的系统上已经有 ezPdf 和 fPdf,所以也许我可以将生成的 Word 二进制文件输入 ezPdf/fPdf 并以这种方式生成 PDF。
是否有任何 PHP 库允许读取 .doc 文件,然后能够编辑文本,然后将其写回磁盘?
我尝试过 ezPdf 和 fPdf,但是指定文本块坐标太繁琐,并且涉及太多猜测和试验。错误。
提前致谢!
I've read PDF Editing in PHP? but haven't found quite what I'm looking for.
Basically I need to take a DOC (read: not .docx) file, which will be used as a template, find certain strings (e.g, [Patient Number], [Site Number], etc) replace them with values that I'll retrieve from a database and then save that file as a .pdf file.
Here's the important points
- I'd rather avoid zend framework (or any framework) for the purpose of keeping my application's software light and not having to maintain another 3rd party piece of code in this project (jquery,jquery-UI,jqGrid, etc)
- I can't use DOCX because I don't have that version of Office installed on my work computer. I will eventually, but I don't know when that'll happen and I need to finish coding this ASAP
- The converting to PDF at the end is somewhat optional. I'd like to have it as interoperable as possible. I already have ezPdf and fPdf on the system, so perhaps I can just feed the generated Word binary into ezPdf/fPdf and generate the PDF that way.
Are there any PHP libraries out there that allow reading a .doc file and then the ability to edit the text and then write it back to the disk?
I've tried ezPdf and fPdf, but the specifying of text block coordinates got too tedious and involved too much guesswork and trial & error.
Thanks in advanced!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果它是标准化形式并且文本不需要根据输入的内容进行重排(例如,您使用固定框和/线,而不是在段落中插入句子),您可能会考虑将形式视为图像,然后使用 PDF api(acrobat pdf 支持表单)或将结果作为 pdf 文件在固定坐标处写入文本。
If it is a standardized form AND the text does not need to reflow based upon what is entered (e.g. you are using fixed boxes and/lines, rather than inserting sentences into a paragraph), you might consider the straightforward idea of treating the form as an image and then writing text to it at fixed coordinates either using a PDF api (acrobat pdf supports forms) or emitting the resulting as a pdf file.
在 PHP 中读取/写入 MS Word 文件
Reading/Writing a MS Word file in PHP
我最终使用了 docx(在我的同事(他有 Office 2007)的帮助下为我导出了文件)并完全(至少现在)放弃了 PDF 转换。
我确实安装了 phpdocx 并在使用了一堆扩展(XSL、mbstring、等)我必须让服务器管理员来安装,它确实根据我生成的 docx 文件生成了 PDF,它没有转换标题中使用的样式或图像,所以它看起来绝对可怕。
由于时间限制,我不得不完全跳过 PDF 转换,只使用 docx 文件。这将是我们将来重新访问的内容,但就目前而言,它是 docx。
我们也可能会研究 LiveDocX,但不幸的是,它涉及将文件上传到云端,因为这些文件包含患者日期(但是,大多数情况下是盲目的),我必须获得我们法律部门的批准,以确保我们遵守 HIPAA 隐私法。
I ended up using docx (with the assistance of my co-worker (who had office 2007) exporting the file for me) and completely (for now at least) forsaking the PDF conversion.
I did install phpdocx and after juggling around with a bunch of extensions (XSL, mbstring, etc) I had to get the server administrator to install, it did generate the PDF based off of my generated docx file, it didn't convert the styles or image used in the header, so it looked absolutely horrible.
Due to time constraints, I had to completely skip out on PDF conversion and just use the docx file. This will be something we re-visit in the future, but for now, docx it is.
We might also look into LiveDocX, but unfortunately that deals with uploading files to the cloud and because these files contain patient date (however, mostly blinded) I have to get approval from our legal department to make sure we're in accordance with HIPAA privacy laws.