EDIT: It turns out that Lua is not needed. Since I call my TeX from script, the necessary investigation can be done directly, using findstr
in Windows batch, or the equivalent in BASH. But that's using script prior to running the TeX file. The answers provided below will do it within the TeX file.
Question:
I use only LuaLaTeX, Windows and Linux. For cross-platform compatibility, and for non-admin users, I cannot invoke sed
or most other shell-escape programs from within TeX, even if it is available. I can invoke from outside TeX with a non-admin batch or BASH script.
My document class produces PDF/X-1a. Thus, any included image must be DeviceGray or DeviceCMYK. Currently, I avoid potential problems by severely limiting TeX commands that include images or other PDF. I would like to lift the limitations, if possible.
Thanks to this very helpful answer of a related question, I can block using \includepdf
if the included file has fonts in it. Now, I would like to block using \includepdf
unless the file has DeviceGray
or DeviceCMYK
written into it.
In all cases, the included PDF is just one page, one image.
If I open a suitable PDF in a hex editor, I see something like this:
10 0 obj
/DeviceCMYK
endobj
The actual image follows as another object (with FlateDecode).
So, to rephrase my question: Is there any way LuaLaTeX can screen a PDF file, perhaps using methods similar to sed
or grep
, and provide a yes/no answer as to whether string DeviceCMYK
or DeviceGray
appears?
I myself can simply use Adobe Acrobat Pro, or perhaps ImageMagick. This is for the benefit of more general users, without having to step outside of LuaLaTeX.
epdf
library to navigate the PDF structure); the hard part may be in understanding enough of PDF structure (and theepdf
library) to express what you want. Maybe the user who gave the other answer also knows how to do this (i.e. leave a message on that answer linking to this question)? – ShreevatsaR Mar 1 '18 at 1:18findstr
does the job, and BASH has a similar method. Since my TeX file is called from command line, it's easy enough to do what I need in a shell script, without Lua. I wouldn't have guessed, but it works! – user139954 Mar 1 '18 at 3:41