Unable to export Paged document as PDF. What is the reason?

I try to export Pages document as PDF, and for some reason the app says something is wrong:

tell front document of application "Pages"
	export to "Macintosh HD:Users:myName:Documents:xyz.pdf" as PDF
end tell

“Pages got an error: The document “test” could not be exported as “xyz”. Your most recent changes might be lost.” number 6

What is the problem there?

(I don’t know whether it is worth to mention, but this or apparently very similar code worked for me today. I tested it multiple times. But then it stopped to work. It seems I made some change that I haven’t even noticed…)

Tell Pages to export the document to a file. You’re telling it to export to a text string.

This works for me:

tell application "Pages"
	export front document to file "Macintosh HD:Users:myname:Documents:xyz.pdf" as PDF
end tell
2 Likes