Components for Developers
© 2000-2017, Two Pilots

PDF Library   EMF2PDF SDK Pilot   Virtual Printers   HTML2PDF-X Pilot   Converters   PDF Mosaic  
Home Download Pricing FAQ Support How to... Documentation Tutorials Languages Testimonials History

How to create Virtual Printer using: C++ | C# | Delphi | VB.NET | VB 

Virtual Printer Tutorials: Print Previewer

 

In this tutorial we create a Print Previewer application. This application will read data from an INI file and output it into a form. It will also display the EMF files generated by the virtual printer:

Print Previewer for Virtual Printer

In the right-hand part of the form, there is a ListBox with detailed information about the printer's work. The list shows the printed files. By clicking an EMF file, we make it appear in the form. If we double-click at the preview window, the EMF files previewer (installed on your computer) will come into play.

 

Recommendations for writing the application in C#

If you use C# or VB.NET (or any other .NET language), you will never find a function to manipulate INI files. The only way is to use the Windows API function GetPrivateProfileString.

Here is the code in C#:

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace Ini
{
    public class IniFile
    {
        public string m_sIniFilePath;

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString
		(string section,  string key, string val, string sIniFilePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString
		(string section, string key,  string def, StringBuilder retVal, int size, string sIniFilePath);

        public IniFile(string sIniFilePath)
        { 
            m_ sIniFilePath = sIniFilePath; 
        }

        public void IniWriteValue(string Section, string Key, string Value)
        { 
            WritePrivateProfileString(Section, Key, Value,  m_ sIniFilePath); 
        }

        public string IniReadValue(string Section, string Key, string Default)
        {
            StringBuilder temp = new StringBuilder(255);
            GetPrivateProfileString(Section, Key, "", temp, 1024, m_ sIniFilePath);
            return (temp.Length>0) ? temp.ToString() : Default;
        }
    }
}

INI files contain a lot of parameters. We will turn them and the reading function into a class. In the class IniFile, we will keep all data from the INI file (printer name, page orientation, resolution, number of printed pages, EMF files paths, etc.). To fill the ListBox, we will use an instance of the class DocumentProperties. An object of the class contains an instance of IniFile, used to manipulate the INI file, obtained from the command line:

DocumentProperties m_docProps = new DocumentProperties();
...
// Parse .ini file
if (m_docProps.Retrieve(m_commandLine) == true)
{
    // Fill ListBox
}

Then we may use an instance of DocumentProperties anywhere in our application, to get information about the printed document. For instance, here is how to display an EMF file inside a form, with a help of the PictureBox control:

pictureBox.Image = Image.FromFile(m_docProps.Files[pageNumber]);

 

Download Print Previewer:
Virtual Printer for C++/MFC
Virtual Printer for Delphi
Virtual Printer for C#
Virtual Printer for VB.Net
Virtual Printer for few languages

How to create Virtual Printer using: C++ | C# | Delphi | VB.NET | VB 

Home Download Pricing FAQ Support How to... Documentation Tutorials Languages Testimonials History

 

PDF Library | EMF2PDF SDK Pilot | Virtual Printers
HTML2PDF-X Pilot | Converters | PDF Mosaic

Support | Blog
Contact | About | Site map

© 2000-2017, Two Pilots