3

我正在使用 CFDOCUMENT 在 CF9.0.1 中创建 PDF。但是,每次我使用 CFDOCUMENT 生成新的 PDF 时,使用相同的输入,MD5 哈希值似乎有所不同。

测试代码很简单:

<cfdocument name=FileData1 format="PDF" localurl="yes" pagetype="A4"><h3>I am happy!</h3></cfdocument>
<cfdocument name=FileData2 format="PDF" localurl="yes" pagetype="A4"><h3>I am happy!</h3></cfdocument>
<cffile ACTION="write" FILE="C:\happy1.pdf" OUTPUT=#FileData1# ADDNEWLINE=NO NAMECONFLICT="Override">
<cffile ACTION="write" FILE="C:\happy2.pdf" OUTPUT=#FileData2# ADDNEWLINE=NO NAMECONFLICT="Override">

生成的两个文件都有不同的 MD5 文件哈希,尽管两个 PDF 看起来完全相同。我有一个用户要求,如果文件相同以忽略 PDF 的重新生成,那么如果给定相同的输入,有谁知道如何强制 CF9 生成具有相同 MD5 哈希(位相似性)的相同 PDF?

我运行了 HxD 十六进制文件比较,发现文件在三个部分有所不同:

  • 字体名称 eg 62176/FontName/OJSSWJ+TimesNewRomanPS (OJSSWJ 是随机的)
  • 时间戳 /CreationDate(D:20110927152929+08'00')
  • 最后的某种键:<]/Info 12 0 R/Size 13>>

提前感谢您的帮助!

4

1 回答 1

4

They will never be the same.

The timestamp /CreationDate(D:20110927152929+08'00')

The creationDate is a timestamp of when it was created, thus unless you create it at the same second every time, it wont be the same.

You might be able to modify the pdf and remove or modify this bit.

Or use a different method to determine if you should create the pdf, creating it to md5 compare the results seems like a waste of processing power.

于 2011-09-27T10:12:30.907 回答