Chapter 9 – Optimizing PDF Files

Here are the Code examples of this chapter. You can compile them online right on this web page by pressing the Typeset / Compile button. You can also edit them for testing and compile them again.

The code pages here are partially based on the First Edition of the book and are currently being edited to match the code of the Second Edition with all the additional examples. It is not complete yet since the focus was on the book production until days ago; please visit again soon!

documentclass[fontsize=11pt,paper=a5,pagesize=auto]{scrbook}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage[english]{babel}
usepackage{microtype}
usepackage{blindtext}
frenchspacing
usepackage{hyperref}
begin{document}
title{The Book}
subtitle{Some more to know}
author{The Author}
date{}
maketitle
tableofcontents 
part{First portion}
chapter{The beginning}
Some introductional text comes here.
section{A first section}
Dummy text will follow.
blindtext
section{Another section}
Blindtext
appendix
part{Appendix}
chapter{An addendum}
section{Section within the appendix}
blindtext
end{document}

documentclass{article}
usepackage{hyperref}
begin{document}
See hyperlink{mytarget}{next page}.
newpage
hypertarget{mytarget}{Here} starts a new page.
end{document}

documentclass{article}
usepackage{hyperref}
hypersetup{hidelinks}
begin{document}
See hyperlink{mytarget}{next page}.
Refer to the hyperref[eq:einstein]{mass-energy equivalence}.
newpage
hypertarget{mytarget}{Here} starts a new page.
begin{equation}
  label{eq:einstein}
  E = mc^2 
