Printer Setup

<< Click to Display Table of Contents >>

Navigation:  Programming Techniques > Printer Control >

Printer Setup

Previous pageReturn to chapter overviewNext page

VPE offers to display a printer properties dialog to your end-users. After the user has made his settings, you can store all settings persistently to file for permanent usage.

Your end-user may make individual printer-setups for each kind of document. So the user can not only specify an individual printer for each different type of document, but also the number of copies and collation, as well as all private driver settings. Just let him do these definitions in an extra part of your application (say: "Printer Setup") and store the different settings in different files. Use these settings later after a call to OpenDoc() by calling SetupPrinter() with a hidden dialog and the filename of the file where you had stored the desired settings.

Example:

The user selects the menu entry of your application for printer setup. You then need to open a document to have access to the printer setup method:

OpenDoc

SetupPrinter("my_setup.prs", PRINTDLG_ALWAYS)

CloseDoc

 

NOTE:Printer Setup files always should have the suffix ".PRS".

The call to SetupPrinter() above does the following: first, VPE tries to load the file "my_setup.prs". If it is found, the old settings are loaded and the appropriate dialog is shown. Otherwise a setup dialog for the default printer with default settings is shown - there, the user can select the printer he wants. The user can make his settings and after pushing the Ok-button, the settings are stored back to the file "my_setup.prs".

 

Whenever your application is later generating a document, you should execute the following code:

OpenDoc

SetupPrinter("my_setup.prs", PRINTDLG_ONFAIL)

CloseDoc

 

With the call to SetupPrinter(), VPE tries to load the file "my_setup.prs". If it is found, the old settings are loaded.

Only in case of a problem (e.g. VPE couldn't load the file, or there was a problem of loading the data into the device driver), the setup dialog will be shown.

There is also the property EnablePrintSetupDialog. If it is False, no setup dialog will be shown, when the user pushes the print button in the Preview.

NOTE: The settings of the printer setup do not influence the VPE document. For example the settings for the Paper Orientation or the Paper Size is independently of the settings for the document. But you can read a printer setup with the method ReadPrinterSetup() and retrieve all settings with the Device Control Properties. Afterwards you can set the properties of the VPE document (e.g. Paper Orientation, Paper Size) to the properties of the device.

 

NOTE:The setup files contain private device driver data. This has the big advantage that special settings, options and features of a specific printer can be set and stored to file (for example some printers offer to select an output paper bin, which is not known by the Windows API). But - because of the private driver data - if the user replaces the printer by another model (or manufacturer) or possibly if just the driver version is changed, the setup file needs to be deleted and newly created.

If you want to gain a driver independent format stored to file (accepting that specific properties of a printer are not supported), it is very simple to create your own file format by using the Device Control Properties and writing / reading them to / from file.

The following device properties are not stored in a VPE printer setup file for technical reasons:

DevFromPage

DevToPage

DevPrintToFile

DevFileName

DevJobName

 

The VPE Printer Setup File (.PRS) has the following format:

DWORD v30_flag;

// = (hex) 0xffffffff

DWORD Magic;

// = (hex) 0x38673042

DWORD Version;

// = 0 in VPE v3.0 and all higher versions

WORD  Platform;

// 0 = 16-Bit; 1 = 32 Bit; 2 = 64 Bit

WORD  Reserved;

// unused, should be NULL

DWORD Collate;

// 0 = no, 1 = yes

DWORD DevNameSize;

// size of the immediately following DEVNAMES structure, including its strings

 

DEVNAMES-Structure, which is:

* devnames-structure (see Windows SDK)

 + 3 zero-terminated strings

 * 1. string = Drivername (MSDOS filename)

 * 2. string = Devicename

 * 3. string = Output port

DWORD DevModeSize;

// size of the immediately following devmode-structure

 

Devmode-Structure (see Windows SDK),

including appended private Device-Driver Data.

The Devmode-Structure also contains the Landscape-flag in the field dmOrientation.