Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        /// HasColor
        #region HasColor

        /// <summary>
        /// Checks whether the postscript file has color inside
        /// </summary>
        /// <param name="psFileName">file to be inspected</param>
        /// <returns>true if colored; otherwise false</returns>
        public static bool?HasColor(string psFileName)
        {
            if (string.IsNullOrWhiteSpace(psFileName))
            {
                return(null);
            }

            LogHelper.LogDebug();

            try
            {
                if (!File.Exists(psFileName))
                {
                    return(null);
                }

                string pdfTMPFileName = Path.GetTempFileName() + ".pdf";

                // and convert PS file to PDF
                GhostScriptHelper.ConvertPStoPDF(psFileName, pdfTMPFileName);

                // find out do PDF has color or not?
                bool hasColor = GhostScriptHelper.HasColor(pdfTMPFileName);

                try
                {
                    File.Delete(pdfTMPFileName);
                }
                catch (Exception ex)
                {
                    LogHelper.Log(ex);
                }

                return(hasColor);
            }
            catch (Exception ex)
            {
                WPFNotifier.DebugError(ex);
                return(null);
            }
        }