Automator Script to batch convert images in pdf with custom setings

Hi,


I'm very new to "Automator" and I'm a little bit lost but for what I saw on internet I saw "Automator" could help me in my batch converting. Because now I'm doing all this by myself with "Preview" and the "Print Settings"


I need to convert on lot of folders full of picture into pdf. But I need to create a pdf for for each folder of pictures, each pdf should have the name of the folder. And the pdf should have a "Paper size="A4 Borderless" and the rendering should be "Scaled to fit=Print Entire Image".


Folder X001/pic001.jpg, pic002.jpg, pic003.jpg...... -> Folder X001.pdf

Folder X002/pic001.jpg, pic002.jpg, pic003.jpg...... -> Folder X002.pdf


I imagine the script giving me the option when I right-click the folder to "Convert in pdf" and it automatically name it like the folder.


Thanks a lot!

MacBook Pro (15-inch, Late 2016)

Posted on Apr 27, 2017 6:26 PM

Reply
26 replies

Apr 30, 2017 5:36 PM in response to François20290

This might scale the images the way you want:


User uploaded file

User uploaded file


The Run Shell Script Action is:


thetmpdir=$(mktemp -d)

folder=$(dirname "$1")

foldername=$(basename "$folder")


for f in "$@"

do

sips -Z 2480 -s format pdf -p 3508 2480 --padColor FFFFFF "$f" --out "$thetmpdir/"$(basename "$f")".pdf"

done


#Combine:

"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o ~/Desktop/temp.pdf "$thetmpdir/"*.pdf


mv ~/Desktop/temp.pdf "$folder"/"$foldername.pdf"


#remove temp files

rm "$thetmpdir/"*.pdf

rm -d $thetmpdir

May 1, 2017 9:27 AM in response to François20290

François20290 wrote:


Tony T1 I finally find a way to fix the Workflow here the revision 1.1


https://ufile.io/zau8l


I wonder if there is a way to make it more powerful I'm thinking of selecting 10 folders filled with images, clicking Folder to PDF and the workflow creates a pdf of each folder inside them?


Glad it worked, I wasn't sure if the scaling to A4 was working.


You can make it work for multiple folders by adding a loop.

First you need to download and Install Dispense Items Incrementally from

http://www.automator.us/leopard/downloads/index.html


Then add that action as the first Action,

and Loop (with [loop automatically] Stop after [25 times]) as the last action:


User uploaded file

User uploaded file

User uploaded file

Apr 30, 2017 8:18 PM in response to François20290

What I would do is to write some program to create an html file with a list of img tags in the file. Once all the images are in the file, convert the html file to a pdf.


VikingOSX wrote this line to convert a file to pdf. Need to change -i to whatever you need for pdf.

man cupsfilter

do shell script "/usr/sbin/cupsfilter -i text/plain -m application/pdf " & posix_path & " >" & out_dir & pdf_file

Re: Apple Script - text file to pdf


R

May 1, 2017 4:39 AM in response to Tony T1

Thank you so much Tony T1! I tried to follow your instructions but there are 2 problems.


First I can't get the action to display in the menu when I right click the folder I wan't to convert.


Then even when I try to add the folder at the very top of the workflow in Automator it copy past all the images on my desktop and create the PDF correctly named but inside the folder of the images


Finally I choose to not scale the images I prefer using Each Page to Fit.


Here my the workflow I create if you want to look at it and tell me what I did wrong: https://ufile.io/f7htr


Thanks again!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator Script to batch convert images in pdf with custom setings

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.