[Tex/LaTex] Producing PDF/X compliant document with XeLaTeX

pdfxxetex

Solution

Full solution for producing PDF/X compliant document can be found in MWE and answer to this question: Disabling all document interactivity (for PDF/X compliance)

Adapted MWE and compilation method are taken from Leonid's answer to this question.

Please note that solution requires compilation with TeXLive 2015 (or later).

Original question

I am trying to compile my source with XeLaTeX to produce PDF/X-1a:2001 compliant document. Getting PDF/X-1a:2001 is possible with pdfx package (while using up-to-date TeX distribution), but only when document is compiled with pdflatex.

Since I am using OTF and TTF fonts in my document, I have to use XeLaTeX to compile it. This is MWE:

\documentclass{book}
\usepackage[x-1a1]{pdfx}
\begin{document}
Some text
\end{document}

When I try to compile this document with MiKTeX's 2.9 xelatex I get following error and compilation halts:

! Undefined control sequence.
l.111 \pdfminorversion
                      =4 %  assumed for PDF/A ;  options may change this for...

? 

Is there any way to compile PDF/X-1a:2001 with XeLaTeX, either using pdfx or different package?

Ps. I used MiKTeX 2.9, because I don't want to update my TeX Live 2013/Debian distribution I normally use. With MiKTeX I get most recent version of pdfx package.

EDIT: Since it isn't obvious from Leonid's answer and is mentioned only in comments, please note that you need TeXLive 2015 in order for Leonid's answer to work fully. TeXLive 2013 (installed by your system's package manager) or MiKTeX 2.9 won't do the trick (this is true as of March 2016; it might change by the time you read this).


I also tried to compile this MWE with LuaLaTeX to see if this works. It didn't. I get following error:

! Undefined control sequence.
\pdfx@findUUID ... \pdfx@tmpstring {\pdfmdfivesum 
                                                  {#1}} \expandafter \pdfx@e...
l.360 \pdfx@findUUID{\jobname.pdf}

?

In the event version of LuaLaTeX matters: lualatex --version outputs

This is LuaTeX, Version beta-0.76.0-2013062821  (MiKTeX 2.9 64-bit) (rev 4627)

Best Answer

You need to put some specific metadata inside resulting pdf with \special command, add some info with hyperref package and then compile with xelatex option -output-driver="xdvipdfmx -V 3". Look at example:

% !TeX program = xelatex 
%%%%Needs to be compiled with commandline: "xelatex.exe -output-driver="xdvipdfmx -V 3" %.tex" % as PDF 1.3 required by PDF/X
\documentclass{book}

%%%%%%%%% PDF-X stuff, IF USING xelatex %%%%%%%%%
%(mm size * 72)/25.4 = bp size
\usepackage{atbegshi}
\AtBeginShipout{% %A hook that is executed for every page (after first one)
    \special{pdf: put @thispage
      <<
        /TrimBox [0 0 210.990 162.086] %put here other numbers = size of page in bp
      >>
    }
}
\special{pdf: put @thispage
  <<
    /TrimBox [0 0 210.990 162.086] %put here other numbers = size of page in bp
  >>
}
\special{pdf:docinfo
  <<
    /GTS_PDFXVersion (PDF/X-1:2001)
    /GTS_PDFXConformance (PDF/X-1a:2001)
  >>
}

\special{pdf:put @catalog
<<
  /PageMode /UseNone
  /OutputIntents [
    <<
      /Info (none)
      /Type /OutputIntent
      /S /GTS_PDFX
      /OutputConditionIdentifier (Custom)
      /RegistryName (http://www.color.org/)
    >>
  ]
>>
}%

\usepackage{datetime} % for \pdfdate command

\usepackage{hyperref} % for \hypersetup

\hypersetup{% 
    pdftitle={DocTitle},% PDF/X document should have a title
    pdfinfo={% Setting some more PDF/X stuff for xelatex
        ModDate={D:\pdfdate},% PDF/X document should have a modification date
        Trapped={False},% PDF/X document should have Trapped tag set
    },
}


\begin{document}
Some text
\end{document}

Another example, compilable in lualatex, pdflatex and xelatex: http://gist.github.com/LSinev/98c0a40e94f4507922a8