Page 1 of 1

Bash and multiple pdf

Posted: 2019-05-01T23:23:16-07:00
by newone
Hi,

so here is what I'm trying to do. I have a bunch of PDF files called:

67123_001.pdf
67134_001.pdf

which are multiple page pdfs.

I would like to convert them to single page .tif files and keep the first number of the name before'_' and increase the count after '_' for each page. So for example if "67123_001.pdf" has 3 pages, I would like to get the following result:

"67123_001.tif"
"67123_002.tif"
"67123_003.tif"

I also need a batch to do this, since I have > 40.000 documents.

I already have a solution for one part of the problem: a good resolution when converting pdf to tif and a count for the single pages when I split the pdf file. I still haven't figured out how to write a batch and how to keep the first part of the name. Here's what i git so far:

Code: Select all

convert -density 300 67123_001.pdf -depth 8 -strip -background white -alpha off output_%03d.tif
Thanks for your help!

Re: Bash and multiple pdf

Posted: 2019-05-01T23:58:24-07:00
by fmw42
I have moved your post from Consulting, since that forum is for PAID consulting only.

What is your platform -- Linux, Mac OSX or Windows? Scripting is different for Linux/Mac vs Windows.

Doing -background white -alpha off will not make the background white if the PDF has transparency. You would need to doe -background white -alpha background -alpha off.

Re: Bash and multiple pdf

Posted: 2019-05-02T04:59:12-07:00
by newone
Thanks! Linux RedHat

Re: Bash and multiple pdf

Posted: 2019-05-02T09:14:59-07:00
by fmw42
Using bash scripting

Code: Select all

for img in /path_to_images/*.pdf; do
name=$(convert "$img" -format "%t\n" info: | -head 1)
convert -density 300 "$img" -depth 8 -strip -background white -alpha background -alpha off ${name}_%03d.tif
done
for the line starting with name, see string formats at https://imagemagick.org/script/escape.php

If your PDF is in CMYK, then you would need to add -colorspace sRGB between your -density 300 and the "$img"

Re: Bash and multiple pdf

Posted: 2019-05-03T00:22:55-07:00
by newone

Code: Select all

for img in ./*.pdf; do
> name=$(convert "$img" -format "%t\n" info: | -head 1)
> convert -density 300 "$img" -depth 8 -strip -background white -alpha background -alpha off ${name}_%03d.tif
> done
-bash: -head: command not found

Re: Bash and multiple pdf

Posted: 2019-05-03T00:23:52-07:00
by newone
Thanks! This is what I get"-bash: -head: command not found" and the result ist "_000.tif"

Re: Bash and multiple pdf

Posted: 2019-05-03T02:55:41-07:00
by snibgo
I think "head" shouldn't have a hyphen.

Re: Bash and multiple pdf

Posted: 2019-05-03T10:07:05-07:00
by fmw42
My typo. Snibgo is correct. It should be "head -n 1"

Code: Select all

for img in /path_to_images/*.pdf; do
name=$(convert "$img" -format "%t\n" info: | head -n 1)
convert -density 300 "$img" -depth 8 -strip -background white -alpha background -alpha off ${name}_%03d.tif
done