« 許功蓋:中文字的替換 | Main | 注音符號的排版 »
在 PDF 嵌入原始文稿,依正式的規格書有兩種方式,一種是在頁面會顯示註解符號,而在這個註解符號按滑鼠右鍵會有功能表出現,可以去開檔或存檔。甚至直接 double click 這個註解圖示就可以開檔閱讀。
另外一種方式是頁面上沒有這個註解圖示,但可以由 Adobe Reader® 的功能表上 [View] => [Navigation Tabs] => [Attachments] 也會顯示出這些嵌入的檔案,從而可以開檔或存檔(前述的嵌入方式亦可以由這種方式來開檔或存檔)。
在 LaTeX 裡頭有 attachfile/attachfile2 及 embedfile 三個 package 有這樣子的功能。其中前兩者是屬於有註解圖示的,後一種則是沒有註解圖示的。我們就以最簡單的例子來看看他們是如何表現的。首先來看 attachfile package:
% vim:ts=2 sw=2 et
% attachf.tex : attachfile package test
% Edward G.J. Lee (09/02/06)
\documentclass{article}
\usepackage{attachfile}
\begin{document}
This is a test for attachfile package.
\attachfile{attachf.tex}
\end{document}
請使用 pdflatex 來編譯,以下是由 acroread 所閱覽的情形:
attachfile2 是 attachfile 的加強版,他可以支援 dvips,也就是說不一定要使用 pdflatex 來編譯。再來看看 embedfile package:
% vim:ts=2 sw=2 et
% embedf.tex : embedfile package test
% Edward G.J. Lee (09/02/06)
\documentclass{article}
\usepackage{embedfile}
\begin{document}
This is embedfile package test.
\embedfile[
stringmethod=escape,
mimetype=plain/text,
desc={This is embedfile package test.}
]{embedf.tex}
\end{document}
一樣,請使用 pdflatex 來編譯,而且需要 pdfTeX 1.30 以上的版本才行。以下是由 acroread 閱覽的情形:
這些 packages 使用上還算方便,而且彈性比較大,有一些參數選項可以加微調,詳細請參考它們的文件說明。另外有一種土法煉鋼的方式,就是把 PDF 指令直接寫入文稿中:
\documentclass{article}
\begingroup\pdfcompresslevel=0
\immediate\pdfobj
stream attr{/Type /SourceFile /SourceName (\jobname.tex)}
file{\jobname.tex}
\pdfcatalog{/SourceObject \the\pdflastobj\space 0 R}
\endgroup
\pdfcompresslevel=9
\begin{document}
This is a embedded source code test.
\end{document}
只要在 preamble 區加入那一段程式碼,由 pdflatex 編譯後就會自動嵌入原文稿。但是這樣嵌入的方式 acroread 並不支援,需要使用 pdfTeX 所附的一個小工具:pdftosrc(如果沒有附上,需自行由 pdftex 原始碼來編譯),他的使用方法如下:
pdftosrc sourceemb.pdf
即可,他會找到第一個找到的 Source object 來解開。
但如果只是簡單的將文件嵌入某個 PDF 檔中,也是有其他的方法,例如使用 pdftk 他不但可以將某檔案嵌入 PDF 中,也可以將他們取出來:
嵌入文件: pdftk your.pdf attach_files your.file output your2.pdf 嵌入有註解圖示的文件: pdftk your.pdf attach_files your.file to_page 1 output your2.pdf 取出所嵌入的文件: pdftk your.pdf unpack_files output .
這樣也是很方便,只不過需要額外安裝 pdftk 就是了。
| « | 三月 2010 | » | ||||
|---|---|---|---|---|---|---|
| 一 | 二 | 三 | 四 | 五 | 六 | 日 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||