Go to page:

Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

FAQ /

PDF

Categories: PDF
<< | Page list | >>

§ How can I include PDF documents in my file?

Use the menu Insert->File->External Material and there the template pdfpages.
For more information about this, see LyX's Embedded Objects manual, section External Material.

If you get the error message "Set output to PDF. (use: \pdfoutput = 1)" when you generate a DVI file instead of a PDF file, you have to update your pdfpages package. With pdfpages version 0.4f, this problem is fixed.

§ How do I create clickable URLs/hyperlinks in a PDF file ?

Enable the hyperref support in the document settings under PDF Properties. Then all URLs within a LyX URL box will be created as clickable hyperlinks.

For more information about this, see LyX's User's Guide manual, section PDF Properties.

Incoming hyperlink anchors are Named-Destinations

§ How do I generate bookmarks in a PDF file?

This is done in the document settings under PDF Properties
For more information about this, see LyX's User's Guide manual, section PDF Properties.

§ How can I create custom PDF bookmarks?

Enable the hyperref support in the document settings under PDF Properties.
Open in LyX a TeX code box by pressing C-L.
Now write: \pdfbookmark{Text of bookmark}{Name_of_anchor}

This will create a bookmark and a Named-Destination (Anchor) called "Name_of_anchor.0" (in my system). URL will be
www.abc.com/somepdf.pdf#Name_of_anchor.0

§ The fonts are bad in the exported PDF, what can I do?

The default LaTeX fonts (cm or ec) are bitmap fonts. Therefore they cannot be scaled to any size and in PDF they look pixeled.

To avoid these problem, use scalable fonts, like Type 1 (PostScript) or TT (True Type) Fonts. Modern LaTeX distributions ship a whole range of Type 1 fonts. Using True Type fonts is a bit trickier (but some LaTeX distributions like MiKTeX ease their use). Some bleeding edge distributions like XeTeX even provide support for OpenType fonts, which is the latest and greatest font format. However, running these distributions with LyX is still tricky (but might improve in the future).

If you want to keep the look of the default fonts, you have several possibilities.

  1. Choose the font AE (Almost European) in Document→Settings→Fonts
    Caveat: ae are virtual fonts, they 'steal' the T1 fonts from other packages. Therefore the characters do not match as good as the ones from a real font. Also, not all symbols are available with ae, e.g. the French 'guillemets'.
    For using the guillemets with ae, you have to install the package aeguill. It is loaded in the preamble with
    \usepackage[ec]{aeguill}
  2. A better solution is to use the Type 1 replacement for Computer Modern: Choose the font Latin Modern in Document→Settings→Fonts. If LaTeX claims that the font is not installed, install the font, reconfigure LyX (Tools→Reconfigure), and try again.

Alternatively, you can also try one of the other Type 1 fonts that ship with LaTeX; for instance Times or Palatino. Caveat: Times, as the name indicates, is designed for printing newspaper with small columns. Therefore the letters are smaller than in other fonts, what makes them improper for one-column documents.

To use Times select

  • Times as Roman font
  • Helvetica scaled to 90% or 92% (as you like)
  • Courier

To use Palatino select

  • Palatino as Roman font
  • Helvetica scaled to 90% or 92% (as you like)
  • Courier

See also section 3.7.2 "Document Font and Font size" in the LyX User's Guide or the FAQ for the TEX FAQ (keyword=fonts) [tex.ca.uk].

§ How can I edit/write the properties of a PDF file?

This is done in the document settings under PDF Properties
For more information about this, see LyX's User's Guide manual, section PDF Properties.

What you still can't do is encrypt your document. If you want to define what the reader is allowed to do with your document, you have to use Adobe Acrobat (open your PDF with Acrobat and set the properties).
Note, however, that quite a range of the properties (including encryption) can also be set with the free tool pdftk, which is available for several platforms (whereas Adobe Acrobat is not available for, say, UNIX).

§ I have included hyperref and LyX tells me of "undefined code sequence"s!

If you are using for example Algorithm floats you run into problems with LyX and hyperref. hyperref needs to be loaded before the algorithm package. Unfortunately LyX loads 'native' packages before the packages defined in Latex Preamble. A workaround is to _not_ use Algorithm floats (preventing LyX to load the package) and instead define your float in ERT. See http://www.mail-archive.com/lyx-users@lists.lyx.org/msg51007.html for details. An advantage of this method is that you can define your own caption names e.g. 'Listing'

§ Can I add annotations to the PDF?

Yes. Use the LaTeX package pdfcomment. Here is a module that adds some native LyX-support for that package.

