Search Subfolders and create for each JPG one PDF with same filename at found location

Discussion in 'Mac Programming' started by kijunam, Apr 8, 2018.

  1. kijunam macrumors newbie

    Joined:
    Apr 8, 2018
    #1
    Hi Together:

    It's amazing but I cannot find a solution for a task, which I think many people may need.
    There are hundreds of solutions for combining JPGs into one Pdf but no one, which creates for each found jpg one single pdf with the same filename


    I would like to achieve the following:

    1.) Select Folder in Finder
    2.) Start Automator or Script which does the following
    - Search all subfolders
    - If Picture is found, create PDF with pictures name at found location

    That's all but I cannot find a solution other than buying AdobePro for 800$ which I would like to avoid, if possible.

    Can someone help me?
     
  2. Kingcr macrumors member

    Joined:
    Feb 1, 2018
    Location:
    UK
    #2
    I'd suggest you just use the command line to do this for free - something like this:
    - Open Terminal
    - Run: IFS=$'\n'
    - Run: for i in `find "/path/to/root/folder/" -name *.jpg`; do sips -s format pdf "$i" --out ${i%.*}.pdf; done

    Some notes, since I've no idea how familiar you are with the command line:
    - Substitute the root folder location in the second command.
    - Check the quotation marks if you copy and paste this. macOS tends to change quotation marks to make them look pretty. There are single, double quotes and backticks (`) in there.
    - The pdf's that are created will OVERWRITE any existing pdf files of the same name.
    - You could obviously put these commands into a parameterised script if you need to do this often.
    - Always test commands/scripts that other people provide in a test directory :)
     
  3. kijunam, Apr 8, 2018
    Last edited: Apr 8, 2018

    kijunam thread starter macrumors newbie

    Joined:
    Apr 8, 2018
    #3
    Dear Kingcr:

    Forst of all, thank you for your time and help.

    Unfortunately, It worked only partial.
    The result was, that the first JPG (1st out of 4) was converted into PDF but the script seamed to stop afterwards. The remaining 3 are still unconverted.

    I copied the following:

    IFS=$'\n'

    for i in `find "/Users/fk/Desktop/Test/2017-12" -name *.jpg`; do sips -s format pdf "$i" --out ${i%.*}.pdf; done


    The message from Terminal was:

    /Users/fk/Desktop/Test/2017-12/11_2017-12-25_Lunch.jpg

    /Users/fk/Desktop/Test/2017-12/11_2017-12-25_Lunch.pdf
     
  4. kijunam thread starter macrumors newbie

    Joined:
    Apr 8, 2018
    #4

    I found the problem. The first file had the ending jpg , the other 3 JPG. Is there a way that it does not matter?
     
  5. Kingcr macrumors member

    Joined:
    Feb 1, 2018
    Location:
    UK
    #5
    Sure there is. Just replace the "-name" parameter to the find program with "-iname" so that it performs a case-insensitive search.

    So your commands would look like this:

    IFS=$'\n'

    for i in `find "/Users/fk/Desktop/Test/2017-12" -iname *.jpg`; do sips -s format pdf "$i" --out ${i%.*}.pdf; done
     

Share This Page