Controlling Distiller from VBA

B

Bill Bell

Are there an example on how to write out Word documents
with Distiller? I wrote up some code to do this and it
works if I single step through the code. I do not block
on distiller execution so running it in normal mode
causes file contention problems. I added sleep commands
but this does not work consistently.

I need to use Distiller and not PDFWriter since I need to
have password security.

Regards,
Bill Bell
 
M

Mark Tangard

Bill,

This is what has worked for me:

strPostScriptPrinter = "Acrobat Distiller"
strActivePrinter = ActivePrinter
ActivePrinter = strPostScriptPrinter
ActiveDocument.PrintOut
DoEvents
ActivePrinter = strActivePrinter
 
B

Bill Bell

This is what I was using. The thing that was causing me
problems is creating the PDF from the PS script file.
Since the PS process does not block the PDF process
creates file contention problems. I also think the
killing the ps file might create a problem. I would like
to know how to block the processes in order to avoid file
contention problems.

Dim xPDF As PdfDistiller

outFilePS = docName & ".ps"
outFilePDF = docName & ".pdf"
If Dir(outFilePS) <> "" Then Kill (outFilePS)
If Dir(outFilePDF) <> "" Then Kill (outFilePDF)
tDoc.Activate
curPrinter = Word.ActivePrinter ' Save
current printer
Word.ActivePrinter = "Acrobat Distiller"
tDoc.PrintOut copies:=1, PrintToFile:=True,
collate:=True,
OutputFileName:=outFilePS

' Causes problems.

Word.ActivePrinter = curPrinter ' Restore
current printer
xPDF.FileToPDF outFilePS, outFilePDF, ""
Kill outFilePS
Set xPDF = Nothing
Set tDoc = Nothing
 
U

Ulf Nilsson

Hi,

I want Distiller to always print to a specific directory
(c:\temp) and that the filename is always, without
prompt, the original filename + pdf?

/ Ulf
 
J

Jonathan West

Ulf Nilsson said:
Hi,

I want Distiller to always print to a specific directory
(c:\temp) and that the filename is always, without
prompt, the original filename + pdf?

Set the OutputFileName paramater of the Printout method to be the full
pathname of the file you want to create. In your case it would go something
like this

strPDF = "C:\temp\" & ActiveDocument.Name
strPDF = Left$(strPDF, InstrRev(strPDF, ".")) & "pdf"
ActiveDOcument.PrintOut PrintToFile:=True, OutputFileName:=strPDF

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
 
M

Mark Tangard

Jonathan,

When I've tried this, Acrobat always says the resulting file
can't be opened (is either not in PDF format or is corrupted).
This happens with the simplest test files so it can't be the
file itself. Any ideas? (I'd *really* like to be able to
point it to specific folders.)
 
M

Mark Baird

Will the following possibly work for you.

'Set refrences to Acrodist.exe and Acrobat.tlb

Dim strActivePrinter As String
Dim strFullName As String
Dim objDistiller As New PdfDistiller
Dim blnSuccessfull As Boolean
Dim strPDFName As String

Dim App As Acrobat.CAcroApp

Set App = CreateObject("AcroExch.App")
App.CloseAllDocs

'***Get the name of the active printer
strActivePrinter = ActivePrinter
strFullName = ActiveDocument.FullName
strPDFName = strFullName & ".pdf"
strFullName = Mid$(strFullName, 1, InStr(1,
strFullName, ".") - 1) & ".ps"

ActivePrinter = "Acrobat Distiller"

Application.PrintOut FileName:="",
Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="",
PageType:=wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True,
Background:=False, PrintToFile:= _
True, PrintZoomColumn:=0, PrintZoomRow:=0,
PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0,
OutputFileName:=strFullName, Append:=False

blnSuccessfull = objDistiller.FileToPDF(strFullName,
strPDFName, "ScreenOptimized")

App.CloseAllDocs

Set App = Nothing

Mark baird
 

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