§ Can I permit others to insert annotations to the PDF?

As of Adobe Acrobat 7 (pro) you can set the permissions of a PDF so that other users can insert annotations with the free Adobe Reader >= 7.0. By default, this is not allowed. Unfortunately, there is no way yet to change this special permission outside of Acrobat. Due to a very rigid licensing policy (of Adobe) it is unlikely that this will change in the future.

§ Can I generate a PDF file containing a subset of the pages in my document?

There are several methods:

  • Put the text you do not want to export in comments or notes. (Warning: This will change pagination and may cause problems with cross-references.)
  • Make a PDF of the entire document, then use Ghostscript to produce a PDF of selected pages, as in the following (which extracts pages 3 through 5 inclusive from sourcefile.pdf):
      gsc -dFirstPage=3 -dLastPage=5 -sDEVICE=pdfwrite -sOutputFile=test.pdf 
      -dBATCH -dNOPAUSE sourcefile.pdf
  • Use a PDF printer driver (such as PDFCreator for the Windows platform or cups-pdf on Linux) that can output selected pages. Generate the entire document in PDF from LyX, load it into your favorite PDF viewer, print it to the PDF driver and extract just the pages you want.
  • Install the pdftk tool kit and run something like
      pdftk sourcefile.pdf cat 130-140 output test.pdf 
  • Look at the \includeonly command (but note that it does not work in recent releases, due to the handling of temp files).

§ pdfTeX warning stops generating PDF (destination with the same identifier):

You are using package "hyperref" and you have at least two pages "1". ==> recommended hyperref options: plainpages=false,pdfpagelabels

If the pages were labled differently (for example: documentclass book with \frontmatter and \mainmatter the pages are labeled "i" and "1"), then the problem is solved.

If there is a title page without a printed page number, you can set the page counter to zero, for example. Or \thepage can be redefined, eg:

 \begingroup
  \renewcommand{\thepage}{title}
  % commands that generates the title page
  \newpage
 \endgroup

Other options:

  • If there are no references and such stuff on the pages "1", you can ignore the warning.
  • Option "hypertexnames=false" solves the warning, but then index links, \autoref will not work correctly.

§ My eps figures are rotated in the pdf output. What can I do ?

The following is a short digest of this thread.

The Orientation comment is allowed in eps files. Unfortunately it is interpreted differently by different programs Some programs interpret "Orientation Landscape" as "this file is already in landscape orientation", while others interpret it as "this file should be in landscape orientation, therefore it should be rotated by 90 degrees."

This makes it difficult to implement a unique solution to eps file conversion in LyX, and to get the same output in dvi, ps, and pdf.

Ghostcript has a -dAutoRotatePages= switch, which is activated by default in ps2pdf and de-activated by default in recent versions of epstopdf.

  • if the rotation comes after DVI->PS->PDF, export to PS and try
              ps2pdf -dAutoRotatePages=/None foo.ps
  • if the rotation comes after pdflatex, each figure should be separately converted using epstopdf (check with
              lyx -dbg files -e pdf foo.lyx
supposing pdf is the format associated to pdflatex):
  • if epstopdf is used, you may upgrade, or add the switch manually.
  • if ps2pdf is used, the file is recognised as PS instead of EPS, you may normalize it.

Difference of ps2pdf, dvipdfm(x) and pdflatex

LyX supports three different ways of producing PDF files. This is because all of them have their specific pros and cons.

Also see http://mintaka.sdsu.edu/GF/bibliog/latex/LaTeXtoPDF.html

§ ps2pdf method

