3 votos

¿Puedo distribuir versiones de varias presentaciones de PowerPoint convertidas en archivos PDF?

Usando PowerPoint 16.15 en Mac OS X High Sierra 10.13.15...

Tengo una carpeta de archivos PPT. Me gustaría guardarlos como archivos PDF, con un diseño de hojas de mano (6 por página) y una salida en blanco y negro.

¿Hay alguna forma (por ejemplo, utilizando Automator, scripts o automatización) de hacer esto para cada archivo en la carpeta?

0 votos

¿Y con la nota clave?

0 votos

¿Es Keynote más programable que PowerPoint? Por cierto, sé cómo hacer el PDF deseado a partir de un archivo PPT abierto. El problema es que tengo más de 25 archivos y prefiero no hacerlo de uno en uno.

0 votos

Ok voy a hacer un script pronto.

3voto

Wolfgang Fahl Puntos 116

Me ha costado unas cuantas horas dar con una solución que funcione en mi entorno. Tenga en cuenta que algunos elementos necesitan internacionalización como "Vorschau" o "Sichern". Esta es una solución en alemán que funciona con PowerPoint para Mac 16.16.27 en MacOS HighSierra 10.13.6.

Tuve que depurar mucho las cosas con ScriptDebug (99 dólares bien gastados..) para que las cosas funcionaran. Tenga en cuenta cómo se utiliza la vista previa para el ahorro de PDF real. Traté de hacer esto desde Powerpoint pero no era confiable.

https://latenightsw.com/

véase https://github.com/WolfgangFahl/ppt2pdf para una versión actualizada de esto.

Ejemplo de llamada

ppt2pdf *.pptx

Tenga en cuenta que los archivos se esperan en el directorio actual. El applescript ppt2pdf.scpt espera la ruta de los archivos como primer parámetro y todos los demás como simples nombres de archivos. Este comportamiento podría cambiarse fácilmente.

ppt2pdf

#!/bin/bash
# WF 2020-11-15
# use current path as base path
osascript $HOME/source/applescript/ppt2pdf.scpt $(pwd) $@

ppt2pdf.scpt

-- 2018-01-31
-- https://github.com/irmowan/Convert-ppt-to-pdf/blob/master/Convert-ppt-to-pdf.applescript
-- modified by WF 2020-11-15
-- 
-- ppt2Pdf({"/Users/wf/Projekte/2020/Infrastruktur2020/ppt2pdf", "TestMe.pptx"})

--http://hints.macworld.com/article.php?story=20050523140439734
-- passing command line arguments to applescript
on run (argv)
    log (count (argv))
    if ((count of argv) < 2) then
        log "usage: ppt2pdf basepath [filenames]"
    else
        my ppt2Pdf(argv)
    end if
end run

