Skip to content

Instantly share code, notes, and snippets.

@TheMatjaz
Last active April 29, 2022 10:32
Show Gist options
  • Save TheMatjaz/ac2974204b2331a9ee4f257aaeb69605 to your computer and use it in GitHub Desktop.
Save TheMatjaz/ac2974204b2331a9ee4f257aaeb69605 to your computer and use it in GitHub Desktop.
Achieving PDF/A compliance in LaTeX

Achieving PDF/A compliance in LaTeX

LaTeX code

Minimal project available also on OverLeaf

  1. Use the PDFLaTeX or XeLaTeX compiler

  2. Create a preamble.tex file and place this into it. Clearly, change the language, metadata, any hyperref fields as required.

    % !TeX encoding = UTF-8
    % Document language and font support
    \usepackage{ifxetex}
    \ifxetex
        \usepackage{polyglossia}
        \usepackage{fontspec}
        \setmainlanguage{english}
    \else
        \usepackage[T1]{fontenc}
        \usepackage[utf8]{inputenc}
        \usepackage[english]{babel}
    \fi
    
    % PDF/A settings
    \begin{filecontents*}[overwrite]{\jobname.xmpdata}
        \Title{My Title}
        \Author{Me Myself}
        \Language{en-GB}
        \Subject{My subject}
        \Keywords{%
            lorem \sep
            ipsum \sep
            dolor}
    \Copyright{Copyright \copyright My Name}
    \end{filecontents*}
    \usepackage[pdfa]{hyperref}
    \usepackage[a-1b,latxmp,mathxmp]{pdfx}[2019/02/27]
    \usepackage{colorprofiles}
    \hypersetup{%
        unicode=true,
        pdftoolbar=false,
        pdfmenubar=false,
        pdffitwindow=true,
        pdfstartview={FitH},
        pdfnewwindow=true,
        colorlinks=true,
        linkcolor=black,
        citecolor=black,
        filecolor=black,
        urlcolor=blue
    }

    Pay attention to:

    • load hyperref with pdfa option.
    • colorprofiles is required
    • set the PDF/A compliance level to the desired one: I used a-1b
    • add support for characters using the pdfx settings: I used extended latin characters and math symbols. More in the pdfx package documentation
  3. Start your main LaTeX document like this:

    % !TeX encoding = UTF-8
    % REQUIRES XELATEX
    % Any \PassOptionsToPackage should go here
    \documentclass{article}
    \input{preamble.tex}
    \begin{document}
    Hello, I'm PDF/A compliant
    \end{document}

A warning about Writing or overwriting file ./output.xmpdata is completely normal - ignore it.

Clashing of package settings

It may happen that some package is imported twice in your preamble, especially if you load it within any custom document class first and only then load the preamble. When they need to be loaded with a specific option, you can force it with the line:

\PassOptionsToPackage{option}{packagename}

placed immediately before the \documentclass call.

Examples:

  • \PassOptionsToPackage{pdfa}{hyperref} - if hyperref is loaded by document class
  • \PassOptionsToPackage{table}{xcolor} - if xcolor is used to fill table cells backgrounds

PDF-A compliance hints

  • Remove transparency effects from Tikz diagrams.
  • Remove transparency effects (alpha) from any used colour.
  • Use images without transparency. PNGs should have only solid colours. Replacing them with JPEGs does the trick, if the compression from JPEG is good-enough for your case.

Validation of the resulting PDF file

  1. Download VeraPDF, an open source PDF/A compliance validator. You will need Java to run it.
  2. Follow the instructions to install it
  3. and then those to use it
  4. Select all features in Config > Features
  5. Choose the PDF file and execute the Validation. In case of errors, select View HTML to see which PDF/A rule was violated. Full rule list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment