Print folder as PDF

R

Roger Morris

I want to print several folders of Word docs (hundreds) as pdf docs, one
word doc to one pdf doc.

To start I thought to try just one and add repeat loop(s) later.
But Word doesn't understand even this very simple applescript!
Can anyone tell me how to make it work please?

tell application "Microsoft Word"
print out active document output file name "xx.pdf" with print to file
end tell

at an even more basic level, the line
print out active document
does create a print

(I could work from a vba example/hint if that is available)
Working with MacOS 11.4.2 and M'soft Office 11.1
 
J

John McGhie [MVP - Word and Word Macintosh]

I Hope Paul will be along to save my AppleScript bacon soon :)

As far as I can see, you have not "Opened" the document. If you don't open
it, it's not "Active" and you will get zilch.

OK, here it is in VBA. This works... The example in the Help is wrong...
The following macro will print out every document in the directory set with
the ChDir statement.

This is very confusing syntax. Note that the Dir statement the first time
requires an empty string (³²) to cause it to list all documents in the
directory and return the first one. Within the While loop, it requires a
Null string () to return the ³Next² item in the list. The MacID for Word 97
and later is as shown.

Just how you are going to get it to print to file as PDF I am not sure. The
PrintToFile:=True, OutputFileName:="PrintFile" parameters produce a runtime
error under OS X. Can you set your PDF printer as the Default Printer?

Sub DirPrint()

ChDir "Macintosh HD:Users:John:Documents:MVP"
aDoc = Dir((""), MacID("W8BN"))

While aDoc <> ""
Application.PrintOut FileName:=aDoc
aDoc = Dir()
Wend

End Sub

I want to print several folders of Word docs (hundreds) as pdf docs, one
word doc to one pdf doc.

To start I thought to try just one and add repeat loop(s) later.
But Word doesn't understand even this very simple applescript!
Can anyone tell me how to make it work please?

tell application "Microsoft Word"
print out active document output file name "xx.pdf" with print to file
end tell

at an even more basic level, the line
print out active document
does create a print

(I could work from a vba example/hint if that is available)
Working with MacOS 11.4.2 and M'soft Office 11.1

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
R

Roger Morris

Thanks John.

In my *very* simple trial the document was already open on the desktop
and did print with the second (even simpler) 2nd script in my post.

Thanks for the VBA, I'm sure I can work out some applescript from that.

The big problem is still getting to the PDF buttons via a script. I am
wondering whether 'print' to PDF is an Apple thing rather than a Word
thing.

"PDF Printer" - ? I don't know anything about that. I have only one
printer in my printer lists. Must do some more studying.

Roger
 
J

John McGhie [MVP - Word and Word Macintosh]

Sorry: My bad. I was assuming you had Adobe Acrobat installed. If you do,
it will configure a PDF Writer as a "Printer" named Adobe PDF.

Cheers


Thanks John.

In my *very* simple trial the document was already open on the desktop
and did print with the second (even simpler) 2nd script in my post.

Thanks for the VBA, I'm sure I can work out some applescript from that.

The big problem is still getting to the PDF buttons via a script. I am
wondering whether 'print' to PDF is an Apple thing rather than a Word
thing.

"PDF Printer" - ? I don't know anything about that. I have only one
printer in my printer lists. Must do some more studying.

Roger

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
R

Roger Morris

originally:
[earlier posts snipped]

The Print - PDF - Save as PDF route seems not to be available to
Applescript but I have found a satisfactory way (for me) to do it.

On 16 Sept 2004 in this group Paul Berkowitz posted an applescript
"Applescript to combine several .doc files"

I have modified this script slightly to insert a page break after each
file is inserted.

The significant part of the script is

tell application "Microsoft Word"
set comboRange to text object of comboDoc
set collapsedRange to collapse range comboRange direction
collapse end
insert file file name filePath at collapsedRange
end tell

just before the "end tell" I inserted:

set newRange to text object of comboDoc
set endofRange to collapse range newRange direction collapse end
insert break at endofRange break type page break

On running, the script successfully produces a single Word document
comprising all those dragged to the script application.

Then, Print - PDF - Save as PDF produces a single .pdf with each new
'document' starting on a new page. Not quite what I set out to do (one
doc to one pdf) but now I think the result of many docs into one pdf is
even better for my purposes.

I combined each folder (of between 10 and 50 .docs) into one PDF and as
each .doc is only a few pages long each combined document is still
easily manageable. It's a bit slow but a lot quicker and certainly less
tedious than opening each word doc separately to print - pdf or than
doing a lot of "insert file" commands.
 
D

Daiya Mitchell

The big problem is still getting to the PDF buttons via a script. I am
wondering whether 'print' to PDF is an Apple thing rather than a Word
thing.

I haven't a clue how the applescript works, and see you solved it anyhow,
but this is exactly right. Print to PDF is an OS function. Word does not
create PDFs. You can use print, print as PDF from any program.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top