Please enable JavaScript to view this site.

PDF Image Printer

Navigation: Automating the Printing Process

Print to File to Control Output Name and Location

Scroll Prev Top Next More

When writing automation code as part of integrating printing with PDF Image Printer in custom programs and workflows, the built-in Print to File capability when printing offers a quick way to dynamically control the output name and location of the created file while automatically suppressing prompting. All other conversion settings to control the output file type are determined by the profile selected on the PDF Image Printer 12 printer when printing.

Office Print to File Methods

Word VBA Macro

C# Sample

Office Print to File Methods

The Office products, Word, Excel, PowerPoint, Publisher and Visio have this capability, Outlook does not. This technique can be used in VBA macros and scripts, and anywhere else you can automate the Office products.  Other applications that have a COM interface for automation and printing may also support this. Look for arguments similar to PrintToFile and OutputFileName as part of the print method.

In Word, Excel and Visio, the PrintToFile argument needs to be set to true as well as passing the full path to the desired output file in a separate argument. For Publisher and PowerPoint, supplying the full path in the PrintToFile argument is all that is needed.

Word

Document.PrintOut(Background, Append, Range, OutputFileName, From, To, Item, Copies, Pages, PageType, PrintToFile, Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint, PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight)

Excel

Workbook.PrintOutEx(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, IgnorePrintAreas)

PowerPoint

Presentation.PrintOut(From, To, PrintToFile, Copies, Collate)

Publisher

Document.PrintOutEx(From, To, PrintToFile, Copies, Collate, PrintStyle)

Visio

Document.PrintOut(PrintRange, FromPage, ToPage, ScaleCurrentViewToPaper, PrinterName, PrintToFile, OutputFileName, Copies, Collate, ColorAsBlack)

 

Word VBA Macro

The Word VBA macro below prints the currently open document to the PDF Image Printer printer and saves it to the folder C:\AutoPrint\ with the name MacroTest.pdf.

The output folder needs to exists or the macro will fail.  The output file is overwritten each time the macro is run. All other settings used to create the file are taken from the profile set on the printer.

This macro is also included in the sample Word file, PDF Image Printer VBA MACRO.docm  in the COMSamples\VBA Macro folder of the installation folder. This is usually C:\Program Files\PDF Image Printer 12\COMSamples\.

This same type of macro can be created from any Office application that supports macros.

 

Sub PrintToFile()
'
' PrintToFile Macro
' Prints the open Word document to the PDF Image Printer  with custom location and no prompting
'
    
    ' Get base document name for output
    Dim documentName As String
    Dim baseDocumentName As String
    documentName = ThisDocument.Name
    If InStrRev(documentName, ".") > 0 Then
        baseDocumentName = Left(documentName, InStrRev(documentName, ".") - 1)
    End If
    
    ' Create the directory if needed
    Dim outputDir As String
    Dim outputDirExists As String
    outputDir = "C:\PEERNETPrintToFile\"
    outputDirExists = Dir(outputDir, vbDirectory)
    If outputDirExists = "" Then
        MkDir (outputDir)
    End If
    
    ' Get current date/time for file name
    Dim datetimeStr As String
    datetimeStr = Format(Now(), "MM-DD-YYYY-hh-nn-ss")
    
    ' Create the file name. Print to File requires the full path, including
    ' the file extension of the output file you are creating
    Dim outputFileName As String
    outputFileName = outputDir & baseDocumentName & "-" & datetimeStr & ".tif"".pdf"".jpg"
 
    ' Set the printer
    ActivePrinter = "PDF Image Printer 12"
    
    ' Print the document
    Application.PrintOut PrintToFile:=True, outputFileName:=outputFileName, _
        FileName:="", Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
        wdPrintAllPages, Collate:=True, Background:=False, _
        PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
        PrintZoomPaperHeight:=0
End Sub

C# Sample

A sample C# application is provided as part of the install to demonstrate using this in your own programs. This sample shows using the Print to File technique using each of the supported Office applications. The sample includes references to the Office 2016 products Word, Excel, PowerPoint, Publisher and Visio to automate printing to the PDF Image Printer printer. If you have a different version of Office installed, you will need to update the references in order to build and run the samples.

The sample, PrintToFile, can be found in the COMSamples folder of the installation folder. This is usually C:\Program Files\PDF Image Printer 12\COMSamples\.

A pre-built demo of the sample is available in a \Demo folder under the project.