我有一份文件,其硬拷贝和软拷贝之间存在明显差异。
类似于一些文本框,在硬拷贝中应该以粗体和大号字体打印,但在电子拷贝版本中应该隐藏(或尽可能不显眼)。
在乳胶中是否有可能合并pdf中可打印但未显示的材料?
答案1
更新
作为马丁·施罗德和亚历克斯指出,现在有三个软件包支持开箱即用的仅打印内容:ocg-p
,ocgx
和ocgx2
。创建可选内容组的语法对于它们所有都是相同的,但ocgx2
还有支持 LuaLaTeX 的额外优势:
\documentclass{article}
\usepackage{ocgx2}
\begin{document}
This text is always visible.
\begin{ocg}[printocg=always]{Hard copy}{printonly}{0}
This can only be seen if the document is printed.
\end{ocg}
This text is visible in both the soft and the hard copy.
\end{document}
输出
电子版:
硬拷贝:
原始答案
这可以使用可选内容组,提供属性ViewState
并PrintState
控制组内容是否应在软拷贝或硬拷贝中可见。以下概念验证定义了printonly
仅在打印文档时才可见的内容的环境。
\documentclass{article}
\makeatletter
% Create optional content group dictionary for print-only content
\immediate\pdfobj{%
<<%
/Type/OCG%
/Name(Hard copy)%
/Usage<<%
/Print<<%
/PrintState/ON%
>>%
/View<<%
/ViewState/OFF%
>>%
>>%
>>}
\xdef\ocg@printonly{\the\pdflastobj\space 0 R}
% Add OCG to resource dictionary
\immediate\pdfobj{<</OCprintonly\space\ocg@printonly\space>>}
\xdef\ocg@mapping{\the\pdflastobj\space 0 R}%
\begingroup
\edef\x{\endgroup
\pdfpageresources{%
\the\pdfpageresources%
/Properties \ocg@mapping%
}%
}%
\x
% List of all optional content groups
\newcount\ocg@listocgs
\pdfobj reserveobjnum
\ocg@listocgs=\pdflastobj
% Create optional content usage dictionary
\pdfcatalog{%
/OCProperties<<%
/OCGs \the\ocg@listocgs\space0 R\space%
/D<<%
/Order [\ocg@printonly\space]% if this line is removed, the OCG isn't shown in the layer toolbar of the viewer
/OFF [\ocg@printonly\space]%
/AS[%
<<%
/Event/View%
/OCGs \the\ocg@listocgs\space0 R\space%
/Category[/View]%
>>%
<<%
/Event/Print%
/OCGs \the\ocg@listocgs\space0 R\space%
/Category[/Print]%
>>%
<<%
/Event/Export%
/OCGs \the\ocg@listocgs\space0 R\space%
/Category[/Print]%
>>%
]%
>>%
>>}
% List all OCGs
\AtEndDocument{%
\immediate\pdfobj useobjnum \ocg@listocgs {%
[\ocg@printonly\space]%
}%
}%
% "printonly" environment for content which should only be visible when the document is printed
\newenvironment{printonly}{%
\pdfliteral{/OC /OCprintonly\space BDC}%
}{%
\pdfliteral{EMC}%
}
\makeatother
\begin{document}
This text is always visible.
\begin{printonly}
This can only be seen if the document is printed.
\end{printonly}
This text is visible in both the soft and the hard copy.
\end{document}
代码受到很大启发ocg.sty
,其分布为渐近线;可以找到一些相关信息在 texample.net 上。但是,本示例无需安装该包。