Save/Export a Specific Sheet Within a Numbers Spreadsheet as a PDF to the Desktop

I'm looking to create an Automator workflow using AppleScript that'll take a specific sheet with an a Numbers document and save it as a PDF to the Desktop. I have a script I've been working on but it keeps throwing an error. The error that it generates is:


Error: Numbers got an error: Invalid key form.


The Automator workflow I'm working on is this mess:


on run {input, parameters}


tell application "Numbers"


-- Check if a document is open


if not (exists document 1) then


display dialog "No Numbers document is open." buttons {"OK"} default button "OK"


return


end if


-- Get the active document and its name


-- The display dialogs are simply there as visual checks along the way


set currentDocument to document 1


set activeSheet to sheet 1 of currentDocument


set documentName to name of currentDocument


display dialog documentName


set documentNameWithoutExtension to my removeExtension(documentName)


display dialog documentNameWithoutExtension


-- Define the export path (The Desktop in this case)


set exportPath to (path to desktop folder as text) & documentNameWithoutExtension & " P1.pdf"


display dialog exportPath


-- Export the active sheet as PDF


try


tell currentDocument


display dialog "It's gotten this far"


-- The error occurs on the next like when attempting the export


-- The below line generates: "Error: Numbers got an error: Invalid key form."


export activeSheet to file exportPath as PDF with properties {image quality:Best}


end tell


display dialog "PDF saved successfully to Desktop!" buttons {"OK"} default button "OK"


on error errMsg


display dialog "Error: " & errMsg buttons {"OK"} default button "OK"


end try


end tell


end run



-- Function to strip away the file extension so it can be used in the PDF file name


on removeExtension(fName)


if fName contains "." then


set AppleScript's text item delimiters to "."


set fNameWithoutExtension to (text items 1 thru -2 of fName) as text


set AppleScript's text item delimiters to ""


return fNameWithoutExtension


else


return fName


end if


end removeExtension



Any help in eliminating the error would be greatly appreciated.

I have two systems. One is running macOS Sequoia 15.7.1 and an older system running Catalina 10.15.7


Posted on Oct 11, 2025 1:13 PM

Reply
4 replies

Oct 11, 2025 5:20 PM in response to Ed M.

I believe the issue is that the "export" command can only export a document, not a sheet.


What don't you use the Print functionality built-in in Numbers? Select your sheet, click File > Print, make sure "This sheet" is selected (bottom right), click the Print button (bottom right), click the dropdown "PDF" (bottom left), choose Save as PDF and choose the Desktop as destination.

Oct 11, 2025 5:50 PM in response to Ed M.

I haven't tried myself but you could try to record those manual steps in Automator. (use the Record button in the toolbar.)


This solution is not as robust as an AppleScript script and you may have to create two recordings (one for macOS Sequoia, the other for macOS Catalina) as I'm not sure the versions of Numbers are the same and the location of the buttons you click might be different.

Oct 11, 2025 9:21 PM in response to Ed M.

If you have to do this often and you don't want to mess around with gui-scripting you could consider installing a virtual pdf printer (such as CUPS-PDF via brew install cups -pdf) and use 'print' instead of 'export' in your script, something like this:


on printSheet(shtName, pdfPath)
    tell application "Numbers"
        tell front document
            set active sheet to sheet shtName
            print with properties {target printer:"CUPS-PDF"}
        end tell
    end tell
end printSheet

-- usage: 
set pdfPath to (path to desktop as text) & "Sheet1.pdf"
printSheet("Sheet 1", pdfPath)




Save/Export a Specific Sheet Within a Numbers Spreadsheet as a PDF to the Desktop

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