donglian1384 2012-03-22 10:00
浏览 51
已采纳

使用PHP脚本中的条形码字体压缩MS word docx文档

Using Tinybutstrong and openTBS i created a script in PHP that opens multiple docx templates and replaces a lot of variables with values from a database. In a nutshell clients can download their unique files, add information and pictures and upload them again. This works excellent. But of coarse i wouldn't post here if there wasn't some sort of problem.

Because of the barcodes (I am using barcode fonts and embed them in Word because the documents will be scanned far later in the process), the documents get huge. Instead of 100 KB average, they'll easily get 7MB. This is a problem, because per year about 20.000 documents will be scanned. That's an extra +/- 130 GB per year.

It's a long story but we need docx, so we can't simply replace it with some sort of PHP / MySQL template that would be far more efficient.

Word has the option to just embed the font symbols that are being used to cut on the size. But that isn't an option, because the main template needs to have all chars available. It's also not an option to send the font to the users, since there are +/- 20.000 new ones each year.

Is there another solution to cut the file size or use compression. Perhaps in Word, PHP, FTP, Apache?

  • 写回答

1条回答 默认 最新

  • duanhua9398 2012-03-26 01:57
    关注

    I'm afraid the solution of using the option "Embed fonts in the file" with "Embed only characters used in the document" cannot be exploited. Ms Word saves the font using a special format with the extension ODTTF (for example, you have it in "word\fonts\font1.odttf"). But this format is binary, it seems badly documented and thus it stays as a proprietary format. Only Ms Word will be able to build such a sub-file.

    Since you haven't any lighter font for the barcode, the only solution I can see is to use image instead of font for you barcode:

    • OpenTBS has a feature to easily replace a picture inside a DOCX file (parameter "op=changepic").
    • Barcode2Image tools are easy to find in PHP. For example : Barcode Generator.

    Then you only have to code your process like this :

    1. Load the DOCX template,
    2. Create the temporary image of the barcode.
    3. Change the image inside the template.
    4. Merge the template, and save or send the result.
    5. Delete the temporary image.

    It's important to delete the temporary image only after the final merge of the template, because OpenTBS actually inserts the image only when method $tbs->Show() is called.

    It's also important to use a different temporary file for each merging because many merges can occur in the same time.

    If temporary files have a prefix or are saved into a dedicated directory, then it is advisable to clean up old temporary images regulary.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算