• Contact
  • Company
  • Login / My Account
  • Shopping Cart (0)
Document Conversion Made Easy!
Peernet Menu
  • Products
      • Virtual Printers
        • tiff-image-printer-iconTIFF Image Printer – Create TIFF Images
        • raster-image-printer-iconRaster Image Printer – Create TIFF, PDF, JPEG, etc.
        • pdf-image-printer-iconPDF Image Printer – Create Searchable PDF
      • PDF Editor
        • pdf-creator-plus-iconPDF Creator Plus – Merge, Edit, Create Searchable PDF
      • Batch Converters
        • document-conversion-service-iconDocument Conversion Service – Unattended 24/7 Batch Converter
        • file-conversion-center-iconFile Conversion Center – Desktop Batch Converter
      • Reporting Software
        • peernet-reports-iconPEERNET Reports – Barcode, Report and Label Software
      • enterprise-licensingEnterprise Licensing for your Corporation
      • discounts-multiple-licensesDiscounts for Purchasing Multiple Licenses
      • distribute-bundle-peernet-softwareDistribute PEERNET Software Bundled with your Product
  • Purchase
      • Purchase Virtual Printers
        • tiff-image-printer-iconTIFF Image Printer – Create TIFF Images
        • raster-image-printer-iconRaster Image Printer – Create TIFF, PDF, JPEG etc.
        • pdf-image-printer-iconPDF Image Printer – Create Searchable PDF
      • Purchase PDF Editor
        • pdf-creator-plus-iconPDF Creator Plus – Merge, Edit, Create Searchable PDF
      • Purchase Batch Converters
        • document-conversion-service-iconDocument Conversion Service – Unattended 24/7 Batch Converter
        • file-conversion-center-iconFile Conversion Center – Desktop Batch Converter
      • Purchase Reporting Software
        • peernet-reports-iconPEERNET Reports – Barcode, Report and Label Software
      • peernet-online-store-purchase-optionsPurchase Options
      • peernet-software-license-levelsLicense Levels
      • peernet-software-purchase-resellerFind Resellers
      • peernet-software-sales-faqsSales FAQ
  • Learn & Support
        • peernet-help-centerTutorials
          • Learn the Basics or Go Beyond with Video Tutorials, FAQs and Guides

            At PEERNET we pride ourselves on providing the best support and the fastest response times in the industry.
          • Select Software Tutorials:
              • tiff-image-printer-iconTIFF Image Printer
              • raster-image-printer-iconRaster Image Printer
              • pdf-image-printer-iconPDF Image Printer
              • pdf-creator-plus-iconPDF Creator Plus
              • document-conversion-service-iconDocument Conversion Service
              • file-conversion-center-iconFile Conversion Center
              • peernet-reports-iconPEERNET Reports
        • peernet-software-faqsSales FAQ
          • Popular Topics

            Find all the answers you need to our most frequently asked questions.
              • Download & Install
                • How do I download software I already purchased?
              • Purchasing & Renewing
                • How do I purchase PEERNET software?
                • What license level do I need?
                • How do I add licenses to an existing serial number?
                • How do I renew my annual subscription?
              • Licensing & Operating
                • How do I activate my new PEERNET software?
                • How do I activate my software without an internet connection?
                • Where do I find my serial number?
                • How do I move my software to a new computer?
                • How do I update/upgrade my software to the latest release?
            • Read all Sales FAQs
  • Blog
  • Menu Menu

Control Output File Name and Location Using Print to File

April 7, 2022/by Robert Massart

The TIFF Image Printer, Raster Image Printer and PDF Image Printer have built-in support which allows Print to File to dynamically control the output file location and name when integrating printing to the Image Printers within your own programs and workflow. This technique works for scenarios where you only need to control the output folder and/or the output filename and are always creating the same type of output file.

You can use this method when writing Office automation code for Word, Excel, Publisher, PowerPoint and Visio; Outlook does not have this capability. This approach can be used in VBA macros and scripts, and anywhere else you can use Office automation.

