Convert a batch of jpgs into pdfs

Greetings all.

Has anyone used automator to convert a batch of jpg's into PDFs? (I am looking to do a 1 to 1 conversion, not merge multiple JPG's into 1 PDF).

I have over 1000 jogs that I have to convert, and I need to do preserve the file name. If anyone has been successful with this, would you be willing to share how you did it?


Thanks in advance and regards,

AJ

MacBook Pro with Retina display, OS X Mavericks (10.9.3)

Posted on Sep 14, 2015 5:33 PM

Reply
Question marked as Top-ranking reply

Posted on Sep 15, 2015 9:35 PM

Hi,


Firecop1 wrote:


This did it! I went with your second option. I worked for jpgs but not jpegs. How would I modify it to convert both without having to go back in and change .jpg in the first line to .jpeg?


Thanks

AJ


Like this:

cd "$@" && for f in *.{jpeg,jpg}
do
    sips -i -s format pdf "$f" -o "${f%.*}".pdf
done


No error when the folder doesn't contains a ".jpeg" file, but an error will occur if you do not have at least one ".jpg" file in the folder.



------

If you do not want to get error when the folder contains no ".jpg" file or neither, use this script:

shopt -s nullglob
cd "$@" && for f in *.{jpeg,jpg}
do
    sips -i -s format pdf "$f" -o "${f%.*}".pdf
done
29 replies
Question marked as Top-ranking reply

Sep 15, 2015 9:35 PM in response to Firecop1

Hi,


Firecop1 wrote:


This did it! I went with your second option. I worked for jpgs but not jpegs. How would I modify it to convert both without having to go back in and change .jpg in the first line to .jpeg?


Thanks

AJ


Like this:

cd "$@" && for f in *.{jpeg,jpg}
do
    sips -i -s format pdf "$f" -o "${f%.*}".pdf
done


No error when the folder doesn't contains a ".jpeg" file, but an error will occur if you do not have at least one ".jpg" file in the folder.



------

If you do not want to get error when the folder contains no ".jpg" file or neither, use this script:

shopt -s nullglob
cd "$@" && for f in *.{jpeg,jpg}
do
    sips -i -s format pdf "$f" -o "${f%.*}".pdf
done

Sep 16, 2015 5:35 AM in response to Firecop1

Hi,


Firecop1 wrote:


I ran the line in terminal. It did in fact create PDFs out of the two JPEG files that were on my desktop. At this point, I am still not sure why it won't do it from a folder on the desktop......


The for loop doesn't work correctly when a filename or the name of the folder contains a space character, you must enclose the input with double quotes, and set the IFS to linefeed


So, use this

IFS=$'\n'
for f in $(ls -1 "$@"/*.{jpg,jpeg})



or use this script :

cd "$@" && for f in *.jpg
do
  sips -i -s format pdf "$f" -o "${f%.*}".pdf
done

Sep 15, 2015 1:21 PM in response to Firecop1

Here is an example Automator application that prompts you for the single folder containing your jpg images. It passes the folder path as an argument to the Bash shell script that generates the full path list of jpg filenames in the provided folder. Each file is converted from jpg to a matching PDF file — retaining the original filename. PDFs are written in the same location as the image files, and the PDF icon is the former jpg image.


Create a test directory, and use that to evaluate this tool.


If you want this to recurse deeper into the specified directory and convert all found jpg, or specify a different PDF output location, changes will be necessary.


Application jpg2pdf.app


User uploaded file

Sep 15, 2015 11:51 AM in response to Firecop1

Launch Automator. From the File menu Recents, pick this application that you are using. Expand the run shell script action so that all of the code shows. Press shift-command-4 to click and drag around your entire workflow. I want to see what you currently have. Use the camera icon in this editor's toolbar to post that screen shot image now on your Desktop in your next post.

Sep 15, 2015 7:20 AM in response to Firecop1

You can debug what's happening with echo.

Change the line:

/usr/bin/sips -i -s format pdf "${f}" -o "${f%.*}"".pdf"

to:

echo /usr/bin/sips -i -s format pdf "${f}" -o "${f%.*}"".pdf" >> ~/Desktop/debug.txt

This will create a file on your Desktop called debug.txt that may help VikingOSX see what's happening on your system.

Post a few lines of what you get in the debug.txt file (redacting any into you don't want to post)

Sep 15, 2015 8:55 AM in response to Firecop1

The Automator application will prompt you for a folder and that is it. There is no other visible output from the running application. Look for the converted same name PDF files with the original images icon in the same location as the specified folder.


The log that you posted shows correct sips functionality. If not, sips would have error messages in your log post.


You can see the results of the Automator activity in the Results window of the Run Shell Script action by interactively running the Automator application when it is open in Automator. See image below.

User uploaded file

Sep 14, 2015 5:39 PM in response to Firecop1

This site has a poor setup - before posting a new question use the search to the right of People to Search this site.

To search Apple site - use the Magnifying glass in the top Bar.

Sometimes questions go unanswered simply because they have been asked many many times before.



Also if More like this below has some threads on converting files in mass.

Sep 15, 2015 10:49 AM in response to VikingOSX

I did indeed. I posted what I saw in the log above.

Again, it lists:

"Ask for Finder Items completed",

"Run Shell Script completed"

"Workflow completed".

Each of these entries have a green check mark next to them.

There are no PDF's anywhere on my mac with the same name as the JPG files that are in the folder that I am trying to convert. There are no PDFs of any kind on my desktop

When selecting the folder in step 1, I single click to select it and then I press Choose. This is the way I have done it each time I tried.

Thanks for your patience.

Sep 15, 2015 12:52 PM in response to VikingOSX

VikingOSX wrote:


The log that you posted shows correct sips functionality. If not, sips would have error messages in your log post.


The debug.txt that I asked him to post is just an echo, so the command was not run, but did show that there were no errors in the command on his system.

OP needs to just copy one of the lines to Terminal to see if there are any error messages.


BTW, thanks for posting this. I didn't know sips could convert to pdf (the man page doesn't list pdf in the format section).

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.

Convert a batch of jpgs into pdfs

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