/// <summary>
        /// Constructor. Demo Mode.
        /// </summary>
        /// <param name="userPC">user PC name</param>
        /// <param name="documentName">document name</param>
        /// <param name="pageCount">page count</param>
        /// <param name="colorPageCost">color page cost</param>
        /// <param name="blackAndWhitePageCost">black and white page cost</param>
        /// <param name="isColorDocument">is color document flag</param>
        /// <param name="printers">list of printers</param>
        public PrintingControlModel(string userPC, string documentName, int pageCount, int colorPageCost, int blackAndWhitePageCost, bool isColorDocument, Printers printers)
        {
            IsTestMode         = true;
            NumberOfPages      = pageCount;
            PostScriptMetaData = new PostScriptMetaData()
            {
                Title = documentName, NumberOfPages = pageCount, HasColor = isColorDocument
            };
            FileHasColor          = isColorDocument;
            UserPC                = userPC;
            ColorPageCost         = colorPageCost;
            BlackAndWhitePageCost = blackAndWhitePageCost;
            Printers              = printers;
            SelectedPrinterIndex  = 0;
            ChosenPrinter         = Printers[0];
            IsControlsEnabled     = true;

            demoPrinters = new Printers();
            foreach (var item in printers)
            {
                demoPrinters.Add(item);
            }
        }
        /// <summary>
        /// Gets Postscript Data.
        /// </summary>
        /// <param name="psFileName">postscript file</param>
        private void GetPSData(string psFileName)
        {
            LogHelper.LogDebug();

            // set status
            SetStatus("Get metadata");
            PostScriptMetaData = PostScriptHelper.GetData(psFileName);
            // check postscript data
            if (PostScriptMetaData != null)
            {
                PostScriptMetaData.HasColor = FileHasColor;

                if (Title != null)
                {
                    PostScriptMetaData.Title = Title.Document;
                }

                NumberOfPages = PostScriptMetaData.NumberOfPages;
            }
            else
            {
                NumberOfPages = -1;
            }
        }
Exemplo n.º 3
0
        /// Print
        #region Print

        /// <summary>
        /// Prints file with specified printer and settings
        /// </summary>
        /// <param name="fileName">file name</param>
        /// <param name="printer">printer settings</param>
        public static void Print(string fileName, string documentName, PrinterSettings printer, PostScriptMetaData data)
        {
            if (String.IsNullOrWhiteSpace(fileName))
            {
                return;
            }

            if (printer == null)
            {
                return;
            }

            if (data == null)
            {
                return;
            }

            try
            {
                // check the existence of the file
                if (!File.Exists(fileName))
                {
                    return;
                }

                // get file format
                SupportedPrintFormat format = GetFileFormat(fileName);
                string newFileName          = fileName;
                // if Postscript file
                if (format == SupportedPrintFormat.PS)
                {
                    newFileName = fileName + ".pdf";
                    // convert to .pdf
                    GhostScriptHelper.ConvertPStoPDF(fileName, newFileName);
                }

                // create corresponding print job title
                PrintJobTitle title = new PrintJobTitle(printer.PrinterName, documentName, Environment.UserName, Environment.MachineName, -1);

                // skip this title
                SkipMethod(title);

                // print document
                if (PDFHelper.Print(printer, newFileName, documentName, Environment.UserName, Environment.MachineName))
                {
                    // add title watcher
                    AddWatcher(title);

                    // log printed data
                    LogPrint(ConfigData.FilePath_PrintLog, documentName, printer, data.NumberOfPages);
                }
            }
            catch (Exception ex)
            {
                WPFNotifier.DebugError(ex);
            }
        }
        /// <summary>
        /// Prints file.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="printerName"></param>
        /// <param name="printerSettings"></param>
        private void Print(string fileName, string documentName, PrinterSettings printerSettings, PostScriptMetaData data)
        {
            // check if it's Demo mode
            if (IsTestMode)
            {
                return;
            }

            SetStatus("Printing");
            LogHelper.Log("Printing " + fileName + " (" + documentName + ") with " + printerSettings.PrinterName);
            PrintHelper.Print(fileName, documentName, printerSettings, data);
            LogHelper.LogDebug("Printing Completed");
            Close();
        }
Exemplo n.º 5
0
        /// GetData
        #region GetData

        /// <summary>
        /// Gets postscript file meta data
        /// </summary>
        /// <param name="fileName">file to be inspected</param>
        /// <returns>postscript file meta data</returns>
        public static PostScriptMetaData GetData(string fileName)
        {
            return(PostScriptMetaData.ReadFile(fileName));
        }
 /// <summary>
 /// Prints file
 /// </summary>
 /// <param name="fileName">file name</param>
 /// <param name="printerSettings">printer settings</param>
 private void Print(string fileName, string documentName, PrinterSettings printerSettings, PostScriptMetaData data)
 {
     SetStatus("Printing");
     PrintHelper.Print(fileName, documentName, printerSettings, data);
     Close();
 }