PDA

View Full Version : Printing from Word to FoxIt Pro



Phantek
12-04-2015, 09:10 AM
Okay, I am quite stuck on this issue. I have a macro that will automatically "print" a Word file to PDF (first by printing to .prn, and then by "distilling" to pdf). This has been working well.

Unfortunately, I now need to get this to work with FoxIt Pro, as Adobe Acrobat Pro is no longer an option (for unfortunate fiscal reasons).

Does anyone know how I can make that happen? I am able to call the print dialogue box, but I want it to print directly to PDF without the user's intervention. My Google searches have thus far not turned up any helpful insights on how to do this.

Thank you in advance for your assistance.

gmayor
12-05-2015, 01:51 AM
There is no reference to Foxit 'Pro' on the Foxit web site, and no indication that I can find Foxit software is programmable from VBA. If it is provided as a 'printer' driver you should be able to simply print to PDF by changing the active printer (see http://www.gmayor.com/fax_from_word.htm for programming suggestions) and print the document, but you may have to manually add the name.

One application that doesn't cost Acrobat prices and can be programmed from Word VBA is PDF Creator. I personally prefer the older version 1.7.3 (http://www.npackd.org/p/org.pdfforge.PDFCreator/1.7.3) which I find easier to work with. The following macro will create a PDF with the parameters declared

Option Explicit

Sub PrintToPDFCreator(sPDFName As String, _
sPDFPath As String, _
odoc As Document, _
Optional sMasterPass As String, _
Optional sUserPass As String, _
Optional bNoCopy As Boolean, _
Optional bNoPrint As Boolean, _
Optional bNoEdit As Boolean)
Dim pdfjob As Object
Dim sPrinter As String
Dim iCopy As Integer, iPrint As Integer, iEdit As Integer

If bNoCopy Then iCopy = 1 Else iCopy = 0
If bNoPrint Then iPrint = 1 Else iPrint = 0
If bNoEdit Then iEdit = 1 Else iEdit = 0

'Change active printer to PDFCreator
With Dialogs(wdDialogFilePrintSetup)
sPrinter = .Printer
.Printer = "PDFCreator"
.DoNotSetAsSysDefault = True
.Execute
End With

Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")

With pdfjob
If .cStart("/NoProcessingAtStartup") = False Then
GoTo err_Handler
End If

.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF

If Not sMasterPass = vbNullString Then

'The following are required to set security of any kind
.cOption("PDFUseSecurity") = 1
.cOption("PDFOwnerPass") = 1
.cOption("PDFOwnerPasswordString") = sMasterPass

'To set individual security options
.cOption("PDFDisallowCopy") = iCopy
.cOption("PDFDisallowModifyContents") = iEdit
.cOption("PDFDisallowPrinting") = iPrint

'To force a user to enter a password before opening
.cOption("PDFUserPass") = 1
.cOption("PDFUserPasswordString") = sUserPass
'To change to High encryption
.cOption("PDFHighEncryption") = 1
End If

.cClearCache
End With

'Print the document to PDF
odoc.PrintOut

'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False

'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
pdfjob.cClose
'Restore the original printer
With Dialogs(wdDialogFilePrintSetup)
.Printer = sPrinter
.Execute
End With
lbl_Exit:
Set pdfjob = Nothing
Exit Sub
err_Handler:
MsgBox "Unable to initialize PDFCreator." & vbCr & vbCr & _
"This may be an indication that the PDF application has become corrupted, " & _
"or its spooler blocked by AV software." & vbCr & vbCr & _
"Re-installing PDF Creator may restore normal working."
Resume lbl_Exit
End Sub