I use only lualatex, so a compiler-specific answer is OK.
Consider this pseudocode-MWE. The included PDF is always one page:
\documentclass{article}
\usepackage{pdfpages}
\def\includepdfifgood#1{
% This is where I test the pdfproducer string in #1.
% If wrong pdfproducer, compile halts with error message. Otherwise:
\includepdf{#1}
}
\begin{document}
\includepdfifgood{something.pdf}
\end{document}
The included page must be the output of a previous lualatex compile. In that earlier compile, I can (for example) set pdfproducer
to a custom string. I know how to do that.
So, what I need to do is inspect pdfproducer
and accept or reject the file.
Why I need to do this: PDF/X (and PDF/A) have stringent requirements. If a properly pre-processed PDF page is included in such a document, it can still be PDF/X or PDF/A. Otherwise, compliance may fail (and TeX does not know that it fails). I know how to pre-process. Now I need to ensure that only a pre-processed page is allowed into another PDF.
EDIT2: When I asked this question, I had the PDF Producer string in mind. It turns out that the Producer string is not the best one to use, because it may change when the Producer changes version number (for example). It is better to use something that the user can directly set, such as Title, Author, Subject, or Keywords. Fortunately, the accepted code works for any standard info dictionary entry. There is no need to modify it, since within the luacode, producer
is just a local variable name, which works even if you are looking for Author, or whatever.
EDIT: In an earlier question, I received a magnificent answer in luacode, which I am already using. My rationale for asking is the same, but the circumstances are different. Alas, I do not know enough Lua to edit the linked answer, or I would have done it.
EDIT2: The accepted answer has been put to good use! In version 1.50 of novel
package, the procedure for creating CMYK 240% PDF/X-1a:2001 color cover artwork has been automated by batch/bash script. First, an RGB image (or PDF) is converted to CMYK 240% PDF (FlateDecode) without TeX, using ImageMagick and Ghostscript. This PDF is not PDF/X. However, using the pdfmark
capability of Ghostscript, it has a custom tag in the PDF info dictionary. Then, LuaLaTeX (with novel
) processes that file into PDF/X-1a:2001. It inspects for the custom tag, and will only perform the process if the tag is detected. That's how it knows the image is in the correct color space, since no profile is embedded. The results have been validated using Adobe Acrobat Pro (which, I believe, is the only kind of program that could do it, until now).