public string GetPreviewImage(string filename, int width, int height)
        {
            _log.Debug($"GetPreviewImage for filename={filename}");

            try
            {
                var previewPath = ConfigurationProvider.Settings.PreviewPath;
                var files       = Directory.GetFiles(previewPath);
                foreach (string file in files)
                {
                    File.Delete(file);
                }


                _format = _engine.Documents.Open(filename);
                _format.PrintSetup.PrinterName = DefaultPrinterName;
                Messages messages;
                _format.ExportPrintPreviewToFile(previewPath, "PrintPreview%PageNumber%.jpg", ImageType.JPEG, Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, new Resolution(width, height), System.Drawing.Color.White, OverwriteOptions.Overwrite, true, true, out messages);
                files = Directory.GetFiles(previewPath, "*.*");

                return(files.Length < 1 ? String.Empty : files[0]);
            }
            catch (Exception ex)
            {
                _log.Error($"BartenderService.GetPreviewImage error for filename={filename}", ex);
            }

            return(null);
        }
예제 #2
0
 public static void PrintPreviewLabel2File(
     LabelFormatDocument updatedFormat, Engine btEngine)
 {
     try
     {
         Messages   msgs;
         Resolution r = new Resolution(200);
         if (!Directory.Exists(Constants.previewDir))
         {
             Directory.CreateDirectory(Constants.previewDir);
         }
         updatedFormat.ExportPrintPreviewToFile(Constants.previewDir,
                                                "当前打印预览.bmp", ImageType.BMP, ColorDepth.ColorDepth16, r,
                                                System.Drawing.Color.White, OverwriteOptions.DoNotOverwrite,
                                                false, false, out msgs);
     }
     catch (Exception ex)
     {
         Log.Instance.Logger.Info($"导出预览错误:{ex.Message}");
     }
 }
예제 #3
0
        private void openFilebtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect      = false;//多个文件
            dialog.Title            = "请选择要烧录的文件";
            dialog.Filter           = "bwt文件(*.btw)|*.btw";
            dialog.InitialDirectory = Application.StartupPath;

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _btw_path              = dialog.FileName;
                fileNametBox.Text      = dialog.SafeFileName;
                fileNametBox.BackColor = Color.LightGreen;

                pictureBox.Image = null;
                using (Engine btEngine = new Engine(true))
                {
                    LabelFormatDocument labelFormat = btEngine.Documents.Open(_btw_path);

                    if (labelFormat != null)
                    {
                        Seagull.BarTender.Print.Messages m;
                        labelFormat.ExportPrintPreviewToFile(Application.StartupPath, @"\exp.bmp", ImageType.JPEG, Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, new Resolution(300, 300), System.Drawing.Color.White, OverwriteOptions.Overwrite, true, true, out m);
                        labelFormat.ExportImageToFile(_bmp_path, ImageType.JPEG, Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, new Resolution(300, 300), OverwriteOptions.Overwrite);

                        Image  image    = Image.FromFile(_bmp_path);
                        Bitmap NmpImage = new Bitmap(image);
                        pictureBox.Image = NmpImage;
                        image.Dispose();
                    }
                    else
                    {
                        MessageBox.Show("生成图片错误", "操作提示");
                    }
                }
            }
        }
