gpt4 book ai didi

java - 如何使用嵌入式图像减小 RTF 的大小?

转载 作者:搜寻专家 更新时间:2023-10-30 19:40:10 25 4
gpt4 key购买 nike

我们有一些代码可以从 RTF 模板生成 RTF 文档。它基本上是在 RTF 文件中进行字符串搜索和特殊标签的替换。这可以通过网页访问。

通常,处理时间非常快。

但是,我们需要在模板中嵌入图像。我们一直使用 Word 的“插入/图片/来自文件...”功能将这些作为 JPEG 图像嵌入。但我们发现生成的 RTF 文件大小在很大程度上取决于图像。

例如,我插入了一个 20k JPEG Logo (基本上是带有一些文本的纯色背景)。 RTF 文件的大小从大约 390k(没有图像)增加到 510k(有图像)。

然后我们插入一个包含屏幕截图的 JPEG,即图像包含文本、多种颜色等。JPEG 大约为 150k。使用此图像,RTF 文件的大小从 390k 增加到 3.5MB。

因此,Word 用于将图像存储到 RTF 中的编码并不是线性执行的。我猜这取决于 JPEG 图像中的内容。

我需要将 RTF 模板的大小保持在最低限度,以尽量将我们的文件处理时间降到最低。

  • 有没有人对如何最小化带有嵌入图像的 RTF 文件的大小有任何想法?
  • 有什么方法可以控制 Word 使用的编码吗?我在任何地方都看不到任何选项。
  • 有人知道 Word/RTF 使用什么类型的二进制编码吗?

提前致谢。

最佳答案

这是最好的解决方案

http://support.microsoft.com/kb/224663

摘录:

SYMPTOMS

When you save a Microsoft Word document that contains an EMF, PNG, GIF, or JPEG graphic as a different file format (for example, Word 6.0/95 (.doc) or Rich Text Format (.rtf)), the file size of the document may dramatically increase.

For example, a Microsoft Word 2000 document that contains a JPEG graphic that is saved as a Word 2000 document may have a file size of 45,568 bytes (44.5KB). However, when you save this file as Word 6.0/95 (.doc) or as Rich Text Format (.rtf), the file size may grow to 1,289,728 bytes (1.22MB).

CAUSE

This functionality is by design in Microsoft Word. If an EMF, a PNG, a GIF, or a JPEG graphic is inserted into a Word document, when the document is saved, two copies of the graphic are saved in the document. Graphics are saved in the applicable EMF, PNG, GIF, or JPEG format and are also converted to WMF (Windows Metafile) format.

RESOLUTION

Warning If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

To prevent Word from saving two copies of the graphic in the document, and to reduce the file size of the document, add the ExportPictureWithMetafile=0 string value to the Microsoft Windows registry.

关于java - 如何使用嵌入式图像减小 RTF 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1405054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com