Traditionally, you converted your LaTeX source file to a DVI file, which could then be converted to PostScript with dvips. This, in turn, can be converted to a PDF file by ps2pdf (LyX does all those steps automatically for you if you select PDF (which is in fact ps2pdf) as output format:

                  latex             dvips            ps2pdf
        text.tex -------> text.dvi -------> text.ps --------> text.pdf

This basically requires all the graphics to be EPS files. But that's not a major problem, as LyX converts all files to the appropriate format if needed (however, if you have the choice, using EPS as native format is recommended). The main advantage of this method (especially compared with PDFLaTeX) is that the resulting PDF file is almost always much smaller. Also, dvi and postscript specials are supported (the former is also true for dvipfdm(x)). For instance, LyX's change tracking feature uses dvi specials to mark the changes in the output. Hence, the change tracking marks are not visible in a PDF produced with PDFLaTeX.

§ Dvipdfm method

If you don't need PostScript output, you can save a step by going directly from DVI to PDF format by using dvipdfm or the newer dvipdfmx, which is intended to supersede the former:

                 latex           dvipdfm(x)
       text.tex -------> text.dvi -------> text.pdf

Once again, the figures must be Encapsulated PS. So you have compact, scalable graphics – with one less step.

§ Pdflatex method

The pdflatex program produces a PDF file directly from the LaTeX source:

              pdflatex
     text.tex --------> text.pdf

That looks pretty painless; but there's a catch. While the previous methods employ EPS exclusively as the graphics format, pdflatex won't accept EPS directly at all: all the graphics have to be converted to JPEG, PNG, or PDF (!) before compiling.

That isn't as bad as it sounds, because EPS can be "wrapped" with PDF headers to become PDF and still have scalable, vector graphics. And JPEG is a compact format for photographs, while PNG is a very compact way to store images with sharp outlines without introducing compression artifacts." And LyX does it again automatically for you, if required.

The advantage of this method is that pdflatex is the most feature-rich converter program. It features, for instance, character protusion and font expansion (see this document for explanation), two microtypographical features that let your document look even better than "ordinary" LaTeX could ever achieve.

§ How can I make Acrobat Reader (acroread) update its display?

§ How can I make gv/Ghostview automatically update its display?

Set the resource (in for instance $HOME/.Xdefaults or $HOME/.gv) to:

  GV.watchFile: True


or change the option Watch File under the menu "State".

§ Where can I find tools for working with PDFs?

Open-source tools:

  • pdftk — PDF Tool Kit — Powerful toolkit, command line only (Windows, Linux, Mac OS X, FreeBSD and Solaris).
  • PdfMod — Simple application for modifying PDF documents under Linux. You can reorder, rotate, and remove pages, export images from a document, edit the title, subject, author, and keywords, and combine documents via drag and drop.
  • DiffPDF — Allows to compare ("diff") two PDF files, textually or visually.
  • PDFJam — Another command line tool for joining, rotating, merging and printing several PDFs on one page (Unix-like operating systems: Linux, Mac OS X, Solaris, etc.)
  • PDFedit — New open source PDF editor for Linux - still alpha/beta quality, but can edit PDF elements, not just metadata.
  • PDFill PDF Tools (MS Windows only)
  • PDF Split and Merge &‐ Utility to split apart (by pages) and merge PDF files (Java application, command line and GUI, with Windows installer).
  • Inkscape — "An Open Source vector graphics editor, with capabilities similar to Illustrator, CorelDraw, or Xara X, using the W3C standard Scalable Vector Graphics (SVG) file format." GUI - runs on Windows, Linux, Mac OS X.
  • Scribus a mighty OpenSource Desktop Publishing (DTP) program with QT GUI for Linux and Windows.
  • Ghostscript — A powerful text-based PostScript and PDF interpreter (MS Windows, Apple MacOS, wide variety of Unix-like platforms, and VMS systems)
    • GSview — GUI for Ghostscript and previewer (MS Windows, Linux, and IBM OS/2)
    • MacGSview — GUI for Ghostscript and previewer (Mac OS)
  • Briss - GUI tool for cropping PDFs (cross-platform, needs Java) (particularly useful when combined with the print "fit to page" option which most PDF viewers have).
  • PDF-Shuffler is a small python-gtk application (frontend for python-pyPdf), which helps the user to merge or split pdf documents and rotate, crop and rearrange their pages using an interactive and intuitive graphical interface.

Commercial tools:

§ The fonts are not embedded in the exported PDF, what can I do?

If all the fonts are not embedded, and if the file is sent to other people who have not the non-embedded fonts installed, there will happen a font substitution which can make the pdf file unreadable. This is the reason why most publishers simply do not accept PDF documents with non-embedded fonts (and with bitmapped fonts, see the previous question).

If you want to check font embedding, you may either use the pdffonts command if it is available on your system, or use the File->Properties-Fonts tag or similar on your favourite viewer.

To make sure that all fonts are embedded:

  • if you use the Latex->ps2pdf way, you have to make sure that GhostScript is called by ps2pdf with the right switches: in the converter section of the LyX preferences, add the following switches to the ps2pdf command (in the PostScript->Pdf (ps2pdf) converter: -dPDFSETTINGS=/prepress -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true
If this does not work, please check the PDF output level of your ps2pdf command: these switches do not work with output level less than or equal to 12.
  • if you use pdflatex, recent distribution are OK with embedded fonts, make sure that you configuration files are correctly set if your distribution is old, cf. e.g. the testflow documentation.

Note that recent versions of the epstopdf script default to embedded fonts creation (a good source of non-embedded fonts are eps files created by external applications).

§ How can I Post-process a PDF?

See **Help->Customisation**

Post processing can be done by the Copier of a new File-Format. This is called to copy the pdf from the temp dir to the destination, and can do any post-processing along the way - e.g. DigitalSigning (below)

First:

 In Tools->Preferences->File Handling->File Formats  

Create a new file format called "pdf signed (pdflatex)", same as pdf (pdflatex) except

 -shortname pdf9 (this is what it will accept)
 -shortcut none
 -copier: c:\sign\signpdf.bat $$i $$o

Then:

 In Tools->Preferences->File Handling->Converters 
Select "Latex (pdflatex)" in From Format and your new format "pdf signed (pdflatex)" in To Format Now the Add button can be pressed to create the new converter. It should be identical in all respects to to the "latex to pdf(pdflatex)" converter, the post-processing is done by the Copier in the new File Format.

Now you can run file->export->pdf signed (pdflatex)

Unix: <insert a minimal unix script>

Windows:

   Unfortunately the file parameters $$i,$$o use forward / not backslash \ as the directory separators (thus dos commands can't find the files).
   CopyIt.bat is a minimal batch file, which fixes the paths 
    rem Simple example Copier batch file for Lyx
    rem Lyx is passing unix paths ie / instead of backslash as dir separator
    rem you can use Msg to debug what is being passed into your batch files.

    rem Msg * "Param1 is: " %1 "   Param2 is: " %2

    rem replace / with \ in path see: http://www.dostips.com/DtTipsStringManipulation.php#Snippets.Replace
    set P1=%1
    set P1=%P1:/=\%
    set P2=%2
    set P2=%P2:/=\%

    copy /y %P1% %P2%   

Is there a direct way to get valid DOS filenames from $$i $$o?

§ How can I Digitally Sign a PDF?

PDFs can be digitally signed, using an X509 code signing certificate. Acrobat Reader can show and check signatures.

This can be for two purposes: Certification/Authentication/Tamperproofing (signed once when created ie a hash check), and approvals (signed by different people as it is read and approved). My interest is in the first - Authentication/Tamperproofing.
Signatures can be just be a hidden digital hash or be visible on page with text ("Digitally signed by Wimble Inc 2016.07.28 22:43:53 PST") and optionally graphics (like a handwritten signature or logo).

PDFs can be signed using a normal code signing certificate or using an Adobe traceable certificate. Using a normal certificate allows you to verify that files have not been tampered with, and allows people to check the certificate, and who it was signed by. However Adobe Reader won't (by default, out of the box) verify the certificate itself. (users can enable certificates trusted by Windows(approve sites) (below) certificate store, and this would work fine for company documents, or in a later legal case). If you want an Adobe tracable certificate they appear to only be available on hardware (usb stick) and are very limited use eg 500 signs/year @ USD299.
If you need a normal cert, I got a good deal, and help sorting out problems with Comodo from Mitchell at KSoftware(approve sites)

§To make Acrobat Reader DC use the windows certificate store, i.e. accept valid non-adobe certificates:
Edit->Preferences->Signatures->Verification->Windows Integration->"Trust All root certificates in the Windows certificate store for:"
Check all checkboxes.

So what I can do is use my normal code signing certificate to provide some tamperproofing of documents put on a website. While I can do binary compare of pdfs on my own website, once they are copied to other sites - which they are - signing provides some protection against tampering (adding javascript attacks, changing company name etc). This is also good for emailed quotes where prices or terms and conditions could be altered later. A digital signature makes it much easier to show in court, 3 years later, that an emailed document was altered, than trying to prove the customers copy is a fake and not your copy

JsignPDF is used to sign the files. It has a gui, but I want to automatically sign PDF's when printed or uploaded, so I use a batch file signpdf.bat, below. The Certificate has been saved as a .PFX file, same as you use with signtool.exe to sign EXE files. A Timeserver is needed to give an externally verifed signing time (Why?(approve sites)). The signature ("Digitally signed by Wimble Inc 2016.07.28 22:43:53 PST") with no graphics is added on the bottom edge of page 1.

To automatically sign pdf during export, you must create a new post-processing output format. Set the Copier field to "c:\sign\signpdf.bat $$i $$o"

rem SIGNPDF.BAT  Sign PDF file. Works with LyX. usage signpdf <inpdf> OR signpdf <inpdf> <outpdf>
rem change paths below to suit your system.  Use lines with "Msg" to help debugging
setlocal 
set STDIR=c:\sign\
set JSP= java -jar "c:\Program Files\JSignPdf\jsignpdf-1.6.1\JSignPdf.jar"
rem set TS=-ts https://freetsa.org/tsr  -ta NONE -tsh SHA512
set TS=-ts http://timestamp.comodoca.com/rfc3161 -ta NONE -tsh SHA512
set OCSP= --ocsp
set V= -llx 5 -lly 0 -urx 500 -ury 40 -V -fs 8
set CL= -cl CERTIFIED_NO_CHANGES_ALLOWED
rem set CL= -cl CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
rem Msg * "Param1 is: " %1 "   Param2 is: " %2

rem for Lyx, replace / with \ in path see: http://www.dostips.com/DtTipsStringManipulation.php#Snippets.Replace
set P1=%1
set P1=%P1:/=\%
set P2=%2
set P2=%P2:/=\%

if [%2]==[] set P2=%P1%

For %%A in (%P1%) do (
    Set "INFILE=%%~nxA"
)
For %%A in (%P2%) do (
    Set "OUTPATH=%%~dpA"
)
set P2S=%OUtPATH%%INFILE:.pdf=_signed.pdf%
rem Msg *  %P1%  %P2% %OUTPATH% "     " %INFILE% %P2S%

%JSP% -d %OUTPATH% -kst PKCS12 -ksf %STDIR%MyCodeSigningCertificate.pfx -ksp MyKeyPassWord  -ha SHA512 %TS% %OCSP% %V% %CL%   %P1% 

if not [%2]==[] move /y %P2S% %P2%

§ Anchors / LinkTargets / Named Destinations

NamedDestinations are Adobes name for Anchors or Link Targets ie where URL's hyperlink to a specific point of a pdf.

Why?
PDF's have a major limitation as web pages: they are too big. You need to hyperlink into specific information within them.
eg www.xxx.com/some.pdf#nameddest=chapter.4 This is theoretically easy, except that (unlike bookmarks) pdf readers do not display the NamedDestinations. They are not bookmarks and you cannot link to or jump to bookmarks (braindead as this seems)

How to make them?

Hyperref generates them automatically, when exported with pdflatex (ps2pdf loses them). Here are some from a file I generated with pdflatex.

section*.1
subsection.2.3
section.2
Doc-Start
page.1

The obvious problem with this is that they are named using section numbering, not section titles, so adding a new section breaks the link to content. In a practical sense it renders them rather useless.

You can create a nameddest directly
Open in LyX a TeX code box by pressing C-L.
Now write: \hypertarget{The_Dest_Name}{} or \hypertarget{The_Dest_Name}{Some Visible Text}

You can create one along with a custom bookmark

Hyperref destination renaming explains hyperef naming. You can rename the section names with a following label, with destlabel=true Put \usepackage[destlabel=true]{hyperref} in the preamble. Unfortunately document->properties->pdf->hperref options puts destlabel=true into hypersetup, which does not work. \\ I have yet to find a way to have the section names automatically used as named destinations.

URL Limitations

  • Avoid spaces in the name - it works, but your URL's will be filled with "%20".
  • Only one digit following a decimal point is retained for float values.
  • Individual parameters, together with their values (separated by & or # ), can be no greater then 32 characters in length.
  • You cannot use the reserved characters = , # , and & . There is no way to escape these

special characters.

How to Explore the Named Destinations?

Online Named-Destination Lister(approve sites) Unless you can find what they are, you can't use them. Acrobat (paid version) appears to be the only gui tool to view named destinations. Why don't you request SumatraPDF to add this(approve sites) now
ListNamedDestinations.py(approve sites) lists and sorts them. (Python is with lyx if you don't have it e.g. "C:\Program Files\LyX 2.2\Python\python.exe" ListNamedDestinations.py SomePDFFile.pdf

Pdf's are compresssed and unreadable normally. Put this in the preamble to make them readable.
\ifx\pdfobjcompresslevel\undefined\else\pdfobjcompresslevel=0 \fi % Debug

How to call a named destination?

www.abc.com/somepdf.pdf#subsection.2.3
www.abc.com/somepdf.pdf#page.3
www.abc.com/somepdf.pdf#AnchorName.0

Or you can explicitly specify 'nameddest'

www.abc.com/somepdf.pdf#nameddest=subsection.2.3

You can also call page numbers directly (also pagemode, zoom, and view)(approve sites)

www.abc.com/somepdf.pdf#page=3

§ Where can I find more help on PDF?

Check out Herbert's page on PDF.

PDF

<< | FAQ.PageList | >>

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2017-01-07 02:06 CET