예제 #4
0
        private int PrintBTLabels(RepackItems e, string filename)
        {
            // string[] browsingFormats;
            // npRepackLabelParm lotGenSerial = (npRepackLabelParm)e.PopupWindowView.CurrentObject;
            string      LabFilename;
            RepackItems Ritem = e;

            try
            {
                engine = new Engine(true);
            }
            catch (PrintEngineException exception)
            {
                // If the engine is unable to start, a PrintEngineException will be thrown.
                //MessageBox.Show(this, exception.Message, appName);
                //this.Close(); // Close this app. We cannot run without connection to an engine.
                throw new ArgumentNullException(exception.Message + " unable to start Bartender Try installing BARTENDER Label Software");
            }
            //string PrinterName = lotGenSerial.PrinterName;
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                if (format != null)
                {
                    format.Close(SaveOptions.DoNotSaveChanges);
                }
                format = engine.Documents.Open(Ritem.BTDefualtTemplate);
                TextFile xfile = new TextFile("test");


                xfile.FileName = filename; // @"c:\BTData\btdata.xls";
                object test = xfile.GetType();


                // format.DatabaseConnections.SetDatabaseConnection(xfile);
                //format.PrintSetup.PrinterName = PrinterName;

                // format.Print("Lot Label print");
                //Resolution res = new Resolution(300, 700);

                Resolution res      = new Resolution(ImageResolution.Screen);
                Messages   messages = new Messages();
                LabFilename = Ritem.ItemNumber.ToString() + "-SampleLabel";

                format.ExportPrintPreviewToFile(@"c:\BTData", LabFilename, ImageType.JPEG, Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, res, System.Drawing.Color.White, OverwriteOptions.Overwrite, true, true, out messages);
                engine.Documents.Close(Ritem.BTDefualtTemplate, SaveOptions.DoNotSaveChanges);
                // format.Close(SaveOptions.DoNotSaveChanges);
                engine.Dispose();
                engine = null;

                //
                //if (messages.HasError)
                // {
                //     throw new Exception("error creating labels") ;
                // }

                Messages rMessages;

                rMessages = new Messages();

                Resolution iResolution;
                iResolution = new Resolution(ImageResolution.Printer);

                //format.ExportPrintPreviewToFile("c:\\temp", "testJpeg.jpg", ImageType.JPEG,
                //    Seagull.BarTender.Print.ColorDepth.ColorDepth24bit, iResolution                     ,
                //    System.Drawing.Color.White,
                //    OverwriteOptions.Overwrite, true, true, out rMessages);
                // format.Close(SaveOptions.DoNotSaveChanges);
                format = null;
            }

            catch (System.Runtime.InteropServices.COMException comException)
            {
                //     errorMessage = String.Format("Unable to open format: {0}\nReason: {1}", browsingFormats[index], comException.Message);
                format = null;
                throw new ArgumentNullException(comException.Message + " Error in Repack Label print");
            }

            if (File.Exists(@"c:\BTData\" + LabFilename + "1"))
            {
                Ritem.LabelImage = DownloadFile(@"c:\BTData\" + LabFilename + "1");
                Ritem.Save();
                Ritem.Session.CommitTransaction();
            }

            // engine.Documents.CloseAll(SaveOptions.DoNotSaveChanges);

            return(1);
        }
예제 #5
0
        private static void preview2BitmapFile(LabelFormatDocument btFormat, PoolItem item)
        {
            string methodName = "preview2BitmapFile";
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                Seagull.BarTender.Print.Messages message = null;
                string bmpFileName = "%PageNumber%.bmp";
                Resolution res = new Resolution(item.DPI);
                System.Drawing.Color bkcolor = System.Drawing.ColorTranslator.FromHtml("#FFFFFF");


                Result result = btFormat.ExportPrintPreviewToFile(item.BmpFolder,
                                            bmpFileName, ImageType.BMP, ColorDepth.Mono
                                              , res, bkcolor, OverwriteOptions.Overwrite,
                                             false, false, out message);
                if (result != Result.Success)
                {
                    item.HasError = true;
                    string str = "";
                    foreach (Seagull.BarTender.Print.Message m in message)
                    {
                        str += string.Format("{0} Message: {1}\r\n", m.Severity, m.Text);
                    }
                    item.ErrorText = string.Format("Thread Id: {0} generate label {1} bitmap file {2}  ErrorText: {3}", item.ThreadId.ToString(), item.BtwFile, result.ToString(), str);
                    throw new Exception(item.ErrorText);
                }
                else
                {

                    logger.DebugFormat("Thread Id: {0} generate label {1} bitmap file ok! ", item.ThreadId.ToString(), item.BtwFile);
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }

        }