2

I have a directory foo containing .pdf files named with pattern X01, X02, ..., each two pages long. I want to combine them to a new .pdf, named "all_YY-MM-DDTHHMMSS.pdf" that will contain the file names as bookmarks.

I used these two commands. While the first one works well,

$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dAutoRotatePages=/None -sOutputFile=all_$(date +"%FT%H%M%S").pdf X*.pdf

the second one, based on this answer fails.

$ pdftk all_2023-07-12T094706.pdf update_info {ls | grep X*} output out.pdf
grep: X}: No such file or directory
grep: output: No such file or directory
grep: out.pdf: No such file or directory
Done.  Input errors, so no output created.

I was trying to grep the ls for the filenames starting with X*, in order to exclude the new combined .pdf names all....

How do I get this to work, preferably by adding update_info to the first command?

I'm aware of solutions like this, but they look rather tedious.

jay.sf
  • 227
  • but the answert you linked to looks like the minimum effort you could possibly have to go through? You need to tell your PDF library what bookmarks to set where, and writing an info file is exactly the pdftk and also mupdf way to do that. – Marcus Müller Jul 12 '23 at 08:31
  • @MarcusMüller That's actually what I tried to accomplish using ls | grep X* since this gives me exactly the bookmarks I want for each first page of the two-pages and should avoid the interim step of creating an info file first to read in again, and which seems a bit redundant to me. – jay.sf Jul 12 '23 at 08:34
  • just as an aside, don't parse ls output, your shell can already just glob X* (and it's not fragile, unlike the ls | grep construct, which almost certainly doesn't do what you think it does, as well.). Again, the contents info file seems to be the minimum of information any program could need, so you'll have to put that info somewhere. – Marcus Müller Jul 12 '23 at 08:38
  • @MarcusMüller Although I still don't get why a file is absolutely necessary, can you see a way to cat this in a tempfile and read it in again to give the program the information? – jay.sf Jul 12 '23 at 08:48
  • well, since your {ls | grep X*} makes no sense to me (nor does it to the shell nor your grep, see your error messages), I really don't! I'd refer to the linked answer. – Marcus Müller Jul 12 '23 at 16:00
  • @MarcusMüller With {ls | grep X*} I'm trying to say, list directory and grep it for filenames starting with X, as a substitute for reading something from a file. – jay.sf Jul 12 '23 at 16:54
  • Yeah. Instead of that {ls | grep X*}, just X* would be correct. – Marcus Müller Jul 12 '23 at 18:12
  • @MarcusMüller I already tried pdftk all_2023-07-12T094706.pdf update_info X* output out.pdf, gave me Error: expecting "output" keyword. Instead, I got: st_ps_S00002_2023-07-12T202825.pdf. – jay.sf Jul 12 '23 at 18:53
  • well, it really says what's wrong. Face it. Solving the problem you set out to solve is as complex as the linked answer. And that's not very complex. – Marcus Müller Jul 12 '23 at 22:30

0 Answers0