private static void preview2BitmapFile(LabelFormat btFormat, TaskQueue queue, PoolItem item) { string methodName = "preview2BitmapFile"; logger.DebugFormat("BEGIN: {0}()", methodName); try { string bmpFileName = "%PageNumber%.bmp"; Resolution res = new Resolution(item.DPI); System.Drawing.Color bkcolor = System.Drawing.ColorTranslator.FromHtml("#FFFFFF"); ExportPrintPreviewToFileTask bitmapTask = new ExportPrintPreviewToFileTask(btFormat, item.BmpFolder, bmpFileName); bitmapTask.Directory = item.BmpFolder; bitmapTask.FileNameTemplate = bmpFileName; bitmapTask.BackgroundColor = bkcolor; bitmapTask.Colors = ColorDepth.Mono; bitmapTask.ImageType = ImageType.BMP; bitmapTask.IncludeBorder = false; bitmapTask.IncludeMargins = false; bitmapTask.OverwriteOptions = OverwriteOptions.Overwrite; bitmapTask.Resolution = res; logger.DebugFormat("ExportPrintPreviewToFileTask bitmap file starting ..."); TaskStatus taskStatus = queue.QueueTaskAndWait(bitmapTask, BtTaskManager.Timeout); if (taskStatus != TaskStatus.Success) { string str = ""; foreach (Seagull.BarTender.Print.Message m in bitmapTask.Messages) { str += string.Format("{0} Message: {1}\r\n", m.Severity, m.Text); } item.HasError = true; item.ErrorText = string.Format("Thread Id: {0} generate label {1} bitmap file {2} ErrorText: {3}", item.ThreadId.ToString(), item.BtwFile, taskStatus.ToString(), str); throw new Exception(item.ErrorText); } else { logger.DebugFormat("Thread Id: {0} generate label {1} bitmap files count :{1} ok! ", item.ThreadId.ToString(), item.BtwFile, bitmapTask.NumberOfPreviews.ToString()); } } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
private static void print2BitmapFile(LabelFormat btFormat, TaskQueue queue, PoolItem item) { string methodName = "print2BitmapFile"; logger.DebugFormat("BEGIN: {0}()", methodName); try { PrintLabelFormatTask bitmapTask = new PrintLabelFormatTask(btFormat); bitmapTask.PrintJobName = item.BtwSrcFileName; logger.DebugFormat("PrintLabelFormatTask bitmap file starting ..."); lock (synPrinter) { setupBitmapPrinter(item); Thread.Sleep(20); TaskStatus taskStatus = queue.QueueTaskAndWait(bitmapTask, BtTaskManager.Timeout); if (taskStatus != TaskStatus.Success) { string str = ""; foreach (Seagull.BarTender.Print.Message m in bitmapTask.Messages) { str += string.Format("{0} Message: {1}\r\n", m.Severity, m.Text); } item.HasError = true; item.ErrorText = string.Format("Thread Id: {0} generate label {1} bitmap file {2} ErrorText: {3}", item.ThreadId.ToString(), item.BtwFile, taskStatus.ToString(), str); throw new Exception(item.ErrorText); } else { waitingBitmapFile(item.BmpFolder); logger.DebugFormat("Thread Id: {0} generate label {1} bitmap files ok! ", item.ThreadId.ToString(), item.BtwFile); } } } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
public static void GenBitmapFile(TaskQueue queue,PoolItem item ) { string methodName = "GenBitmapFile"; logger.DebugFormat("BEGIN: {0}()", methodName); try { LabelFormat btFormat = null; // Create a new task to retrieve format information. GetLabelFormatTask task = new GetLabelFormatTask(item.BtwFile); logger.DebugFormat("GetLabelFormatTask starting ..."); TaskStatus status = queue.QueueTaskAndWait(task, BtTaskManager.Timeout); if (status == TaskStatus.Success) { // Get the LabelFormat object from the task // (this is cached format information; not an open document). btFormat = task.LabelFormat; logger.DebugFormat("GetLabelFormatTask completed"); } else { string str = ""; foreach (Seagull.BarTender.Print.Message m in task.Messages) { str += string.Format("{0} Message: {1}\r\n", m.Severity, m.Text); } item.HasError = true; item.ErrorText = "Generate labelFormat file " + status.ToString() + " ErrorText:" + str; throw new Exception(item.ErrorText); } string printerName = ConfigurationManager.AppSettings[PrinterName] ?? ""; logger.DebugFormat("set Default Printer Name : {0}", printerName); btFormat.PrintSetup.PrinterName = printerName; //setup label content setAndCheckLabelContent(btFormat, item); string isPreviewBitmap = ConfigurationManager.AppSettings[IsPreviewBitmap] ?? "Y"; if (isPreviewBitmap == "Y") { preview2BitmapFile(btFormat, queue, item); } else { print2BitmapFile(btFormat, queue, item); } #region generate Label Bitmap File(disbale code) //string bmpFileName = "%PageNumber%.bmp"; //Resolution res = new Resolution(item.DPI); //System.Drawing.Color bkcolor = System.Drawing.ColorTranslator.FromHtml("#FFFFFF"); //ExportPrintPreviewToFileTask bitmapTask = new ExportPrintPreviewToFileTask(btFormat, item.BmpFolder, bmpFileName); //bitmapTask.Directory = item.BmpFolder; //bitmapTask.FileNameTemplate = bmpFileName; //bitmapTask.BackgroundColor = bkcolor; //bitmapTask.Colors = ColorDepth.Mono; //bitmapTask.ImageType = ImageType.BMP; //bitmapTask.IncludeBorder = false; //bitmapTask.IncludeMargins = false; //bitmapTask.OverwriteOptions = OverwriteOptions.Overwrite; //bitmapTask.Resolution = res; //logger.DebugFormat("ExportPrintPreviewToFileTask bitmap file starting ..."); //TaskStatus taskStatus = queue.QueueTaskAndWait(bitmapTask, BtTaskManager.Timeout); //if (taskStatus != TaskStatus.Success) //{ // string str = ""; // foreach (Seagull.BarTender.Print.Message m in bitmapTask.Messages) // { // str += string.Format("{0} Message: {1}\r\n", m.Severity, m.Text); // } // item.HasError = true; // item.ErrorText = string.Format("Thread Id: {0} generate label {1} bitmap file {2} ErrorText: {3}", item.ThreadId.ToString(), item.BtwFile, taskStatus.ToString(), str); // throw new Exception(item.ErrorText); //} //else //{ // logger.DebugFormat("Thread Id: {0} generate label {1} bitmap files count :{1} ok! ", item.ThreadId.ToString(), item.BtwFile,bitmapTask.NumberOfPreviews.ToString()); //} #endregion } catch (Exception e) { logger.Error(e.Message, e); item.HasError = true; item.ErrorText = e.Message; } finally { logger.DebugFormat("END: {0}()", methodName); } }