--
-- convert powerpoint to pdf on the given list of files
--
on ppt2Pdf(fileNames)
    log "launching Powerpoint ..."
    set pp to "Microsoft PowerPoint"
    tell application pp -- work on version 15.15 or newer
        launch
        set isfirst to true
        repeat with fileName in fileNames
            if isfirst then
                set basepath to fileName
                log "base path is " & basepath
                set isfirst to false
            else
                if fileName ends with ".ppt" or fileName ends with ".pptx" or fileName ends with ".pptm" then
                    set filePath to basepath & "/" & fileName
                    -- set filePath to POSIX path of fileAlias
                    set pdfPath to my makeNewPath(filePath)
                    log "trying to convert powerpoint file " & filePath & " to " & pdfPath
                    open filePath

                    -- save active presentation in pdfPath as save as PDF 
                    -- save in same folder
                    -- https://macscripter.net/viewtopic.php?id=26342
                    --tell application "System Events"
                    --  set listOfProcesses to (name of every process where background only is false)
                    --  tell me to set selectedProcesses to choose from list listOfProcesses with multiple selections allowed
                    --end tell
                    --repeat with processName in selectedProcesses
                    --  log processName
                    --end repeat

                    if not my chooseMenuItem(pp, "Datei", "Drucken...") then
                        error number -128
                    end if

                    --my showUiElements(pp, "menu button")
                    -- my waitFor(button whose description is "PDF", 5, 0.5)
                    my choosePopUp(pp, "Layout für den Druck", "Notizen")
                    my choosePopUp(pp, "Farbausgabeformat", "Farbe")
                    --my chooseMenuButtonItem(pp, "PDF", "Als PDF sichern")
                    local myTitle
                    tell application "System Events"
                        -- the magic of Applescript
                        -- if you really want the title and not a reference to it you need to use an operator
                        -- http://books.gigatux.nl/mirror/applescriptdefinitiveguide/applescpttdg2-CHP-12-SECT-5.html
                        set myTitle to title of window 1 of process pp & ""
                    end tell
                    my chooseMenuButtonItem(pp, "PDF", "In Vorschau öffnen")
                    delay 5
                    tell application "System Events"
                        log "waiting for Vorschau to display " & myTitle
                        set timeLeft to my waitForAppearWindow(myTitle, process "Vorschau", 30, 0.5)
                        if timeLeft < 0 then
                            log "Vorschau " & myTitle & " window didn't show up after 30 secs"
                            error number -128
                        else
                            log "Vorschau appeared with " & timeLeft & "secs left"
                            tell process "Vorschau"
                                delay 0.2
                                click menu item "Als PDF exportieren …" of menu 1 of menu bar item "Ablage" of menu bar 1
                                delay 0.5
                                -- CMD-SHIFT-G to set the export director
                                -- https://dougscripts.com/itunes/itinfo/keycodes.php
                                keystroke "g" using {command down, shift down}
                                delay 0.2

                                tell sheet 1 of window (myTitle)
                                    tell sheet 1
                                        -- dereference basePath
                                        local basePathStr
                                        set basePathStr to basepath & ""
                                        set value of first combo box to basePathStr
                                        delay 0.2
                                        click button "Öffnen"
                                        delay 0.2
                                    end tell
                                    click button "Sichern"
                                    set timeLeft to my waitForAppear(sheet 1, 3, 0.2)
                                    tell sheet 1
                                        if timeLeft > 0 then
                                            click button "Ersetzen"
                                        end if
                                    end tell
                                    delay 5
                                    keystroke "q" using {command down}
                                end tell

                            end tell
                        end if
                    end tell

                    --tell application "System Events"
                    --  set timeLeft to my waitForAppear("button", button "Sichern" of sheet 1 of sheet 1 of window 1 of process pp, 5, 0.5)
                    --  if timeLeft < 0 then
                    --      log "Sichern button didn't show up after 5 secs"
                    --      error number -128
                    --  end if
                    --  click button "Sichern" of sheet 1 of sheet 1 of window 1 of process pp
                    --end tell

                    --tell application "System Events"
                    --  delay 0.5
                    --  try
                    --      set timeLeft to my waitForAppear("button", button "Ersetzen" of sheet 1 of sheet 1 of sheet 1 of window 1 of process pp, 5, 0.5)
                    --      if timeLeft < 0 then
                    --          log "Ersetzen button didn't show up after 5 secs"
                    --          error number -128
                    --      end if
                    --      click button "Ersetzen" of sheet 1 of sheet 1 of sheet 1 of window 1 of process pp
                    --  end try
                    --end tell
                    log "done ..."
                    -- close filePath
                end if
            end if
        end repeat
        -- still in tell powerpoint context
        --tell application "System Events"
        --  delay 0.5
        --  try
        --      set timeLeft to my waitForVanish("window", window "Sichern" of process pp, 60, 1)
        --      if timeLeft < 0 then
        --          log "print dialog didn't vanish after 60 secs"
        --          error number -128
        --      end if
        --  end try
        --end tell
        quit
    end tell
end ppt2Pdf

on showElement(uiElem)
    local className
    set className to class of uiElem as string
    log (((«class pDSC» of uiElem as string) & "=" & value of uiElem as string) & "(" & className) & ")"
end showElement

--
-- show all UI elements
--
on showUiElements(appName, filterClassName)
    tell application "System Events"
        tell process appName
            tell (1st window whose value of attribute "AXMain" is true)
                repeat with uiElem in entire contents of it as list
                    try
                        local className
                        set className to class of uiElem as string
                        if filterClassName is missing value or className is filterClasssname then
                            log (((description of uiElem as string) & "=" & value of uiElem as string) & "(" & className) & ")"
                        end if
                    end try
                end repeat
            end tell
        end tell
    end tell
end showUiElements

--
-- wait for the given element to appear
--
on waitForAppearWindow(elementName, parentElement, time, slice)
    set timeLeft to time
    set appeared to false
    repeat until (appeared) or timeLeft  0
        try
            set appeared to window elementName of parentElement exists
        end try
        delay slice
        log "."
        set timeLeft to timeLeft - slice
    end repeat
    log timeLeft
    return timeLeft
end waitForAppearWindow

--
-- wait for the given element to appear
--
on waitForAppear(element, time, slice)
    set timeLeft to time
    set appeared to false
    repeat until (appeared) or timeLeft  0
        try
            set appeared to element exists
        end try
        delay slice
        log "."
        set timeLeft to timeLeft - slice
    end repeat
    log timeLeft
    return timeLeft
end waitForAppear

---
--- wait for the given element to vanish
---
on waitForVanish(element, time, slice)
    set timeLeft to time
    try
        repeat while (exists element) and timeLeft > 0
            delay slice
            log "."
            set timeLeft to timeLeft - slice
        end repeat
    end try
    log timeLeft
    return timeLeft
