PlexMode GetPlexMode(byte[] initialBytes) { string ascii = Encoding.ASCII.GetString(initialBytes, DUPLEX_SETTING_OFFSET, DUPLEX_SETTING_STRING.Length); PlexMode plexMode = (String.Equals(DUPLEX_SETTING_STRING, ascii, StringComparison.Ordinal)) ? PlexMode.Duplex : PlexMode.Simplex; return(plexMode); }
public void Print(string psFilePath, string outputPrinter, PlexMode plexMode) { if (psFilePath == null) { throw new ArgumentNullException("psFilePath"); } if (outputPrinter == null) { throw new ArgumentNullException("printerName"); } string setupFilePath = null; try // try/finally block for setup file { setupFilePath = this.writeSetupFile(outputPrinter, plexMode); var args = this.createArgs(psFilePath, outputPrinter, setupFilePath); var hInstance = IntPtr.Zero; try // try/finally block for GhostScript handle { int errorCode = NativeMethods.gsapi_new_instance(ref hInstance, IntPtr.Zero); if (errorCode < 0) { throw new Exception(String.Format("gsapi_new_instance returned error code {0}", errorCode)); } errorCode = NativeMethods.gsapi_init_with_args(hInstance, args.Length, args); if (errorCode < 0) { throw new Exception(String.Format("gsapi_init_with_args returned error code {0}", errorCode)); } NativeMethods.gsapi_exit(hInstance); this.logger.Invoke("GhostScript completed processing successfully"); } finally { if (hInstance != null) { NativeMethods.gsapi_delete_instance(hInstance); } } } finally { if (setupFilePath != null) { File.Delete(setupFilePath); this.logger.Invoke("Deleted job setup file"); } } }
public void Print(string psFilePath, string outputPrinter, PlexMode plexMode) { if (psFilePath == null) { throw new ArgumentNullException("psFilePath"); } if (outputPrinter == null) { throw new ArgumentNullException("printerName"); } string setupFilePath = null; try // try/finally block for setup file { setupFilePath = this.writeSetupFile(outputPrinter, plexMode); var args = this.createArgs(psFilePath, outputPrinter, setupFilePath); var hInstance = IntPtr.Zero; try // try/finally block for GhostScript handle { int errorCode = NativeMethods.gsapi_new_instance(ref hInstance, IntPtr.Zero); if (errorCode < 0) { throw new Exception(String.Format("gsapi_new_instance returned error code {0}", errorCode)); } errorCode = NativeMethods.gsapi_init_with_args(hInstance, args.Length, args); if (errorCode < 0) { throw new Exception(String.Format("gsapi_init_with_args returned error code {0}", errorCode)); } NativeMethods.gsapi_exit(hInstance); this.logger.Invoke("GhostScript completed processing successfully"); } finally { if (hInstance != null) { NativeMethods.gsapi_delete_instance(hInstance); } } } finally { if (setupFilePath != null) { File.Delete(setupFilePath); this.logger.Invoke("Deleted job setup file"); } } }
private string writeSetupFile(string outputPrinter, PlexMode plexMode) { if (outputPrinter == null) { throw new ArgumentNullException("printerName"); } string fileContent = Encoding.UTF8.GetString(Properties.Resources.setupPostScript); fileContent = fileContent.Replace(PostScriptPrinter.OUTPUT_PRINTER_TOKEN, outputPrinter); fileContent = fileContent.Replace(PostScriptPrinter.OUTPUT_PLEX_MODE_TOKEN, plexMode == PlexMode.Duplex ? "true" : "false"); string path = Path.GetTempFileName(); File.WriteAllText(path, fileContent); this.logger.Invoke(String.Format("Wrote job setup file to \"{0}\"", path)); return(path); }
public PrintJobProperties GetProperties() { byte[] initialBytes = new byte[SEARCH_SIZE]; using (var stream = File.OpenRead(pclFilePath)) { int totalRead = 0; do { int read = stream.Read(initialBytes, totalRead, initialBytes.Length - totalRead); if (read < 1) { throw new EndOfStreamException("PCL file is too small, cannot read job properties"); } totalRead += read; } while (totalRead < SEARCH_SIZE); } PlexMode plexMode = this.GetPlexMode(initialBytes); ColorMode colorMode = this.GetColorMode(initialBytes); return(new PrintJobProperties(colorMode, plexMode)); }
private string writeSetupFile(string outputPrinter, PlexMode plexMode) { if (outputPrinter == null) { throw new ArgumentNullException("printerName"); } string fileContent = Encoding.UTF8.GetString(Properties.Resources.setupPostScript); fileContent = fileContent.Replace(PostScriptPrinter.OUTPUT_PRINTER_TOKEN, outputPrinter); fileContent = fileContent.Replace(PostScriptPrinter.OUTPUT_PLEX_MODE_TOKEN, plexMode == PlexMode.Duplex ? "true" : "false"); string path = Path.GetTempFileName(); File.WriteAllText(path, fileContent); this.logger.Invoke(String.Format("Wrote job setup file to \"{0}\"", path)); return path; }
public PrintJobProperties(ColorMode colorMode, PlexMode plexMode) { this.ColorMode = colorMode; this.PlexMode = plexMode; }
public PrintJobProperties(ColorMode colorMode, PlexMode plexMode) { this.ColorMode = colorMode; this.PlexMode = plexMode; }