Click here to Skip to main content
15,886,788 members
Articles / Programming Languages / Visual Basic

Automated PDF Conversion using the PDF995 and FreePDF_XP Freeware Printers

Rate me:
Please Sign up or sign in to vote.
4.67/5 (10 votes)
16 Oct 2008BSD7 min read 128.2K   3.1K   89  
An object oriented class automating the creation of PDF files from any file using freeware tools.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace CPDFPrinter
{
    //we want an abstract base class
    abstract class CPrinter
    {
        protected String _strFileToPrint = "";

        protected String strFileToPrint
        {
            get { return _strFileToPrint; }
            set {_strFileToPrint = value; }
        }

        //save original settings
        protected abstract void pushSettings();
        //restore original settings
        protected abstract void popSettings();
        //start printing process
        protected void printFile()
        {
            //Define properties for the print process
            ProcessStartInfo procStartInfo = null;

            if (File.Exists(_strFileToPrint))
            {
                procStartInfo = new ProcessStartInfo();
                procStartInfo.FileName = _strFileToPrint;
                procStartInfo.Verb = "Print";

                //Make process invisible
                procStartInfo.CreateNoWindow = true;
                procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                //start print process for the file with/from the associated application
                System.Diagnostics.Process procPrint = Process.Start(procStartInfo);
                //give the system some time
                System.Threading.Thread.Sleep(2500);

                if (procPrint.Handle != System.IntPtr.Zero)
                {
                    procPrint.WaitForExit();
                }

            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Software Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions