Resetting PDFCreator Options via Code

This article contains code examples to reset some (but not all) of the default settings of PDFCreator.

These code examples are built for PDFCreator, an open source PDF writer utility. Unlike Adobe Acrobat and CutePDF, which both require pro versions to create PDF's via code, PDFCreator is completely free! Download PDF Creator from Sourceforge here. Please note that this code will NOT work with Adobe Acrobat.

It should be noted that each of the examples in this section use an Early Bind. If you are not familiar with the difference between Early and Late Binding, please read our article on Early vs Late binding.

Routines Included In This Article:

  • Reset PDFCreator's Default Settings
  • List PDFCreator's Default Values

Versions Tested:
These routines were tested successfully using PDFCreator 0.9.1, GPLGhostscript.exe download package, on Windows XP Pro (SP2). Excel versions tested include:

  • Excel 2003
  • Excel 2007

NOTE: Before you "go it alone" with trying to adapt any of these routines, you may want to read this article, which shares some of the idiosyncrasies discovered in the development of the PDFCreator code samples.

Reset PDFCreator's Default Settings:
The following routine is intended to reset PDFCreator's default values via code. The routine does not reset all the default values, but rather the ones that I've changed most commonly and in examples on the site. My thought is that if you can figure out how to change different settings via code, you can figure out how to add them to this routine. As time goes on, I may add the rest, but I think that this is probably enough to do what 99% of users will need to do.

This code, as written, is intended to go in a standard module, and could be called from a button, or a Workbook_Open event, if so required/desired.

Code:
Sub RestoreDefaults()
'Author       : Ken Puls (www.excelguru.ca)
'Macro Purpose: Reset the PDFCreator seetings to their default values

    Dim objPDF As New PDFCreator.clsPDFCreator

    With objPDF
        If .cStart("/NoProcessingAtStartup") = False Then
            MsgBox "Can't initialize PDFCreator.", vbCritical + _
                    vbOKOnly, "PrtPDFCreator"
            Exit Sub
        End If
        
        'Set Values
        .cOption("UseAutosave") = 0
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = ""
        .cOption("AutosaveFilename") = ""
        .cOption("AutosaveFormat") = 0
        .cOption("UseCreationdate") = vbNullString
        .cOption("UseStandardAuthor") = 0
        .cOption("PDFUseSecurity") = 0
        .cOption("PDFUserPass") = 0
        .cOption("PDFUserPassString") = vbNullString
        .cOption("PDFOwnerPass") = 1
        .cOption("PDFOwnerPassString") = vbNullString
        .cOption("PDFEncryptor") = 0
        .cOption("PDFDisallowCopy") = 1
        .cOption("PDFDisallowPrinting") = 0
        .cOption("PDFDisallowModifyContents") = 0
        .cOption("PDFDisallowModifyAnnotations") = 0
        .cOption("PrinterTempPath") = "PDFCreator"
        
        'Save Values
        .cSaveOptions
    End With
    Set objPDF = Nothing
End Sub

List PDFCreator's Default Values:
The code below (which also is intended for a standard module), was used in the development of the above. I thought I'd share it for the sole reason that it makes it a bit easier to work out what defaut values are, and prints the .cOption line you need directly to the immediate window. Having said that, you do need to wrap outputted text in quotes, and fill vbNullstring in for blank values, but hopefully it helps someone.

The method to use it is as follows:

  • Open the PDFCreator Control panel: StartAll ProgramsPDFCreatorPDFCreator
  • From the Printer menu, choose Options
  • Click the "Reset All Settings" box, and then Save
  • Exit the PDFCreator Control panel
  • Modify the code to add any other properties as per the object browser
  • Run the code to see what your default values are
  • Integrate the string printed to the immediate window into the Reset routine above

Code:
Sub ListDefaults()
'Author       : Ken Puls (www.excelguru.ca)
'Macro Purpose: List PDFCreator defaults in Immediate window
    Dim objPDF As New PDFCreator.clsPDFCreator
    
    With objPDF
        If .cStart("/NoProcessingAtStartup") = False Then
            MsgBox "Can't initialize PDFCreator.", vbCritical + _
                    vbOKOnly, "PrtPDFCreator"
            Exit Sub
        End If
        
        'Determine Values
        Debug.Print ".cOption(""UseAutosave"") = " & .cOption("UseAutosave")
        Debug.Print ".cOption(""UseAutosaveDirectory"") = " & .cOption("UseAutosaveDirectory")
        Debug.Print ".cOption(""AutosaveDirectory"") = " & .cOption("AutosaveDirectory")
        Debug.Print ".cOption(""AutosaveFilename"") = " & .cOption("AutosaveFilename")
        Debug.Print ".cOption(""AutosaveFormat"") = " & .cOption("AutosaveFormat")
        Debug.Print ".cOption(""UseCreationdate"") = " & .cOption("UseCreationdate")
        Debug.Print ".cOption(""UseStandardAuthor"") = " & .cOption("UseStandardAuthor")
        Debug.Print ".cOption(""PDFUseSecurity"") = " & .cOption("PDFUseSecurity")
        Debug.Print ".cOption(""PDFUserPass"") = " & .cOption("PDFUserPass")
        Debug.Print ".cOption(""PDFUserPassString"") = " & .cOption("PDFUserPassString")
        Debug.Print ".cOption(""PDFOwnerPass"") = " & .cOption("PDFOwnerPass")
        Debug.Print ".cOption(""PDFOwnerPassString"") = " & .cOption("PDFOwnerPassString")
        Debug.Print ".cOption(""PDFEncryptor"") = " & .cOption("PDFEncryptor")
        Debug.Print ".cOption(""PDFDisallowCopy"") = " & .cOption("PDFDisallowCopy")
        Debug.Print ".cOption(""PDFDisallowPrinting"") = " & .cOption("PDFDisallowPrinting")
        Debug.Print ".cOption(""PDFDisallowModifyContents"") = " & .cOption("PDFDisallowModifyContents")
        Debug.Print ".cOption(""PDFDisallowModifyAnnotations"") = " & .cOption("PDFDisallowModifyAnnotations")
        Debug.Print ".cOption(""PrinterTempPath"") = " & .cOption("PrinterTempPath")
    End With
    Set objPDF = Nothing
End Sub

Thanks
Just a quick little note of thanks to the person who emailed me to point out that I had failed to see the .cSaveOptions method in the object browser!

Share:

Facebook
Twitter
LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Posts