Consulting

Results 1 to 2 of 2

Thread: Printing from Word to FoxIt Pro

  1. #1
    VBAX Newbie
    Joined
    Dec 2012
    Posts
    2
    Location

    Unhappy Printing from Word to FoxIt Pro

    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.

  2. #2
    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 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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •