• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Appscript, Word and PDF
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Appscript, Word and PDF


  • Subject: Appscript, Word and PDF
  • From: richard brosnahan <email@hidden>
  • Date: Mon, 28 Aug 2006 13:47:14 -0400

The announcement of the new version of appscript reminded me of some work I did recently to script the conversion of microsoft word docs to PDFs. I used appscript to accomplish this task because I'm a big fan of Python, plus python fits better into what I ultimately need to do.

In any case, my solution works very well, tho it took me awhile to get there.

To convert Word docs to PDF, thru scripting, I first installed cups- pdf. This nice utility is open source, and it creates a virtual printer. this gets around the problem of doing UI scripting in the print dialog. UI scripting for me, has been problematic. Once installed, you can just tell word to print to that printer, and there are no dialog dismissals nessa.
http://www.codepoetry.net/projects/cups-pdf-for-mosx


Next, I downloaded appscript, installed it, and read the documentation. The syntax for appscript is rather odd, compared to applescript, but makes sense. I had to read the docs thoroughly before I understood.
http://appscript.sourceforge.net/index.html


Then I scripted.

#! /usr/local/bin/python

from appscript import *
def print2pdf(theDocPath):
  word = app("Microsoft Word")
  word.launch()
  word.active_printer = u'PDF_Virtual_Printer'
  theDoc = word.open(theDocPath)
  word.print_out(theDocPath)
  word.documents[1].close(saving = k.no)

print2pdf("Big Disk:Documents:aWordDocument.doc")


theDocPath is a string describing the path to the document you want to print. It is : delimited, not / delimited. the active_printer should be set to what you called your virtual printer.


One could translate this to pure AppleScript if they needed.

Thought this might be useful.

BTW, I really like appscript. Many thanks to those who have worked on this terrific utility.

--
Richard Brosnahan
Owner
Engineering Art, L.L.C
email@hidden
M 804.304.6880

Talent hits a target no one else can hit; Genius hits a target no one else can see.
Arthur Schopenhauer




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: A few questions about dates
  • Next by Date: Re: A few questions about dates
  • Previous by thread: Re: Dialog from script application displays raw codes
  • Next by thread: XML Suite in System Events
  • Index(es):
    • Date
    • Thread