end{equation}
href{http://latex-community.org}{LaTeX Community Forum}

url{http://texample.net}

nolinkurl{http://texdoc.net}


newcommand{baseaddress}{http://latex-community.org/}
newcommand{articleaddress}{baseaddress
  know-how/latexs-friends/61/486/}
hyperref{articleaddress}{running}{lualatex}
  {Running MetaPost within LuaLaTeX}
end{document}

documentclass[fontsize=11pt,paper=a5,pagesize=auto]{scrbook}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage[english]{babel}
usepackage{microtype}
usepackage{blindtext}
frenchspacing
usepackage{hyperref}
hypersetup{pdfauthor   = The Author,
            pdftitle    = The Book,
            pdfsubject  = Draft version,
            pdfkeywords = {book, draft},
            pdfproducer = TeX version,
            pdfcreator  = LaTeX editor}
begin{document}
title{The Book}
subtitle{Some more to know}
author{The Author}
date{}
maketitle
tableofcontents 
part{First portion}
chapter{The beginning}
Some introductional text comes here.
section{A first section}
Dummy text will follow.
blindtext
section{Another section}
Blindtext
appendix
part{Appendix}
chapter{An addendum}
section{Section within the appendix}
blindtext
end{document}

documentclass[fontsize=11pt,paper=a5,pagesize=auto]{scrbook}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage[english]{babel}
usepackage{microtype}
usepackage{blindtext}
frenchspacing
usepackage[pdfauthor   = {The Author},
            pdftitle    = {The Book},
            pdfsubject  = {Draft version},
            pdfkeywords = {{book, draft}},
            pdfproducer = {TeX version},
            pdfcreator  = {LaTeX editor}]{hyperref}
begin{document}
title{The Book}
subtitle{Some more to know}
author{The Author}
date{}
maketitle
tableofcontents 
part{First portion}
chapter{The beginning}
Some introductional text comes here.
section{A first section}
Dummy text will follow.
blindtext
section{Another section}
Blindtext
appendix
part{Appendix}
chapter{An addendum}
section{Section within the appendix}
blindtext
end{document}

documentclass[fontsize=11pt,paper=a5,pagesize=auto]{scrbook}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage[english]{babel}
usepackage{microtype}
usepackage{blindtext}
frenchspacing
pdfinfo{
  /Author (The Author)
  /Title (The Book)
  /Subject (Draft version)
  /Keywords (book, draft)
  /Producer (pdfTeX 1.40.0)
  /Creator (LaTeX editor)}
begin{document}
title{The Book}
subtitle{Some more to know}
author{The Author}
date{}
maketitle
tableofcontents 
part{First portion}
chapter{The beginning}
Some introductional text comes here.
section{A first section}
Dummy text will follow.
blindtext
section{Another section}
Blindtext
appendix
part{Appendix}
chapter{An addendum}
section{Section within the appendix}
blindtext
end{document}

documentclass[fontsize=11pt,paper=a5,pagesize=auto]{scrbook}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage[english]{babel}
usepackage{microtype}
usepackage{blindtext}
frenchspacing
usepackage{hyperref}
hypersetup{pdfinfo = {
              Author   = The Author,
              Title    = The Book,
              Subject  = Draft version,
              Keywords = {book, draft},
              Producer = TeX Live 2014,
              Creator  = TeXworks,
              Version  = 2.0,
              Comment  = Contains dummy text}}
begin{document}
title{The Book}
subtitle{Some more to know}
author{The Author}
date{}
maketitle
tableofcontents 
part{First portion}
chapter{The beginning}
Some introductional text comes here.
section{A first section}
Dummy text will follow.
blindtext
section{Another section}
Blindtext
appendix
part{Appendix}
chapter{An addendum}
section{Section within the appendix}
blindtext
end{document}

documentclass[fontsize=11pt,paper=a5,pagesize=auto]{scrbook}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage[english]{babel}
usepackage{microtype}
usepackage{blindtext}
frenchspacing
usepackage{hyperref}
usepackage{hyperxmp}
hypersetup{
  pdfcopyright = {Copyright (C) 2012 by auhor name.
    All rights reserved.},
  pdflicenseurl = {http://latex-community.org/license/}}
begin{document}
title{The Book}
subtitle{Some more to know}
author{The Author}
date{}
maketitle
tableofcontents 
part{First portion}
chapter{The beginning}
Some introductional text comes here.
section{A first section}
Dummy text will follow.
blindtext
section{Another section}
Blindtext
appendix
part{Appendix}
chapter{An addendum}
section{Section within the appendix}
blindtext
end{document}

documentclass[paper=a4,oneside,fontsize=12pt,
  parskip=full]{scrartcl}
usepackage[svgnames]{xcolor}
usepackage[author={Stefan Kottwitz},icon=Note,color=Yellow,open=true,final]{pdfcomment}
begin{document}
%tableofcontents
addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.
pdfcomment{Simple documents don't have chapters.}

The text will be divided into pdfmarkupcomment{sections}{You could additionally use subsections.}.
section{The first section}
This first text will contain
begin{pdfsidelinecomment}[color=Red]{A bulleted list}
begin{itemize}
item a table of contents,
item a bulleted list,
item headings and some text and math in section,
item referencing such as to section ref{sec:maths} and
      equation (ref{eq:integral}).
end{itemize}
end{pdfsidelinecomment}
We can use this document as a template for filling in
our own content.
section{Some maths}
label{sec:maths}
When we write a scientific or technical document, we usually
include math pdftooltip{formulas}{Formulas can be inline or displayed in their own paragraph}. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
begin{equation}
  pdfmargincomment{The equation environment produces a centered
  equation with whitespace before and after it.}
  label{eq:integral}
  int_a^b pdfmarkupcomment{f(x)}{This function will be approximated.},mathrm{d}x approx (b-a)
  sum_{i=0}^n pdfmarkupcomment{w_i}{Those are the weights} f(x_i)
end{equation}
pdffreetextcomment[subject={Summary},width=7.5cm,height=2.2cm,opacity=0.5,voffset=-3cm]{The whole document is an example
showing how to write a small document.
Now we enriched it with sample comments.}
end{document}

documentclass[a6paper,landscape,parskip=half]{scrartcl}
usepackage[margin=0.4cm]{geometry}
usepackage{xcolor}
pagecolor{yellow!30}
pagestyle{empty}
usepackage{hyperref}
begin{document}
begin{Form}
  begin{tabular}{|lr|}hline
    textbf{Dear TeX user, please help in our survey.} &
      PushButton[width=1cm, onclick =
         {app.alert("You may use a pseudonym for the name.")}]%
         {Info}\[0.5ex] hline
    & \
    TextField[width=5cm]{Name:} &
    TextField[width=3cm]{Profession:} \
    & \
    ChoiceMenu[radio, radiosymbol=6,
      width=0.5cm]{Software:quad}{TeX Live, MiKTeX} 
    &ChoiceMenu[combo, width=3cm]{Editor:}%
    {TeXworks,TeXstudio,TeXmaker,TeXshop,
    WinEdt,Kile,Emacs,vi} \ 
    & \ 
    Membership in: hfillCheckBox[width=0.5cm]{TUG}hfill
    CheckBox[width=0.5cm]{DANTE e.V.} &
    TextField[width=3cm]{Other:}\ & \ hline
  end{tabular}
  par
  textbf{Notes:}
  par
  TextField[multiline, width=0.94paperwidth,
    height=10baselineskip]{ }
end{Form}%
end{document}

documentclass[fontsize=11pt,headings=small,
  parskip=half]{scrreprt}
usepackage[papersize={3.6in,4.8in},margin=0.2in]{geometry}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
renewcommand{familydefault}{sfdefault}
usepackage[english]{babel}
usepackage{microtype}
usepackage[demo]{graphicx}
pagestyle{empty}
renewcommand{partpagestyle}{empty}
renewcommand{chapterpagestyle}{empty}
usepackage{blindtext}
frenchspacing
usepackage{hyperref}
hypersetup{colorlinks}
begin{document}
title{The Book}
subtitle{Some more to know}
author{The Author}
date{}
maketitle
tableofcontents 
part{First portion}
chapter{The beginning}
Some introductional text comes here.
begin{center}
  includegraphics[width=0.8textwidth]{text}
end{center}
section{A first section}
Dummy text will follow.
blindtext
section{Another section}
Blindtext
appendix
part{Appendix}
chapter{An addendum}
section{Section within the appendix}
blindtext
end{document}

Go to next chapter.