biopdf logo

COM Automation from Visual Basic Scripting

This example will show you how to create a simple VBScript that will control the PDF Writer. The script creates a runonce file and launches a print job that consumes the runonce settings.

A document named example.rtf is printed in this example. This example works with any type of file that has an application associated with it for printing. Most of the time you can recognize these files by the print option in the context menu when you right click the file in the Windows file explorer.

Download example Source Files  

Source Code

Rem -- This example will show you how to create a very simple runonce configuration.
Option Explicit

Dim printername
Dim output, statusfile, fso, currentdir, documentfile, util, settings

Rem -- Create the COM helper object.
set util = CreateObject("biopdf.PdfUtil")

Rem -- Create the COM settings object to control the printer.
set settings = CreateObject("biopdf.PdfSettings")

Rem -- Get current path of this script.
Set fso = CreateObject("Scripting.FileSystemObject")
currentdir = fso.GetAbsolutePathName(".")

output = currentdir & "\out\example.pdf"
statusfile = currentdir & "\out\status.ini"
documentfile = currentdir & "\in\example.rtf"

Rem -- Change the value of printer name if you want to use another PDF printer
printername = util.DefaultPrinterName

settings.PrinterName = printername
settings.SetValue "Output", output
settings.SetValue "WatermarkText", Now
settings.SetValue "WatermarkColor", "#FF9900"
settings.SetValue "ShowSettings", "never"
settings.SetValue "ShowPDF", "no"
settings.SetValue "ShowProgress", "no"
settings.SetValue "ShowProgressFinished", "no"
settings.SetValue "ConfirmOverwrite", "no"
settings.SetValue "StatusFile", statusfile
settings.SetValue "StatusFileEncoding", "unicode"

Rem -- Write settings to the runonce.ini.
settings.WriteSettings True

Rem -- Remove old output and status files
if fso.FileExists(output) then fso.DeleteFile(output)
if fso.FileExists(statusfile) then fso.DeleteFile(statusfile)

Rem -- Print the file
util.PrintFile documentfile, printername

Rem -- Wait for the status file.
Rem -- The printing has finished when the status file is written.
if util.WaitForFile(statusfile, 10000) then
	wscript.echo "Print job finished."
else
	wscript.echo "Print job timed out."
end if


 
McAfee SiteAdvisor Norton Safe Web