/// HasColor #region HasColor /// <summary> /// Indicates whether specified file has color or not. Has to be supported file (ps or pdf) /// </summary> /// <param name="fileName">file name</param> /// <returns>true if has color; otherwise false</returns> public static bool?HasColor(string fileName) { if (String.IsNullOrWhiteSpace(fileName)) { return(null); } try { if (!File.Exists(fileName)) { return(null); } SupportedPrintFormat format = GetFileFormat(fileName); if (format == SupportedPrintFormat.PDF) { return(GhostScriptHelper.HasColor(fileName)); } else if (format == SupportedPrintFormat.PS) { return(PostScriptHelper.HasColor(fileName)); } } catch (Exception ex) { WPFNotifier.Error(ex); } return(null); }
/// 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); } }
/// 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); } }
public static bool HasColor(string fileName) { LogHelper.LogDebug(fileName); return(GhostScriptHelper.HasColor(fileName)); }