8 Replies Latest reply: Apr 8, 2009 12:59 PM by KOENIG Yvan
Ray Bentsen Level 1 Level 1 (70 points)
I have about 150 Pages documents that I would like to convert to PDFs, and I would prefer not to open each one and use the Print dialog to create a PDF.

Is this sort of batch conversion something that can be done with Automator, or is there any freeware that can do the job?

Thanks in advance for any suggestions.

2.66 GHz iMac G5 (Intel Core 2 Duo), Mac OS X (10.5.6)
  • Ric Donato Level 4 Level 4 (1,095 points)
    Hi Ray Bentsen,
    Welcome to Pages '09 discussions.

    If memory serves me correctly a Pages to PDF script was written by Yvan. Not sure if it works for Pages '09 so I'll suggest finding his link in these discussions asking him for suggestions. Maybe he'll see this post and answer you.

    Cordially,

    RicD
  • Ray Bentsen Level 1 Level 1 (70 points)
    Ric,

    Thanks for your reply. I found a solution from a different board, which suggested I try an Applescript posted on MacOSXHints. This script (Submitted by musselrock)will actually convert any batch of files that Pages can read:

    (* Drag and drop batch conversion of Word docs to PDF files using Pages*)
    on open filist
    repeat with lvar in filist
    tell application "Finder"
    set thename to name of lvar
    end tell
    set nuname to text 1 thru text item -5 of thename
    tell application "Pages"
    activate
    set filname to (path to desktop folder as text) & nuname & ".pdf"
    set x to make new document with properties {path:filname}
    open lvar
    save document 1 in file filname
    close every window saving no
    end tell
    end repeat
    end open

    It worked great except that both Pages and the script were set to append the .pdf extension ... so I ended up with files having ".p.pdf" extension. The files converted in about one second apiece. I was thrilled!! Thanks again.
  • Ric Donato Level 4 Level 4 (1,095 points)
    Hi Ray,
    Congratulations on the conversion. Thank you for that script as well.

    Cordially,

    RicD
  • Level 8 Level 8 (41,790 points)
    Here is a revised version.


    on open filist
    repeat with lvar in filist
    set lvar to lvar as text
    tell application "System Events" to tell disk item lvar
    set thename to get name
    set theExt to get name extension
    end tell
    set nuname to text 1 thru -(1 + (count of theExt)) of thename
    tell application "Pages"
    activate
    set filname to (path to desktop folder as text) & nuname & "pdf"
    set x to make new document with properties {path:filname}
    open lvar
    save document 1 in file filname
    close every window saving no
    end tell
    end repeat
    end open


    Yvan KOENIG (from FRANCE lundi 12 janvier 2009 21:30:46)
  • Ray Bentsen Level 1 Level 1 (70 points)
    Yvan,
    Thanks for posting a corrected script. Will that script work on any batch of files, regardless of current extension ... as long as they can be opened by Pages?

    It turns out that I was able to use Automator (for the first time) to replace all of the ".p.pdf" extensions on my files with ".pdf". So, I am all set.

    BTW, if you are using the first script with a trial version of Pages '09, the first file will not convert correctly ... because of the Pages "Try It or Buy It" screen. To avoid that problem simply launch Pages before running the script.
  • s.lallement Level 1 Level 1 (0 points)
    Yvan,
    I'm trying to use your script to batch convert Pages'08 to Pages'09 docs.
    I just put "pages" in place of "pdf" as extension string in the script, but it doesn't work : the new docs are still in Pages'08 format.
    In fact, I'm not an apple script expert !
    Do you have any idea about the way to do this ?
    Thanks !
  • fruhulda Level 6 Level 6 (15,120 points)
    s.lallement

    You don't need to change your Pages08 files to 09 files. Just open them in Pages09 when you need them. Then you can save them in Pages09. Both version end with .pages anyhow.
  • Level 8 Level 8 (41,790 points)
    If I dress my daughter with trousers she doesn't become my son !

    It's the same with files and name extensions.

    I really don't understand why some one may need a Pages '08 to Pages '09 converter script.

    I wrote one in a hurry which is able to do the job for the three kinds of documents.


    (*
    This script batch transcode iWork '08 into iWork '09.

    To use the script, save it as a script or as an "Application Bundle".
    As it's not a script which will be used daily, it's not useful to install it in the Scripts Menu.

    Run it (or double click its icon)
    navigate to the folder containing the docs
    click "OK"

    or

    drag and drop iWork '08 documents or folders
    containing iWork '08 documents on the script's icon.

    In both cases they will be saved as iWork '09 documents.

    The only interest is that it treats the three kinds of documents in a single call.

    Yvan KOENIG (Vallauris, FRANCE)
    8 avril 2009
    *)
    --=====
    (* Des globales *)
    property msg3 : "" -- globale
    property msg90 : "" -- globale
    property msg91 : "" -- globale
    property msg94 : "" -- globale
    property msg97 : "" -- globale
    property rapport : "" -- globale

    --=====

    on run
    tell application "System Events" to set dossier to choose folder (*
    dans un bloc System Events pour avoir un titre de dialogue "localisé"
    • in a System Events block to get a localized dialog title. *)
    my main({dossier})

    end run

    --=====

    on open sel
    my main(sel)
    end open

    --=====

    on main(sel)
    tell application "System Events" to set (UI elements enabled) to true
    my nettoie()
    my |prépareMessages|()

    try
    repeat with elem in sel
    try
    set elemT to elem as text
    tell application "System Events" to tell disk item (elem as text)
    if class is folder then
    set ptree to ""
    else
    set ptree to path of container
    end if
    end tell -- System Events
    my exploreTraite(elem, ptree)
    end try
    end repeat

    if rapport = "" then set rapport to msg90 (*
    crée un fichier texte sur le Bureau *)
    set nomDuRapport to "report_iWork08toiwork09.txt"
    set p2d to path to desktop
    set p2r to (p2d as text) & nomDuRapport
    tell application "System Events"
    if exists (file p2r) then delete (file p2r)
    make new file at end of p2d with properties {name:nomDuRapport}
    end tell -- System Events

    write (rapport as text) to (p2r as alias)

    my afficheLeMessage(msg3) (*
    Traitement terminé
    • Export done.
    *)
    on error MsgErr number NroErr
    if NroErr is not -128 then
    beep 2
    tell application (path to frontmost application as string) to ¬
    display alert "" & NroErr & " : " & MsgErr giving up after 20
    end if -- NroErr is…
    end try

    my nettoie()

    end main

    --=====

    on exploreTraite(elem, ptree) (*
    elem est un alias
    • elem is an alias *)
    local elemT, laClasse, UTI, flag, gr6
    set elemT to elem as text
    tell application "System Events" to tell disk item elemT
    set laClasse to class as text
    try
    set UTI to type identifier
    on error
    set UTI to ""
    end try
    end tell -- System Events
    if (UTI is not "") and UTI does not start with "com.apple.iwork." then
    set rapport to rapport & elemT & msg94 & return (*
    Attention, ce n'est pas un document iWork.
    • Caution, it's not an iWork document *)
    else if UTI starts with "com.apple.iwork." then
    my traiteUnFichier(elemT, UTI)
    else if laClasse is in {"file package", "«class cpkg»"} then
    set rapport to rapport & elemT & msg91 & return (*
    Attention, un package EST un dossier "spécial".
    • Caution, a package IS a "special" folder. *)
    else if laClasse is in {"folder", "«class cfol»"} then
    my ExploreUnDossier(elemT, ptree)
    else
    set rapport to rapport & elemT & msg94 & return (*
    Pas un document iWork.
    • not an iWork file. *)
    end if
    end exploreTraite

    --=====

    on ExploreUnDossier(dossier, ptree)
    local nomElement, cheminElement
    repeat with nomElement in list folder dossier without invisibles
    try
    set cheminElement to dossier & (nomElement as text)
    tell application "System Events" to set c to name of folder dossier
    my exploreTraite(cheminElement as alias, ptree & c & ":")
    on error errmsg number errNbr
    set rapport to rapport & dossier & msg97 & return & errNbr & return & errmsg
    end try
    end repeat
    end ExploreUnDossier

    --=====

    on afficheLeMessage(m)
    beep 1
    tell application (path to frontmost application as string)
    activate
    display alert m giving up after 10
    end tell
    end afficheLeMessage

    --=====

    on traiteUnFichier(cheminDocIwork, UTI)

    if UTI contains "pages" then
    tell application "Pages" to open file cheminDocIwork
    my saveIt(cheminDocIwork, "Pages")
    else if UTI contains "numbers" then
    tell application "Numbers" to open file cheminDocIwork
    my saveIt(cheminDocIwork, "Numbers")
    else
    tell application "Keynote" to open file cheminDocIwork
    my saveIt(cheminDocIwork, "Keynote")
    end if
    end traiteUnFichier

    --=====

    on saveIt(f, a)

    tell application a to activate
    tell application "System Events" to tell process a
    keystroke "s" using {command down}
    repeat 10 times
    if exists sheet 1 of window 1 then
    keystroke return
    exit repeat
    end if
    end repeat
    end tell
    set phs to 0
    repeat
    tell application "System Events" to set phs2 to physical size of file f
    if phs2 = phs then exit repeat (* the doc is completely written on the disk *)
    set phs to phs2
    end repeat
    tell application "System Events" to tell process a
    keystroke "w" using {command down}
    end tell
    end saveIt

    --=====

    on nettoie() (*
    pour ne pas stocker dans le fichier script
    • So it will not be stored in the script file *)
    set msg3 to ""
    set msg90 to ""
    set msg91 to ""
    set msg94 to ""
    set msg97 to ""
    set rapport to ""
    end nettoie

    --=====

    on |prépareMessages|()

    if (do shell script "defaults read 'Apple Global Domain' AppleLocale") starts with "fr_" then

    set msg3 to "Terminé !"
    set msg90 to "Conversion réussie sans incident."
    set msg91 to " est un Package !"
    set msg94 to " n’est pas un fichier iWork !"
    set msg97 to " n’a pu être identifié !"
    else
    set msg3 to "Done !"
    set msg90 to "No problem during the recoding process."
    set msg91 to " is a Package !"
    set msg94 to " is not an AW file !"
    set msg97 to " can’t be identified !"
    end if
    end |prépareMessages|

    --=====


    Yvan KOENIG (from FRANCE mercredi 8 avril 2009 21:58:54)