Other applications with a COM interface for printing may support Print to File as well, the print method usually contains arguments to pass a full path as the desired output file name and optionally an argument to enable print to file or for WIN32 applications the DOCINFO structure in the StartDoc API can be used to specify the output file.

When using Print to File, the output name and location is set directly in your code as you print the document, allowing full control over the location and file name at the time of printing. Prompting is automatically suppressed and all other conversion settings for controlling the output file are taken from the Image Printer’s currently selected profile.

Below is a sample WORD VBA macro that that will print the currently open document to a specific folder and create a new generated file name each time. The directory is created if it does not exist as Print to File will fail on a missing directory. The file name is based on the document name and the current date and time.

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 currrent 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"
 
    ' Set the printer
    ActivePrinter = "TIFF 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

This is a simple example of using Print to File in a VBA macro. The same approach works in C++, .NET, PowerShell and other scripting languages. In this macro we dynamically generated the output file name from the document and using the current date and time. More advanced workflows where the document, output location and file name are pulled from a database, read from a job file on disk, or passed as arguments from a RESTFUL API or web service are just a few of the ways you can integrate printing to the Image Printers using this method.

Office Print to File Methods

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)

Included in the Image Printer 12 installation is a C# sample application demonstrating using Print to File from Word, Excel, PowerPoint, Publisher and Visio. Also included is a Word document containing the macro listed above. For more information on Print to File usage and where to find the program samples, see the user guide for your Image Printer.

Print to File TIFF Image Printer
Print to File Raster Image Printer
Print to File PDF Image Printer

https://www.peernet.com/wp-content/uploads/tutorial-post-automation-tif-ras-pdf.png 600 900 Robert Massart https://www.peernet.com/wp-content/uploads/peernet-logo.png Robert Massart2022-04-07 12:58:532023-10-26 13:51:05Control Output File Name and Location Using Print to File
  • Document Conversion Service
  • TIFF Image Printer
  • Raster Image Printer
  • PDF Image Printer
  • PDF Creator Plus
  • File Conversion Center
  • PEERNET Reports
Search Search

Recent Posts

  • PNSrv11Lib to PNSrv12Lib: Migration Made Easy
  • Migrating to Version 12: Compatibility Mode Quick Start Guide
  • Well Logs: Stitch PDF Pages into a Continuous TIFF Image
  • Dynamic Stamp Content
  • Convert to PDF: The Power of On-Premise PDF Creation

INTERESTING LINKS

Below are some interesting links for you! Enjoy your stay :)

RSS Feed Logo RSS Feed Logo Subscribeto RSS Feed

OUR PRODUCTS

  • Document Conversion Service
  • TIFF Image Printer
  • Raster Image Printer
  • PDF Image Printer
  • PDF Creator Plus
  • File Conversion Center
  • PEERNET Reports

LATEST NEWS

  • PNSrv11Lib to PNSrv12Lib: Migration Made EasyMarch 14, 2025 - 2:10 pm
  • Migrating to Version 12: Compatibility Mode Quick Start GuideMarch 14, 2025 - 2:09 pm
  • Well Logs: Stitch PDF Pages into a Continuous TIFF ImageMarch 14, 2025 - 2:08 pm
  • Dynamic Stamp ContentNovember 4, 2024 - 4:47 pm

BUSINESS INFORMATION

Toll Free: 1-800-883-7980 North America

Tel: 1-613-224-6894

Our office hours are Monday to Friday, from 0900 hrs to 1700 hrs, Eastern Standard Time.

Email Address: [email protected]
Copyright © 1997-2026. All rights reserved. Terms and Conditions | Disclaimer | Privacy Policy | Trademarks.
PEERNET® is a registered trademark of PEERNET Inc.
  • Link to Youtube
  • Link to Rss this site
  • Products
  • Purchase
  • Company
  • Contact
Link to: Share Settings Across Multiple Users Link to: Share Settings Across Multiple Users Share Settings Across Multiple Users Link to: Print Automation Using Script File Link to: Print Automation Using Script File Print Automation Using Script File
Scroll to top Scroll to top Scroll to top