1 2 3 4 5 6 Previous Next 77 Replies Latest reply: Jun 30, 2014 10:34 PM by Eureka098 Go to original post
  • 45. Re: how do I use automator to batch convert doc to pdf?
    mohair_slim Level 1 Level 1 (0 points)

    Hi Spazek.

     

    Have you though any more about adding to the script so that if there is already a PDF by than name it adds a number on the end?  e.g.  "test 1.pdf".  At the moment it just gets an error.  Thx heaps.

  • 46. Re: how do I use automator to batch convert doc to pdf?
    spazek Level 2 Level 2 (215 points)

    Hi,

    (this is an example for an already opened Word document only)

     

    tell application "Microsoft Word"

              set theDoc to path of active document as alias

     

              tell application "Finder"

                        set ext to name extension of theDoc

                        set x to (length of ext) + 2

                        set theName to (text 1 thru -x) of (theDoc as string)

                        set thePDF to theName & ".pdf"

     

      --IF FILE ALREADY EXISTS ADD A NUMBER (INCREASING)

                        if (exists file thePDF) then

                                  set n to 1

                                  set thePDF to theName & "_" & n & ".pdf"

                                  repeat until (exists file thePDF) is false

                                            if (exists file thePDF) then

                                                      set n to n + 1

                                                      set thePDF to theName & "_" & n & ".pdf"

                                            end if

                                  end repeat

                        end if

     

              end tell

     

              set theActiveDoc to the active document

              try

      save as theActiveDoc file format format PDF file name thePDF

              on error

      display alert "Error"

     

              end try

      -- close theActiveDoc

     

    end tell


    It looks for existing files and adds a number (or increases it) : if there is a "test_1.pdf" ist will save it as "test_2.pdf" ...

     

    I will add the necessary lines to the script on page 1 the next days...

     

    Spazek

  • 47. Re: how do I use automator to batch convert doc to pdf?
    mohair_slim Level 1 Level 1 (0 points)

    Love your work Spazek.  You the boss.

  • 48. Re: how do I use automator to batch convert doc to pdf?
    spazek Level 2 Level 2 (215 points)

    So here a modificated version of the script on page 1 to use in the Run AppleScript Action:

     

     

    property theList : {"doc", "docx"}

     

    on run {input, parameters}

              set output to {}

              tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path

              repeat with x in input

                        try

                                  set theDoc to contents of x

     

                                  tell application "Finder"

                                            set ext to name extension of theDoc

                                            if ext is in theList then

                                                      set x to (length of ext) + 2

                                                      set theName to (text 1 thru -x) of (theDoc as string)

                                                      set thePDF to theName & ".pdf"

     

                                                      if (exists file thePDF) then

                                                                set n to 1

                                                                set thePDF to theName & "_" & n & ".pdf"

                                                                repeat until (exists file thePDF) is false

                                                                          if (exists file thePDF) then

                                                                                    set n to n + 1

                                                                                    set thePDF to theName & "_" & n & ".pdf"

                                                                          end if

                                                                end repeat

                                                      end if

     

     

     

                                                      tell application "Microsoft Word"

                                                                open theDoc

                                                                set theActiveDoc to the active document

      save as theActiveDoc file format format PDF file name thePDF

                                                                copy (POSIX path of thePDF) to end of output

      close theActiveDoc

                                                      end tell

     

                                            end if

                                  end tell

     

     

                        end try

              end repeat

     

              tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath

     

     

              return output

    end run

     

     

     

    --Spazek

  • 49. Re: how do I use automator to batch convert doc to pdf?
    Jef Leys Level 1 Level 1 (0 points)

    Hi,

     

    You could also use this.

     

    Just print to a PDF printer.

     

    http://www.maclife.com/article/howtos/how_print_directly_pdf_without_opening_fil e

     

    You don't need apple scripting, only automator.

  • 50. Re: how do I use automator to batch convert doc to pdf?
    eplefrikk Level 1 Level 1 (5 points)

    Thank you, all of you! It looks like @spazek is posting some great code here, but for me the AppleScript applet posted by @studentfromutrecht (goo.gl/IAl4h) worked like a charm right out of the box.

  • 51. Re: how do I use automator to batch convert doc to pdf?
    ptr10402 Level 1 Level 1 (0 points)

    Just have to say,

     

    spazek your script works like magic!

     

     

    thanks a million~

  • 52. Re: how do I use automator to batch convert doc to pdf?
    JAC151 Level 1 Level 1 (0 points)

    I want to thank you for your scripts, they have helped me a lot, but, if you have time, I have two questions.

     

    1)  This conversion does not mess witht the content or format of your documents, correct?  (It doesn't appear to).

     

    2) How can I alter this to work with Pages '09 files?  (Also, if possible the new Pages '13 as well, but mainly the Pages '09).  If you have time to reply I would appreciate it, if not you've already helped me a ton.

     

     

    Thanks again!

  • 53. Re: how do I use automator to batch convert doc to pdf?
    matt.bowlby Level 1 Level 1 (0 points)

    These are wonderful - but I'm having a little trouble getting it to work. Perhaps it has to do with using Mavericks?

     

    I am trying to get this to work a different way. I want to be able to select a Word file in finder and have that file be converted into PDF. This could be a service, which is really just executing an AppleScript. In fact, what I would do is have Hazel watch a particular folder and convert every file in that folder to PDF.

     

    My AppleScripting skills are still quick elementary. Can anyone help with this? Your help would be very appreciated.

  • 54. Re: how do I use automator to batch convert doc to pdf?
    qfieldboden Level 1 Level 1 (0 points)

    Hi

     

    I'm in a similar situation and would very much like some help too if there is anyone willing and able out there. My stuation is that I have a large number of .doc files of varying ages but mostly from around 1992-1994.

     

    I'm using a Mavericks installation with Office Mac 2011 I've just bought, all the latest versions, all software has been updated. I'm finding that I can open all the files I want to convert using Word if I open Word and use the File->Open option on single files, so all the files are "openable". However, if I use the Automator system or some of the excellent scripts posted earlier in this thread I just get no output from the script, and no PDFs. The problem seems to be that on some of the files I get the message in the image attached below, even when I try opening them by double-clicking rather than using the File->Open menu.

     

    My gut feeling is that this is the problem that the Automator or the script are running up against, can anyone suggest how I might get this to work, if not I've just thrown top $s down the drain

     

    In a nutshell I believe that for some reason the script and automator are unable to open these files even though the File-Open option can. I really don't want to have to open them all one by one and then save them individually as PDFs!

     

    Thank you,

     

    Quentin.

     

    Screen Shot 2013-12-20 at 21.25.58.png
  • 55. Re: how do I use automator to batch convert doc to pdf?
    Bartarter Level 1 Level 1 (0 points)

    Try the PDF export of OpenOffice.
    MS Office for Mac is quite bad with pdfs (and other stuff) I had some font issues which OpenOffice solved. Considering how long OO supports pdf exports it probably supports all forms, links and such too. Or if you have Windows use Office 2007 SP2 or later those have an actual save as PDF option and not just some pdf printer that poses as a pdf saving option.

     

    Not very convenient but if it is only very few files, online converters do the trick. They eat just about everything and most produce very good results with support for just about anything.
    as an example.
    http://www.pdf-file-converter.com/create-pdf-from-ms-office-on-mac/

  • 56. Re: how do I use automator to batch convert doc to pdf?
    Grady Tracy1 Level 1 Level 1 (75 points)

    spazekI'm having a difficult time trying to do this...

     

    I am opening Automator

    Choosing Application

    Draging Run Apple Script to the workflow area

    Earasing all information from the script and pasting your script in the area.

    Saving the application to my desktop with the name of "PDF Maker"

     

    For a test, I am draging a .doc file over the PDF Maker and dropping the file to run the script.

     

    Then I get this error

     

    The action "Run AppleScript" encounted an error.

    Check the actionʼs properties and try running the workflow again.

     

    What am I doing wrong?

    I am using Word 2011 (student version)

    OSX 10.9.2

     

    Any help would be great. Thanks.

  • 57. Re: how do I use automator to batch convert doc to pdf?
    SkyWatching Level 1 Level 1 (0 points)

    OMG!! This worked perfectly on the first try.  You have just saved me soooooo much trouble!

     

    THANK YOU FOR SHARING THIS!

  • 58. Re: how do I use automator to batch convert doc to pdf?
    Amanda Marks1 Level 1 Level 1 (0 points)

    THANK YOU!  Amazing - solved all my problems!

  • 59. Re: how do I use automator to batch convert doc to pdf?
    Albatros blanc Level 1 Level 1 (0 points)

    I have a similar problem which needs batch converting:

     

    I have got on a CDROM roughly 1200 .pdf documents which I need to open with preview and than to export as PDF.

     

    This sounds a little odd but I have to do this because the documents, as they are currently saved, appear to be sort of corrupted and by this process the corruption is cured.

     

    Thanks for any help!