end waitForVanish

on chooseMenuButtonItem(appName, buttonName, itemName)
    tell application "System Events"
        tell process appName
            tell window 1
                local win1
                set win1 to it
                tell sheet 1
                    log "choosing " & itemName & " of menu button " & buttonName
                    tell menu button buttonName
                        click
                        delay 0.1
                        tell menu 1
                            click menu item itemName
                        end tell
                    end tell
                end tell
            end tell
        end tell
    end tell
end chooseMenuButtonItem
--
-- choose a popup 
--
on choosePopUp(appName, buttonName, itemName)
    tell application "System Events"
        tell process appName
            tell window 1
                tell sheet 1
                    log "choosing " & itemName & " of pop up menu " & buttonName
                    --repeat with pbutton in pop up buttons
                    --  local pbutton1
                    --  set pbutton1 to pbutton
                    --  log description of pbutton & "=" & value of pbutton
                    --end repeat
                    tell (1st pop up button whose description is buttonName)
                        click it
                        delay 0.5
                        pick menu item itemName of menu 1
                    end tell
                end tell
            end tell
        end tell
    end tell
end choosePopUp

--
-- https://developer.apple.com/library/archive/documentation/
-- LanguagesUtilities/Conceptual/MacAutomationScriptingGuide
-- AutomatetheUserInterface.html#//apple_ref/doc/uid/TP40016239-CH69-SW17
--
on chooseMenuItem(theAppName, theMenuName, theMenuItemName)
    try
        -- Bring the target app to the front
        tell application theAppName
            activate
        end tell

        -- Target the app
        tell application "System Events"
            tell process theAppName

                -- Target the menu bar
                tell menu bar 1

                    -- Target the menu by name
                    tell menu bar item theMenuName
                        tell menu theMenuName

                            -- Click the menu item
                            log "clicking " & theMenuItemName
                            click menu item theMenuItemName
                        end tell
                    end tell
                end tell
            end tell
        end tell
        return true
    on error
        return false
    end try
end chooseMenuItem

on makeNewPath(f)
    set t to f as string
    if t ends with ".pptx" or t ends with ".pptm" then
        return (text 1 thru -5 of t) & "pdf"
    else
        return (text 1 thru -4 of t) & "pdf"
    end if
end makeNewPath

1voto

talkingnews Puntos 42

Me temo que sólo es una respuesta a medias, ya que no tengo tiempo para depurar, pero creo que podría ser una solución interesante para futuras referencias.

  1. Instalar PowerShell para MacOS (Yo recomendaría utilizar Homebrew para ello).
  2. Consiga este script por el usuario de GitHub mp4096 para que funcione.

    Batch convert all .ppt/.pptx files encountered in folder and all its subfolders

    The produced PDF files are stored in the invocation folder

    #

    Adapted from http://stackoverflow.com/questions/16534292/basic-powershell-batch-convert-word-docx-to-pdf

    Thanks to MFT, takabanana, ComFreek

    #

    If PowerShell exits with an error, check if unsigned scripts are allowed in your system.

    You can allow them by calling PowerShell as an Administrator and typing

    ```

    Set-ExecutionPolicy Unrestricted

    ```

    Get invocation path

    $curr_path = Split-Path -parent $MyInvocation.MyCommand.Path

    Create a PowerPoint object

    $ppt_app = New-Object -ComObject PowerPoint.Application

    Get all objects of type .ppt? in $curr_path and its subfolders

    Get-ChildItem -Path $currpath -Recurse -Filter *.ppt? | ForEach-Object { Write-Host "Processing" $.FullName "..."

    Open it in PowerPoint

    $document = $ppt_app.Presentations.Open($_.FullName)
    # Create a name for the PDF document; they are stored in the invocation folder!
    # If you want them to be created locally in the folders containing the source PowerPoint file, replace $curr_path with $_.DirectoryName
    $pdf_filename = "$($curr_path)\$($_.BaseName).pdf"
    # Save as PDF -- 17 is the literal value of `wdFormatPDF`
    $opt= [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsPDF
    $document.SaveAs($pdf_filename, $opt)
    # Close PowerPoint file
    $document.Close()

    }

    Exit and release the PowerPoint object

    $ppt_app.Quit()

Al parecer, esto no se ejecuta fuera de la caja en MacOS. Pero algunos usuarios en los comentarios informan de que lo han hecho funcionar.

Si alguien consigue hacerlo funcionar, por favor, no dude en editar esta respuesta.

0 votos

Es maravilloso. Esperaba que la recompensa trajera algunos ojos frescos. Tener varias formas de exportar parece útil. Puede que intente una versión de pages / Automator si puedo hacer algo fácil de rodar.

AppleAyuda.com

AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X