| 1 |
% File: thumbpdf.tex |
| 2 |
% Project: thumbpdf |
| 3 |
% Version: 2018/09/07 v3.17 |
| 4 |
% Author: Heiko Oberdiek |
| 5 |
% |
| 6 |
% Copyright: Copyright (C) 1999-2018 Heiko Oberdiek. |
| 7 |
% |
| 8 |
% This work may be distributed and/or modified under |
| 9 |
% the conditions of the LaTeX Project Public License, |
| 10 |
% either version 1.3 of this license or (at your option) |
| 11 |
% any later version. The latest version of this license |
| 12 |
% is in |
| 13 |
% http://www.latex-project.org/lppl.txt |
| 14 |
% and version 1.3 or later is part of all distributions |
| 15 |
% of LaTeX version 2003/12/01 or later. |
| 16 |
% |
| 17 |
% This work has the LPPL maintenance status "maintained". |
| 18 |
% |
| 19 |
% This Current Maintainer of this work is Heiko Oberdiek. |
| 20 |
% |
| 21 |
% See file "readme.txt" for a list of files that |
| 22 |
% belong to this project. |
| 23 |
% |
| 24 |
% Function: Program to include thumbnails as images. |
| 25 |
% It looks for thumbnail files `thb*.png' and |
| 26 |
% includes them as images in the output pdf file |
| 27 |
% `thumbpdf.pdf'. The perl script `thumbpdf(.pl)' |
| 28 |
% automatically calls pdftex with this file to |
| 29 |
% generate `thumbpdf.pdf' and produces the data |
| 30 |
% files, that contains the necessary pdf image objects |
| 31 |
% for package `thumbpdf.sty'. |
| 32 |
% |
| 33 |
% Requirement: * pdftex |
| 34 |
% * thumbnails `thb*.png' |
| 35 |
% |
| 36 |
% Use: * Syntax: pdftex thumbpdf |
| 37 |
% * \thumbmax: |
| 38 |
% Because it takes some time to look for 1000 thumbnail |
| 39 |
% files, a maximum number can be specified: |
| 40 |
% pdftex \def\thumbmax{20}\input thumbpdf |
| 41 |
% * \thumbjob: |
| 42 |
% This macro contains the name of the user's TeX file |
| 43 |
% without extension (`<jobname>'). It is needed to build |
| 44 |
% the name of the optional file `<jobname>.tno', that |
| 45 |
% contains extra thumbnail declarations: |
| 46 |
% pdftex \def\thumbjob{example}\input thumbpdf |
| 47 |
% Then `example.tno' are read to get additional |
| 48 |
% thumbnails. |
| 49 |
% |
| 50 |
% History: 1999/02/14 v1.0: first public release |
| 51 |
% 1999/02/23 v1.1 |
| 52 |
% 1999/03/01 v1.2 |
| 53 |
% 1999/03/12 v1.3: Copyright: LPPL |
| 54 |
% 1999/05/05 v1.4 |
| 55 |
% 1999/06/13 v1.5 |
| 56 |
% 1999/07/27 v1.6 |
| 57 |
% 1999/08/08 v1.7: pdfTeX 0.14a |
| 58 |
% 1999/09/09 v1.8 |
| 59 |
% 1999/09/16 v1.9 |
| 60 |
% 2000/01/11 v1.10: \immediate before \pdfximage removed, |
| 61 |
% because it is obsolete and because of a problem with |
| 62 |
% a pre-release version of pdfTeX 0.14d. |
| 63 |
% 2000/01/19 v1.11 |
| 64 |
% 2000/02/11 v1.12: \thumbjob added. |
| 65 |
% 2000/02/22 v2.0: Looking for `\thumbjob.tno' only, the |
| 66 |
% file name `thumbopt.tex' is not supported anymore. |
| 67 |
% 2000/02/28 v2.1 |
| 68 |
% 2000/03/07 v2.2 |
| 69 |
% 2000/03/22 v2.3 |
| 70 |
% 2000/04/10 v2.4: Version is also printed on screen. |
| 71 |
% 2000/07/29 v2.5 |
| 72 |
% 2000/09/27 v2.6 |
| 73 |
% 2000/10/27 v2.7 |
| 74 |
% 2001/01/12 v2.8 |
| 75 |
% 2001/03/29 v2.9 |
| 76 |
% 2001/04/02 v2.10 |
| 77 |
% 2001/04/26 v2.11 |
| 78 |
% 2002/01/11 v3.0 |
| 79 |
% 2002/05/26 v3.1 |
| 80 |
% 2002/05/26 v3.2 |
| 81 |
% 2003/03/19 v3.3 |
| 82 |
% 2003/06/06 v3.4 |
| 83 |
% 2004/10/24 v3.5: LPPL 1.3. |
| 84 |
% 2004/11/19 v3.6 |
| 85 |
% 2004/11/19 v3.7: For easier debugging, the special |
| 86 |
% thumbpdf objects are now valid PDF objects that |
| 87 |
% are referenced in the Catalog. |
| 88 |
% 2005/07/06 v3.8 |
| 89 |
% 2007/11/07 v3.9 |
| 90 |
% 2008/04/16 v3.10 |
| 91 |
% 2010/07/07 v3.11: \pdfcompresslevel=0 and |
| 92 |
% \pdfminorversion=4 added. |
| 93 |
% 2011/08/09 v3.12 |
| 94 |
% 2011/08/10 v3.13 |
| 95 |
% 2012/04/09 v3.14 |
| 96 |
% 2012/04/18 v3.15 |
| 97 |
% 2014/07/15 v3.16 |
| 98 |
% 2018/09/07 v3.17 https://github.com/ho-tex/thumbpdf |
| 99 |
|
| 100 |
\immediate\write16{% |
| 101 |
File: thumbpdf.tex 2018/09/07 v3.17 % |
| 102 |
Including thumbnails as images (HO)% |
| 103 |
} |
| 104 |
\immediate\write16{% |
| 105 |
****************************************************************} |
| 106 |
\immediate\write16{% |
| 107 |
* Generating `thumbpdf.pdf', each page with a found thumbnail. *} |
| 108 |
\immediate\write16{% |
| 109 |
****************************************************************} |
| 110 |
|
| 111 |
\def\END{\csname @@end\endcsname\end} |
| 112 |
|
| 113 |
% Check, if LaTeX format |
| 114 |
\ifx\mbox\undefined |
| 115 |
\else |
| 116 |
\immediate\write16{% |
| 117 |
!!! Process this file `\jobname.tex' with pdf(e)tex % |
| 118 |
(plain format) !!!% |
| 119 |
}% |
| 120 |
\expandafter\END |
| 121 |
\fi |
| 122 |
|
| 123 |
% Check if pdfTeX |
| 124 |
\ifx\pdfoutput\undefined |
| 125 |
\immediate\write16{% |
| 126 |
!!! Process this file `\jobname.tex' with pdf(e)tex % |
| 127 |
(NOT tex) !!!% |
| 128 |
}% |
| 129 |
\expandafter\END |
| 130 |
\fi |
| 131 |
|
| 132 |
\pdfoutput=1 |
| 133 |
|
| 134 |
% Disable \pdfobjcompresslevel |
| 135 |
\ifx\pdfobjcompresslevel\undefined |
| 136 |
\else |
| 137 |
\pdfobjcompresslevel=0 % |
| 138 |
\fi |
| 139 |
\ifx\pdfminorversion\undefined |
| 140 |
\else |
| 141 |
\ifnum\pdfminorversion>4 % |
| 142 |
\pdfminorversion=4 % |
| 143 |
\fi |
| 144 |
\fi |
| 145 |
|
| 146 |
% this file is tested with pdfTeX 0.13a |
| 147 |
% but for downward compatibilty a trick from Hans Hagen: |
| 148 |
\ifnum\pdftexversion<13 \ifnum\expandafter `\pdftexrevision<`s |
| 149 |
\let\normalpdfimage\pdfimage |
| 150 |
\def\grabpdfimage#1#2{\normalpdfimage#1 #2\relax} |
| 151 |
\def\pdfimage#1#{\grabpdfimage{#1}} |
| 152 |
\fi\fi |
| 153 |
|
| 154 |
% syntax has changed with pdfTeX 0.14a: |
| 155 |
\ifnum\pdftexversion>13 |
| 156 |
\def\pdfimage#1#{\grabpdfimage{#1}} |
| 157 |
\def\grabpdfimage#1#2{% |
| 158 |
\pdfximage#1{#2}\pdfrefximage\pdflastximage |
| 159 |
} |
| 160 |
\fi |
| 161 |
|
| 162 |
% max. 106x106 / 72 dpi |
| 163 |
\hsize 1.5in |
| 164 |
\vsize 1.5in |
| 165 |
|
| 166 |
\nopagenumbers |
| 167 |
|
| 168 |
\newcount\thumbcount |
| 169 |
\def\thumbcountstep{\advance\thumbcount by 1 } |
| 170 |
|
| 171 |
\def\thumbfilename{thb\the\thumbcount.png} |
| 172 |
|
| 173 |
\newread\thumbread |
| 174 |
\def\ifthumbexists{% |
| 175 |
\openin\thumbread=\thumbfilename\relax |
| 176 |
\ifeof\thumbread |
| 177 |
\expandafter\noneofone |
| 178 |
\else |
| 179 |
\closein\thumbread |
| 180 |
\expandafter\firstofone |
| 181 |
\fi |
| 182 |
} |
| 183 |
\def\noneofone#1{} |
| 184 |
\def\firstofone#1{#1} |
| 185 |
|
| 186 |
\def\iffileexists#1{% |
| 187 |
\openin\thumbread=#1\relax |
| 188 |
\ifeof\thumbread |
| 189 |
\expandafter\secondoftwo |
| 190 |
\else |
| 191 |
\closein\thumbread |
| 192 |
\expandafter\firstoftwo |
| 193 |
\fi |
| 194 |
} |
| 195 |
\long\def\firstoftwo#1#2{#1} |
| 196 |
\long\def\secondoftwo#1#2{#2} |
| 197 |
|
| 198 |
\let\listthumbs\empty |
| 199 |
|
| 200 |
\def\printthumbfile{% |
| 201 |
\vfill\eject |
| 202 |
\centerline{% |
| 203 |
\pdfimage height \vsize {\thumbfilename}% |
| 204 |
}% |
| 205 |
} |
| 206 |
|
| 207 |
\newcount\thumbfound |
| 208 |
\thumbfound=0 |
| 209 |
\def\processthumb{% |
| 210 |
\edef\listthumbs{\listthumbs\space\the\thumbcount}% |
| 211 |
\printthumbfile |
| 212 |
\pageno=\thumbcount |
| 213 |
\advance\thumbfound by 1 |
| 214 |
} |
| 215 |
|
| 216 |
\expandafter\ifx\csname thumbmax\endcsname\relax |
| 217 |
\def\thumbmax{999}% |
| 218 |
\fi |
| 219 |
|
| 220 |
\immediate\write16{* Looking for thumbnails 0..\thumbmax:} |
| 221 |
|
| 222 |
\thumbcount=\thumbmax\relax |
| 223 |
\advance\thumbcount by 1 |
| 224 |
\edef\thumbmax{\the\thumbcount}% |
| 225 |
\thumbcount=0 |
| 226 |
\loop |
| 227 |
\ifnum\thumbcount<\thumbmax\relax |
| 228 |
\ifthumbexists\processthumb |
| 229 |
\thumbcountstep |
| 230 |
\repeat |
| 231 |
|
| 232 |
\break |
| 233 |
\immediate\write16{==> \the\thumbfound\space thumbnail(s) found.} |
| 234 |
\immediate\pdfobj{<</MaxThumbNumber \the\thumbfound>>} |
| 235 |
\edef\CatalogHook{\the\pdflastobj\space 0 R}% |
| 236 |
\immediate\write16{* Looking for extra thumbnails:} |
| 237 |
|
| 238 |
\def\END{% |
| 239 |
\ifx\allthumbs\empty |
| 240 |
\else |
| 241 |
\immediate\pdfobj{<</ListThumbs\listthumbs>>}% |
| 242 |
\edef\CatalogHook{\CatalogHook\space\the\pdflastobj\space 0 R}% |
| 243 |
\fi |
| 244 |
\pdfcatalog{/ThumbpdfHook [\CatalogHook]}% |
| 245 |
\vfill\eject |
| 246 |
\csname bye\endcsname % \bye is \outer |
| 247 |
} |
| 248 |
|
| 249 |
% <jobname>.tno |
| 250 |
\ifx\thumbjob\UnDeFiNeD |
| 251 |
\immediate\write16{!!! Warning: \string\thumbjob\space undefined, |
| 252 |
search for extra thumbnails skipped!% |
| 253 |
} |
| 254 |
\expandafter\END |
| 255 |
\fi |
| 256 |
\def\optfile{\thumbjob.tno}% |
| 257 |
\iffileexists{\optfile}{}{% |
| 258 |
\immediate\write16{==> No optional thumbnail file.}% |
| 259 |
\END |
| 260 |
}% |
| 261 |
\thumbfound=0 |
| 262 |
|
| 263 |
\def\thumb{\futurelet\nexttoken\thumbA} |
| 264 |
\let\braceleft=[ |
| 265 |
\def\thumbA{% |
| 266 |
\if\nexttoken\braceleft |
| 267 |
\expandafter\thumbB |
| 268 |
\else |
| 269 |
\expandafter\thumbC |
| 270 |
\fi |
| 271 |
} |
| 272 |
\def\thumbC#1{\thumbB[#1]{#1}} |
| 273 |
\def\thumbB[#1]#2{% #1: label, #2: file[.png] |
| 274 |
\iffileexists{#2.png}{% |
| 275 |
\def\thumbfilename{#2.png}% |
| 276 |
}{% |
| 277 |
\iffileexists{#2}{% |
| 278 |
\def\thumbfilename{#2}% |
| 279 |
}{% |
| 280 |
\let\thumbfilename\empty |
| 281 |
}% |
| 282 |
}% |
| 283 |
\ifx\thumbfilename\empty |
| 284 |
\immediate\write16{% |
| 285 |
!!! Warning: Thumbnail `#2' does not exist!"}% |
| 286 |
\else |
| 287 |
\edef\listthumbs{\listthumbs\space{#1}}% |
| 288 |
\printthumbfile |
| 289 |
\advance\thumbcount by -1 |
| 290 |
\pageno=\thumbcount |
| 291 |
\advance\thumbfound by 1 |
| 292 |
\fi |
| 293 |
} |
| 294 |
|
| 295 |
\thumbcount=0 |
| 296 |
\input \optfile |
| 297 |
\break |
| 298 |
\immediate\write16{==> \the\thumbfound\space extra thumbnail(s) found.}% |
| 299 |
|
| 300 |
\END |