Have you ever wanted to automate printing using a command line or a batch file? Then this example might be something for you. It will show you how to control the PDF Writer from a batch file. This example will enable you to print a wide range of document types to PDF from the command line.

Using Microsoft Windows you can right click your documents and select print from the context menu. This behavior is supported by most of the common document types. Each document type has an associated program that will take care of the printing. These associations are set up in the computer's registry database. With this example you will be able to automatically print most of the documents, which support with the "print" option in the context menu.

Using Microsoft Windows you can right click your documents and select print from the context menu.

This behavior is supported by most of the common document types. Each document type has an associated program that will take care of the printing. These associations are set up in the computer's registry database. With this example you will be able to automatically print most of the documents, which support with the "print" option in the context menu.

  1. 7-PDF Command Line Print
  2.  
  3. USAGE:
  4.    printto "file name" ["printer name"]

With this tool on the system you can automate printing from the command line as shown in the example batch file below. Please note that this code example requires the system variable% LOCALAPPDATA%, which is already pre-assigned by the operating system as of Windows Vista. Under Windows XP, you still need to set this environment variable. A tutorial for this can be found here

  1. @ECHO OFF
  2.  
  3. @REM Set environment variables used by the batch file
  4. SET PRINTERNAME=7-PDF Printer
  5.  
  6. REM Create runonce.ini
  7. SET LAPP=%LOCALAPPDATA%
  8. IF "%LAPP%"=="" SET LAPP=%USERPROFILE%\Lokale Einstellungen\Anwendungsdaten
  9. SET RUNONCE=%LAPP%\PDF WRITER\%PRINTERNAME%\runonce.ini
  10. ECHO %RUNONCE%
  11. IF EXIST "%RUNONCE%" DEL "%RUNONCE%"
  12.  
  13. ECHO Save settings to "%RUNONCE%"
  14. ECHO [PDF Printer] >>  "%RUNONCE%"
  15. ECHO output=%CD%\out\demo.pdf >> "%RUNONCE%"
  16. ECHO author=Demo Script >> "%RUNONCE%"
  17. ECHO showsettings=never >> "%RUNONCE%"
  18. ECHO showpdf=no >> "%RUNONCE%"
  19. ECHO watermarktext=Batch Demo >>  "%RUNONCE%"
  20. ECHO confirmoverwrite=no >>  "%RUNONCE%"
  21. printto.exe "in\example.rtf" "%PRINTERNAME%"
  22. ECHO ERRORLEVEL=%ERRORLEVEL%

The code will print the example.rtf file to the PDF Writer and save the result as demo.pdf.

Download Example Files

You can download and run the example yourself. The files you need for this are included. Please note - required environment variables, which the sample code requires, should be set correctly before this example is executable. For information about the appropriate storage path configuration file, see here.

Downloads

Attachment Size
Example file 13.32 KB

LiveZilla Live Chat Software
Top