Page 1 of 1
Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T06:30:38-07:00
by AnthonyC84
Hi,
I am trying to create a batch file so that when a multi page PDF document is dragged onto the PDF, the BAT file will create a multi page tiff document with the same filename and page numbers attached.
ie) File.pdf becomes File_001.tiff File_002.tiff .. etc.
I was looking at some posts and found this code for single files
for %%f in (%*) DO "C:\Program Files\ImageMagick-6.6.4-Q16\convert.exe" -density 300 -compress lzw %%f %%f.tiff
However, this is for single page pdfs and I also learned that convert.exe didn't exist in my install and was replaced with magick. I tried modifying the code to
for %%f in (%*) DO "C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe" -density 300 -compress lzw -units pixelsperinch %%f %%f_%03d.tiff
Sadly, this doesn't work.
Could anyone tell me how to modify the code to make it work?
Moreover as a bonus, could anyone tell me what I could input into a batch file that will take tiff files in a folder and convert them into a single pdf
in otherwords in imgmagick perform convert *.tiff -compress lzw "filename.pdf"
Cheers.
Re: Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T06:59:57-07:00
by snibgo
AnthonyC84 wrote:Sadly, this doesn't work.
It would help if you said what happens instead -- error messages or any file outputs or what?
In a batch file, any % signs (other than script parameters) need to be doubled. So you need %%f_%%03d.tiff for the output filename.
Re: Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T07:53:06-07:00
by Werty
Do you have Ghostscript installed ? that is required on Windows platforms to convert PDF's.
Read here:
https://imagemagick.org/Usage/files/#de ... postscript
Ghostscript here:
https://www.ghostscript.com/download.html
Re: Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T07:55:08-07:00
by AnthonyC84
snibgo wrote: ↑2019-07-16T06:59:57-07:00
AnthonyC84 wrote:Sadly, this doesn't work.
It would help if you said what happens instead -- error messages or any file outputs or what?
In a batch file, any % signs (other than script parameters) need to be doubled. So you need %%f_%%03d.tiff for the output filename.
The BAT would lock up CMD and didn't flag any error. However, adding the extra % sign has worked. Thank you.
Now I just need to fiddle with getting a batch of tiff files to convert to a single pdf.
Re: Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T07:57:52-07:00
by AnthonyC84
I have GS as well as imgmagick. I'm use to using imgmagick commands in CMD but I have no real experience creating batch files. I just want a simple solution for some colleagues who are not very good with computers who will not go into a cmd window cuz they think they will explode their PC.
Re: Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T08:16:09-07:00
by snibgo
AnthonyC84 wrote:... cuz they think they will explode their PC.
Ha!
AnthonyC84 wrote:... a batch file that will take tiff files in a folder and convert them into a single pdf
in otherwords in imgmagick perform convert *.tiff -compress lzw "filename.pdf"
I suppose that command does exactly what you need, and you want to put it into a "drag-n-drop" BAT file. I encourage you to experiment.
Create a BAT file on your desktop. Insert that command. Then when any file is dropped onto the BAT file, that command will be executed in that directory.
Re: Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T08:17:59-07:00
by AnthonyC84
I got the Tiff to PDF to work.
For anyone who wants to know Batch code to do the conversions with ImageMagick installed.
PDF->Tiff
for %%f in (%*) DO "C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe" -density 300 -compress lzw -units pixelsperinch %%f %%f_%%03d.tiff
Tiff->PDF
for %%f in (%*) DO "C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe" *.tiff -compress lzw -quality 100 %%f.pdf
Note that if you have a different version of ImageMagick you need to change the directory path to the exe.
Cheers!
Re: Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T08:21:42-07:00
by snibgo
You have omitted "for" at the start of those examples.
Your second example will read all of the tiff files and put then in a single PDF named after the first tiff. Then it will again read all of the tiff files and put then in a single PDF named after the second tiff, and so on.
Re: Trying to make a BAT file to convert PDF to multi page tiff
Posted: 2019-07-16T08:34:31-07:00
by AnthonyC84
snibgo wrote: ↑2019-07-16T08:21:42-07:00
You have omitted "for" at the start of those examples.
Your second example will read
all of the tiff files and put then in a single PDF named after the first tiff. Then it will again read
all of the tiff files and put then in a single PDF named after the second tiff, and so on.
I edited the post for the "for" missing.
For the 2nd statement. This doesn't happen for me. I just drag the first tiff file only and that's it. You do not highlight all the tiff files and drag them onto the batch file.
** I'd be interested in knowing the proper code for highlighting all tiff files and dragging them onto the BAT file for a single output pdf but nothing seems to be working atm.
You are correct in that if there are tiff files from different files that I don't want merged then this code is not efficient. The file path needs to contain only the tiff files I want to convert into a pdf.
You can change the line to
"C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe" *.tiff -compress lzw -quality 100 %1.pdf
or
"C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe" *.tiff -compress lzw -quality 100 Output.pdf