Skip to main content
Participant
July 27, 2012
Answered

Converting PDF to PNG

  • July 27, 2012
  • 2 replies
  • 5059 views

I wrote the following AppleScript to open a PDF file and export is as PNG.

I am using Illustrator CS5.

The export command gets an error: Adobe Illustrator got an error: Can't get current document.

when it encounters the export command.

What is causing this and how do I fix it?

set inputFile to (choose file with prompt "Open PDF file to convert to PNG:") as text

set exportFile to inputFile & ".png"

tell application "Adobe Illustrator"

    if not frontmost then activate

    open inputFile as alias without dialogs

    export current document to exportFile as PNG24 ¬

        with options {class:PNG24 export options ¬

        , resolution:300 ¬

        , matte color:{red:0, green:0, blue:0}}

    close current document saving no

end tell

This topic has been closed for replies.
Correct answer Muppet Mark

I tried your script and while the error kick back say's its a file/document issue… It's NOT you have supplied a bad parameter… resolution NO such thing except for PSD… Remove and you will be fine…

2 replies

Larry G. Schneider
Community Expert
Community Expert
July 29, 2012

You will have to scale the PNG larger and then batch reduce in Photoshop to get the resolution you want. AI thinks all PNGs are 72 ppi.

DVF2Author
Participant
July 30, 2012

Making the object larger worked to get the desired resolution. Thanks.

It appears that there is not way to script the options that appear on the PNG export dialog,

other than using something like UI Browser. For example I can not set the background

to white from transparent with the scripting options. Is this correct?

Larry G. Schneider
Community Expert
Community Expert
July 30, 2012

Set the transparency to false and the matte color to 255, 255, 255

Muppet MarkCorrect answer
Inspiring
July 28, 2012

I tried your script and while the error kick back say's its a file/document issue… It's NOT you have supplied a bad parameter… resolution NO such thing except for PSD… Remove and you will be fine…

DVF2Author
Participant
July 30, 2012

Thank you, that got me past one hurdle.