Generate ODT documents with dynamic images in PHP

本小妞迷上赌 提交于 2020-01-02 06:11:34

问题


I maintain a couple of web databases based on PHP and mySQL on a shared hosting package. The databases have a mechanism for the user to upload OpenOffice documents with placeholders:

[person.name] [person.address] [person.postcode]

I then use this great PHP tool to run through the OpenOffice document and insert values from the database into it. The result is again, an OpenOffice document.

What it can't do is dynamic images.

Does anybody know a - preferably PHP-only - solution to insert images into OpenOffice documents?

  • I know PUNO. Can't use it in this context because it's shared hosting.
  • I know OpenOffice can be run as a daemon - ditto.
  • I know phpDocWriter. It was great for SXW files but is dead now.
  • I know OpenDocument is a collection of XML files in a ZIP file. I once tried to programmatically add a caption to every image in a ODT document. It drove me fricking crazy. I look with admiration upon developers who work with the format, but it's not for me.

I would really appreciate any hints on existing solutions.


回答1:


I think odtPHP might be what you're looking for

is seems to be able to insert images on a placeholder in the document and reads simply from an array to see which image to place.

http://www.odtphp.com/index.php?i=tutorials&p=tutorial5

Now, if you do this as a post-process after your current code, or simply use it instead of TBS, you got everything you need IMHO

Alternatively, you can include a default image with a certain filename in your document, and simply replace that imagefile in the archive.




回答2:


There is a new version of TbsOOo, it's OpenTBS and it has a feature for inserting/changing a picture in the file.

http://www.tinybutstrong.com/opentbs.php




回答3:


Did you try to use the AddFileToDoc method to add an image to the document?

The documentation on this method is here:

http://www.tinybutstrong.com/tbsooo.php#AddFileToDoc



来源:https://stackoverflow.com/questions/1780130/generate-odt-documents-with-dynamic-images-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!