wkhtmltopdf每次运行都会生成不同的校验和 [英] wkhtmltopdf generates a different checksum on every run

查看:144
本文介绍了wkhtmltopdf每次运行都会生成不同的校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图验证从wkhtmltopdf生成的内容在运行之间是相同的,但是,每次运行wkhtmltopdf时,我都会在同一页面上获得不同的哈希/校验和值.我们正在谈论一些真正的基础知识,例如使用html页面:

I'm trying to verify that the content generated from wkhtmltopdf is the same from run to run, however every time I run wkhtmltopdf I get a different hash / checksum value against the same page. We are talking something real basic like using an html page of:

<html>
<body>
<p> This is some text</p>
</body
</html>

每次运行wkhtmltopdf时,我都会得到一个不同的md5或sha256哈希,它使用以下惊人的一行:

I get a different md5 or sha256 hash every time I run wkhtmltopdf using an amazing line of:

./wkhtmltopdf example.html ~/Documents/a.pdf

并使用以下python哈希器:

And using a python hasher of:

def shasum(filename):
    sha = hashlib.sha256()
    with open(filename,'rb') as f: 
        for chunk in iter(lambda: f.read(128*sha.block_size), b''): 
            sha.update(chunk)
    return sha.hexdigest()

或仅将sha256与md5交换的md5版本

or the md5 version which just swaps sha256 with md5

为什么wkhtmltopdf会生成足以引起不同校验和的不同文件,并且有什么方法可以做到这一点?可以通过传递一些命令行来防止这种情况?

Why would wkhtmltopdf generate a different file enough to cause a different checksum, and is there any way to not do that? some command line that can be passed in to prevent this?

我尝试了--default-header,-no-pdf-compression和--disable-smart-shrinking

I've tried --default-header, --no-pdf-compression and --disable-smart-shrinking

这是在MAC osx上,但是我已经在其他计算机上生成了这些pdf,并以相同的结果下载了它们.

This is on a MAC osx but I've generated these pdf's on other machines and downloaded them with the same result.

wkhtmltopdf版本= 0.10.0 rc2

wkhtmltopdf version = 0.10.0 rc2

推荐答案

我尝试了此操作,并在emacs中打开了生成的PDF. wkhtmltopdf在PDF中嵌入了"/CreationDate"字段.每次运行都会有所不同,并且会破坏两次运行之间的哈希值.

I tried this and opened the resulting PDF in emacs. wkhtmltopdf is embedding a "/CreationDate" field in the PDF. It will be different for every run, and will screw up the hash values between runs.

我没有看到禁用"/CreationDate"字段的选项,但是在计算哈希值之前将其从文件中删除很简单.

I didn't see an option to disable the "/CreationDate" field, but it would be simple to strip it out of the file before computing the hash.

这篇关于wkhtmltopdf每次运行都会生成不同的校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