Custom File Name Generation C++ Sample

 

Description:

·         GetCustomFilenameTemplate

·         IsCustomFilenameTemplateValid

·         SetCustomFilenameTemplate (for setting the custom file name dynamically)

This demonstration sample program will set the custom file name to IMG <<DOCNAME>>printedby <<USERNAME>>.<<ORIGINAL>>and indicate whether this template is valid or not. The sample can be compiled using Visual Studio 2005 using the appropriate project file.

 

How to Use the Sample:

1.    Open the Devices and Printers window.

 

On Windows 10/8/7 and Windows 2022/2019/2016:

Start > Settings > Devices > Devices and Printers

 

On Windows 11:

Start > Settings > Bluetooth & devices > Printers & scanners

 

2.    Find your previously installed Black Ice Printer Driver and right-click on it. Select Printing Preferences, select Filename Generation tab. In the Filename Generation Method section select Custom file naming from the dropdown list. Click OK button.

 

 

3.    Run the sample

4.    Print a document.

5.    Check the sample window for the text output.

 

 

6.    Check the output files of the printer driver for their filenames.

 

The custom filename template must be the following:

[prefix][optional_field1][custom_field][optional_field2].[extension]

 

[prefix] can be the following:

The prefix is a maximum 4 characters long string. Prefix can contain any characters, except invalid filename characters, such as ? or *. The prefix can be an empty string.

[optional_field1], [optional_field2] can be the following:

<<NONE>>

The optional field is not used.

<<DOCNAME>>

Name of the document. This name is came from the printing application.

<<PAGENUM>>

Actual page number. It uses zero padding for 4 characters, for example 0005.

<<USERNAME>>

Name of the current logged in user.

<<COMPUTER>>

The host name of the computer.

<<DATE>>

Actual system date when printing in format of system default.

<<TIME>>

Actual system time when printing in format of system default.

<<TIMEMS>>

Local time with millisecond accuracy.

<<COUNTER>>

Sequential document number in 7 digits format.
The counter <<COUNTER>> can be rest manually at the following registry location:

HKEY_CURRENT_USER\Software\Black Ice Software LLC\[Black Ice Pinter driver name]      (dword) LastDocNumber

[custom_field] can be the following:

Custom_field is a maximum 64 character long string. Custom_field can contain any characters, except invalid filename characters, such as ? or *.

[extension] can be the following:

<<ORIGINAL>>

In this case the extension is the original extension of the selected file format. For example if the selected file format is JPEG the extension of the printed image will be .jpg.

Exteinsion also can be a maximum 4 charater long string, such as PDF, TIFF. This field can be empty.

 

These are some examples for the template string:

 

AAA<<NONE>><<NONE>>.<<ORIGINAL>>

<<DATE>>_printed_<<TIME>>.jpg

IMG<<DOCNAME>>printedby<<USERNAME>>.<<ORIGINAL>>

 

Field explanations:

 

prefix

optional_field1

custom_field

optional_field2

.extension

Result example

AAA

<<NONE>>

 

<<NONE>>

.<<ORIGINAL>>

AAA.PDF

 

<<DATE>>

_printed_

<<TIME>>

.jpg

4-19-2017_printed_10-44-33 AM.PDF

IMG

<<DOCNAME>>

printedby

<<USERNAME>>

.<<ORIGINAL>>

IMGDocumentprintedbyJohn.PDF

 

Changing the Settings

Edit the INI file of Sample, calledSampleSettings.ini. The following option must be specified in the INI file:

[Printer Settings]

Printer Name=<Name of the Black Ice Printer>

Description of the settings:

Printer name: Fill in the name of the Black Ice printer to be used by the Sample (without ‘<’ and ‘>’)

Sample Source Code Folder Location:

<RTK Installation Folder>\<RTK 32/64 bit>\Samples\Sample Source Codes\C++\Custom Filename C++ Sample

 

Solution files

Compilers

Custom Filename C++ Sample_VS2015.sln

Visual Studio 2015

Custom Filename C++ Sample _VS2017.sln

Visual Studio 2017

Custom Filename C++ Sample _VS2019.sln

Visual Studio 2019

Custom Filename C++ Sample _VS2022.sln

Visual Studio 2022

 

Files needed for redistribution:

 

-   BlackIceDEVMODE.dll

-   blicectr.dll

-   INI file (Optionally change the printer name in the ini file):

-   SampleSettings.ini

 

Warning: You must copy the appropriate dll files to the project folder.

 

Note: Please make sure that you use the appropriate Resource ToolKit, there are two different RTKs.

- API/RTK for 32/64 bit Windows 11, 10, 8.1, 7

- API/RTK for 32/64 bit Windows Server 2022/2019/2016/2012

 

Using Message Capture and Printing from the Same Process

 

If you wish to extend the Message Capture samples with printing using AutoPrint, or otherwise combine message capture and printing in the same application, the printing thread must be separated from the message capture thread.

Printing and capturing messages from the same thread will result in lost

 

BLACKICE_MESSAGE_DEVMODE messages. Other messages may appear to work, but they will be delayed. This is because BLACKICE_MESSAGE_DEVMODE messages will wait for response and eventually time out, while other messages do not wait for response and are queued.