LaTeX下使用XMP在PDF文档中嵌入许可信息

在 PDF 文档中声明许可证信息大致有两种方式。一是直接在许可证信息写在文档内(目录之前或文档末尾等位置),另一种方式则是嵌入 XMP 元数据信息。这里讲的是后面一种方式。

XMP 并不仅限于嵌入 PDF,事实上它是独立于目标媒体的标准。可以将 XMP 数据嵌入到文档、图片、音频等各种文件中。它本质上是一段 XML 文档。详情参看 wikipedia

在 LaTeX 下使用 XMP 在最终的 PDF 文档中嵌入许可证信息,我摸索出来的最好方法是使用 hyperxmp 宏包。这个宏包会和 hyperref 宏包配合,扩展 hyperref ,支持诸如 pdfcopyright、pdflicenseurl 等选项。这些选项的内容会最终添加到 DVI/PDF 文档的元信息中。

如下是一个简单的示例:

[tex]
documentclass{article}
% A Test to use hyperxmp package to include license info into the pdf file.
% The pdf file can be produced by pdflatex/xelatex.
% The license info can be seen in
% * Evince(File–Properties) (of a new version, v3.2.1 on Fedora 16 is ok).

% See also the hyperxmp package’s doc by ‘texdoc hyperxmp’.

% License of this tex file:
% Copying and distribution of this file, with or without modification,
% are permitted in any medium without royalty provided the copyright
% notice and this notice are preserved. This file is offered as-is,
% without any warranty.

title{Hyperxmp Tests}
author{Foo Bar}
usepackage{hyperref}
usepackage{hyperxmp}
hypersetup{
pdfauthor={Foo Bar},
pdfcopyright={Copyright (C) 2012 by Foo Bar.
Licensed under CC-BY-NC-SA 3.0. Some rights reserved.},
pdflicenseurl={http://creativecommons.org/licenses/by-nc-sa/3.0/},
}
usepackage{lipsum}

begin{document}
maketitle
lipsum
end{document}
[/tex]

编译可以使用 pdflatex 或者 xelatex。之后可以使用 Evince 看到如图的结果。 图片是在 Fedora 16 上 Evince 3.2.1 的截图。高版本的 Adobe Reader 应该也能看到类似的效果。注意 hyperxmp 的文档中提及使用 xelatex 引擎编译时默认情况下会压缩元数据信息,可能导致其他的 PDF 阅读器无法识别元信息。不过我的测试表明 Evince 可以识别并正确处理压缩过的元信息。另外完整的测试文件可以在我的 TeXlab 仓库中得到。测试过程中发现一个有趣的现象:当删掉 pdflicenseurl 一行后, 编译得到的 PDF 文档里的许可证信息就无法在 Evince 中看到了。

Screenshot-pdf-license-info-shown-in-evince

另外一种方式是使用 xmpincl 宏包。它需要单独的一个 .xmp 文件,而且目前只兼容 pdflatex 引擎。所以我觉得不是很方便易用。注意到 Creative Commons 网站上提供生成 .xmp 格式的许可证文件,所以这也算是一个可行的选择。这篇博文有关于这种方式的更多介绍。

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s