In this example, you will see how to convert an existing PDF document to a TIFF image. The principle shown in this example can be used to produce other types of files. It can easily be changed to produce JPEG, PNG, or BMP files.

The idea is that we use the PrintPdf method found in the utility class. This method is available in both the COM and Microsoft.NET assembly. It takes many parameters as you can see from the source code included below.

Before the PrintPdf method is called, the code creates a runonce.ini to control the printer. The settings in the runonce.ini controls the output format, file name, status file, and hides the dialogs. It also applies a sample watermark that shows the current date and time.

Before the print job is created, the old status file and output file are deleted. After the print job, the code will wait for a new status file to determine if the operation was a success or a failure.

    Option Explicit
    
    Dim pdfFileName, printerSelection, printToPrinterName
    Dim pdfPrinterName, showProgress, bitsPerPixel
    Dim documentName, maxResolution, scaleToFit
    Dim firstPage, lastPage, timeoutMilliseconds
    Dim currentdir, util, fso, settings
    Dim printername, statusfile, outFileName
    Dim resolution, device
    
    resolution = 300
    device = "tiff24nc"
    
    Rem -- Get current path of this script.
    Set fso = CreateObject("Scripting.FileSystemObject")
    currentdir = fso.GetAbsolutePathName(".")
    
    Rem -- Create the COM helper object.
    Set util = CreateObject("pdf7.PdfUtil")
    
    Rem -- Create the COM settings object to control the printer.
    set settings = CreateObject("pdf7.PdfSettings")
    
    printername = util.DefaultPrinterName
    pdfFileName = currentdir & "\test page.pdf"
    outFileName = currentdir & "\test page.tiff"
    
    Rem -- Set parameters for the conversion
    Rem -- Settings are documented at https://www.7-pdf.com/products/pdf-printer/documentation/settings
    statusfile = currentdir & "\status.ini"
    settings.PrinterName = printername
    settings.SetValue "Output", outFileName
    
    settings.SetValue "Device", device
    settings.SetValue "ResX", resolution
    settings.SetValue "ResY", resolution
    settings.SetValue "TextAlphaBits ", "4"
    settings.SetValue "GraphicsAlphaBits ", "4"
    
    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 to control the next print job.
    settings.WriteSettings True
    
    Rem -- Remove old output and status files
    if fso.FileExists(outFileName) then fso.DeleteFile(outFileName)
    if fso.FileExists(statusfile) then fso.DeleteFile(statusfile)
    
    Rem -- Send the PDF to the printer
    printerSelection = "specific"
    pdfPrinterName = printername
    printToPrinterName = printername
    showProgress = False
    bitsPerPixel = 24
    documentName = "Example"
    maxResolution = resolution
    scaleToFit = True
    firstPage = 0
    lastPage = 0
    timeoutMilliseconds = 30000
    util.PrintPdf pdfFileName, printerSelection, printToPrinterName, _
    	pdfPrinterName, showProgress, bitsPerPixel, documentName, _
    	maxResolution, scaleToFit, firstPage, lastPage, timeoutMilliseconds
    
    Rem -- Wait for the status file. 
    Rem -- The printing has finished when the status file is written.
    if util.WaitForFile(statusfile, 30000) then
    	wscript.echo "Print job finished."
    else
    	wscript.echo "Print job timed out."
    end if
    

You can download and run the example yourself. The file you needed are available here.

Downloads

Attachment Size
Example file 174.5 KB

Top