private Task GeneratePDF() { return(Task.Run(() => { var thermalLabel = new ThermalLabel(); thermalLabel.LoadXmlTemplate(Template); var bytes = GetBytes(Data); using (var memory = new MemoryStream(bytes)) { using (var dataset = new DataSet()) { using (var printer = new PrintJob()) { dataset.ReadXml(memory); thermalLabel.DataSource = dataset; printer.PrintOrientation = PrintOrientation.Portrait; printer.ExportToPdf(thermalLabel, Filename, 600); } } } })); }
public ThermalLabel GenerateInventoryDetailLabel(string LineID, string jobname, string orderNumber, string receiver, string revDate) { //Define a ThermalLabel object and set unit to inch and label size ThermalLabel tLabel = new ThermalLabel(UnitType.Inch, 2, 1); tLabel.GapLength = 0.2; //Define a TextItem object TextItem txtItem = new TextItem(0.1, 0.10, 1.75, 0.125, "Job = " + jobname); txtItem.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontA; txtItem.Font.Unit = FontUnit.Point; txtItem.Font.Size = 7; txtItem.TextAlignment = TextAlignment.Left; TextItem txt2Item = new TextItem(0.1, 0.20, 1.75, 0.125, "Recv Date: " + revDate); txt2Item.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontA; txt2Item.Font.Unit = FontUnit.Point; txt2Item.Font.Bold = true; txt2Item.Font.Size = 7; txt2Item.TextAlignment = TextAlignment.Left; TextItem txt3Item = new TextItem(0.1, 0.3, 1.75, 0.125, "Order Number: " + orderNumber); txt3Item.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontA; txt3Item.Font.Unit = FontUnit.Point; txt3Item.Font.Size = 7; txt3Item.TextAlignment = TextAlignment.Left; TextItem txt4Item = new TextItem(0.1, 0.4, 1.75, 0.125, "Recieved By: " + receiver); txt4Item.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontA; txt4Item.Font.Unit = FontUnit.Point; txt4Item.Font.Size = 7; txt4Item.TextAlignment = TextAlignment.Left; //Define a BarcodeItem object BarcodeItem bcItem = new BarcodeItem(0.1, 0.53, 1.75, 0.45, BarcodeSymbology.Code39, LineID); bcItem.AddChecksum = false; bcItem.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontS; bcItem.Font.Unit = FontUnit.Point; bcItem.Font.Size = 7; bcItem.CodabarStopChar = CodabarStartStopChar.A; //Set bars height to .75inch bcItem.BarHeight = 0.325; //Set bars width to 0.0104inch bcItem.BarWidth = 0.0104; bcItem.BarcodeAlignment = BarcodeAlignment.MiddleCenter; //Add items to ThermalLabel object... tLabel.Items.Add(bcItem); tLabel.Items.Add(txtItem); tLabel.Items.Add(txt2Item); tLabel.Items.Add(txt3Item); tLabel.Items.Add(txt4Item); return(tLabel); }
public ThermalLabel GeneratePartLabel(string PartID, string partDescription) { //Define a ThermalLabel object and set unit to inch and label size ThermalLabel tLabel = new ThermalLabel(UnitType.Inch, 2, 1); tLabel.GapLength = 0.2; //Define a TextItem object TextItem txtItem = new TextItem(0.1, 0.25, 1.75, 0.25, "PN | " + PartID); txtItem.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontB; //txtItem.RotationAngle = 90; txtItem.Font.Unit = FontUnit.Point; txtItem.Font.Size = 10; txtItem.TextAlignment = TextAlignment.Center; //Define a TextItem object TextItem txt2 = new TextItem(0.03, 0.15, 1.9, 0.125, "DESIGN SYNTHESIS"); txt2.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontS; //txt2.RotationAngle = 90; txt2.Font.Unit = FontUnit.Point; txt2.Font.Size = 4; txt2.TextAlignment = TextAlignment.Center; //A simple vertical line LineShapeItem l3 = new LineShapeItem(1.85, 0.1, 0.01, 0.870); l3.StrokeThickness = 0.05; l3.Orientation = LineOrientation.Vertical; //A simple vertical line LineShapeItem l2 = new LineShapeItem(0.105, 0.1, 0.01, 0.870); l2.StrokeThickness = 0.05; l2.Orientation = LineOrientation.Vertical; //Define a BarcodeItem object BarcodeItem bcItem = new BarcodeItem(0.5, 0.4, 1.0, 0.5, BarcodeSymbology.Code39, PartID); bcItem.AddChecksum = false; bcItem.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontS; bcItem.Font.Unit = FontUnit.Point; bcItem.Font.Size = 4; bcItem.CodabarStopChar = CodabarStartStopChar.A; bcItem.BarHeight = 0.375; bcItem.BarWidth = 0.0104; bcItem.BarcodeAlignment = BarcodeAlignment.MiddleCenter; //Add items to ThermalLabel object... tLabel.Items.Add(bcItem); tLabel.Items.Add(txtItem); tLabel.Items.Add(txt2); tLabel.Items.Add(l3); tLabel.Items.Add(l2); return(tLabel); }
protected void Button2_Click(object sender, EventArgs e) { //ThermalLabel tLabel = new ThermalLabel(Neodynamic.SDK.Printing.UnitType.Inch, 4, 3); //tLabel.GapLength = 0.2; ////Define a BarcodeItem object for encoding Code 39 symbology //BarcodeItem bc1 = new BarcodeItem(0.2, 0.2, 2, 1, BarcodeSymbology.Code39, "ABC123"); //bc1.AddChecksum = false; //bc1.CodeAlignment = BarcodeTextAlignment.BelowJustify; //bc1.BarWidth = 0.01; //bc1.BarHeight = 0.5; //bc1.QuietZone = new FrameThickness(0); //bc1.BarcodeAlignment = BarcodeAlignment.MiddleCenter; //bc1.BorderThickness = new FrameThickness(0.03); ////A second Code 39 barcode with sizing = Fill //BarcodeItem bc2 = bc1.Clone() as BarcodeItem; //bc2.Y = 1.5; //bc2.BarcodePadding = new FrameThickness(0.1); //bc2.Sizing = BarcodeSizing.Fill; ////Add items to ThermalLabel object... //tLabel.Items.Add(bc1); //tLabel.Items.Add(bc2); ////Create a WindowsPrintJob object //WebPrintJob pj = new WebPrintJob(); // //Create PrinterSettings object // PrinterSettings myPrinter = new PrinterSettings(); // myPrinter.Communication.CommunicationType = CommunicationType.USB; // myPrinter.Dpi = 203; // myPrinter.ProgrammingLanguage = ProgrammingLanguage.ZPL; // myPrinter.PrinterName = "Zebra TLP2844-Z"; // ////Set PrinterSettings to WindowsPrintJob // pj.PrinterSettings = myPrinter; //////Print ThermalLabel object... ThermalLabel tLabel = new ThermalLabel(Neodynamic.SDK.Printing.UnitType.Inch, 4, 3); tLabel.GapLength = 0.2; //Define a TextItem object TextItem txtItem = new TextItem(0.2, 0.2, 1, 0.5, "Thermal Label Test"); //Define a BarcodeItem object BarcodeItem bcItem = new BarcodeItem(0.2, 1, 2, 1, BarcodeSymbology.Code128, TextBox1.Text); //Set bars height to .75inch bcItem.BarHeight = 0.75; //Set bars width to 0.0104inch bcItem.BarWidth = 0.0104; //Add items to ThermalLabel object... //tLabel.Items.Add(txtItem); tLabel.Items.Add(bcItem); //Create a PrintJob object //using (WindowsPrintJob pj = new WindowsPrintJob()) //{ // //Create PrinterSettings object // PrinterSettings myPrinter = new PrinterSettings(); // myPrinter.Communication.CommunicationType = CommunicationType.USB; // myPrinter.Dpi = 203; // myPrinter.ProgrammingLanguage = ProgrammingLanguage.ZPL; // myPrinter.PrinterName = "Zebra TLP2844-Z"; // //Set PrinterSettings to WindowsPrintJob // pj.PrinterSettings = myPrinter; // //Print ThermalLabel object... // pj.Print(tLabel); //} using (PrintJob pj = new PrintJob()) { //Set number of copies pj.Copies = 5; //Save output to PDF... pj.ExportToPdf(tLabel, @"d:\develop\myLabels.pdf", 300); } }
private void WcThumbnail_DownloadDataCompleted(object sender, System.Net.DownloadDataCompletedEventArgs e) { int thumbnailSize = 200; this.Entries[_index - 1].XmlContent = Encoding.UTF8.GetString(e.Result); var tl = ThermalLabel.CreateFromXmlTemplate(this.Entries[_index - 1].XmlContent); var ms = new MemoryStream(); using (var pj = new PrintJob()) { pj.ExportToImage(tl, ms, new ImageSettings() { AntiAlias = true, ImageFormat = ImageFormat.Png, ThumbnailSize = thumbnailSize }, 96); } System.Drawing.Image imgLabel = null; if (ZipUtils.IsPkZipCompressedData(ZipUtils.GetInitBytes(ms, 4))) { using (var zip = new ZipArchive(ms)) { foreach (var entry in zip.Entries) { imgLabel = System.Drawing.Image.FromStream(entry.Open()); } } } else { imgLabel = System.Drawing.Image.FromStream(ms); } var pb = new System.Windows.Forms.PictureBox(); pb.SizeMode = PictureBoxSizeMode.CenterImage; pb.BorderStyle = BorderStyle.FixedSingle; pb.BackColor = System.Drawing.Color.WhiteSmoke; pb.Width = pb.Height = thumbnailSize + 20; pb.Image = imgLabel; var lbl = new Label(); lbl.TextAlign = ContentAlignment.MiddleCenter; lbl.AutoSize = false; lbl.Width = thumbnailSize + 20; lbl.Height = 30; lbl.Text = this.Entries[_index - 1].Name; lbl.ForeColor = System.Drawing.Color.White; var btn = new Button(); btn.Text = "Edit..."; btn.Width = thumbnailSize + 20; btn.Height = 30; btn.BackColor = System.Drawing.SystemColors.ButtonFace; btn.Tag = _index; btn.Click += Btn_Click; var uc = new UserControl(); uc.Controls.Add(lbl); uc.Controls.Add(pb); uc.Controls.Add(btn); pb.Top = lbl.Height; btn.Top = pb.Top + pb.Height; uc.Height = btn.Top + btn.Height; uc.Width = pb.Width; fpnlContainer.Controls.Add(uc); this.pbGallery.Value = _index * this.pbGallery.Step; if (_index == this.Entries.Count) { this.pbGallery.Value = 0; } _index++; }
private ThermalLabel GenerateBasicThermalLabel() { //Define a ThermalLabel object and set unit to inch and label size ThermalLabel tLabel = new ThermalLabel(Neodynamic.SDK.Printing.UnitType.Inch, 4, 6); tLabel.GapLength = 0.2; //Define a couple of TextItem objects for Employee info TextItem txt1 = new TextItem(); //set data field txt1.DataField = "Items"; //set font txt1.Font.Name = Font.NativePrinterFontA; txt1.Font.Unit = FontUnit.Point; txt1.Font.Size = 10; txt1.TextPadding = new FrameThickness(0.5); TextItem txt2 = new TextItem(); //set data field txt2.DataField = "Quantity"; //set font txt2.Font.Name = Font.NativePrinterFontA; txt2.Font.Unit = FontUnit.Point; txt2.Font.Size = 10; txt1.TextPadding = new FrameThickness(0.5); //TextItem txt3 = new TextItem(); ////set data field //txt3.DataField = "Rate"; ////set font //txt3.Font.Name = Font.NativePrinterFontA; //txt3.Font.Unit = FontUnit.Point; //txt3.Font.Size = 10; //TextItem txt4 = new TextItem(0.13, 0.05, 2.8, 0.3, ""); ////set data field //txt4.DataField = "Total"; ////set font //txt4.Font.Name = Font.NativePrinterFontA; //txt4.Font.Unit = FontUnit.Point; //txt4.Font.Size = 10; tLabel.Items.Add(txt1); tLabel.Items.Add(txt2); //tLabel.Items.Add(txt3); //tLabel.Items.Add(txt4); tLabel.DataSource = _invoiceDataManager.GetInvoiceByOrderId(1); //TextItem title = new TextItem(0.5, 0.5, 2.5, 0.5, "Ismartmandu"); //title.TextPadding = new FrameThickness(0.2); //TextItem address = new TextItem(0.5, 0.5, 2.5, 0.5, "Kathmandu, Nepal"); //address.TextPadding = new FrameThickness(0.2); //var orderlist = GetInvoiceByOrderId(1); //foreach(var order in orderlist) //{ //} //TextItem Greetings = new TextItem(0.5, 0.5, 2.5, 0.5, "Thank you for vist"); //Greetings.TextPadding = new FrameThickness(0.2); ////Add items to ThermalLabel object... //tLabel.Items.Add(title); //tLabel.Items.Add(address); //tLabel.Items.Add(Greetings); //tLabel.DataSource=orderlist; return(tLabel); }
private void btnPrint_Click(object sender, EventArgs e) { if (_aObject.IdAssets == 0) { MessageBox.Show("Busque primero un Activo Fijo.", "Campo Faltante", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ThermalLabel _currentThermalLabel = null; _currentThermalLabel = this.GenerateBasicThermalLabel(); Neodynamic.SDK.Printing.PrinterSettings _printerSettings = new Neodynamic.SDK.Printing.PrinterSettings(); _printerSettings.Communication.CommunicationType = CommunicationType.USB; _printerSettings.PrinterName = _Printer; _printerSettings.Dpi = 203; _printerSettings.ProgrammingLanguage = (ProgrammingLanguage)Enum.Parse(typeof(ProgrammingLanguage), "ZPL"); PrintOrientation _printOrientation = PrintOrientation.Portrait; int x = 0; bool isPrinterValid = false; string printerName = _Printer; string query = string.Format("SELECT * from Win32_Printer " + "WHERE Name LIKE '%{0}'", printerName); ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); ManagementObjectCollection coll = searcher.Get(); foreach (ManagementObject printer in coll) { foreach (PropertyData property in printer.Properties) { //Console.WriteLine(string.Format("{0}: {1}", // property.Name, // property.Value)); if (x == 85) { isPrinterValid = (bool)property.Value; } x++; } } if (isPrinterValid) { MessageBox.Show("Impresora no conectada o apagada. Asegúrese de que la impresora esté conectada y que esté encendida para poder imprimir.", "Conecte y encieda la impresora", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { using (PrintJob pj = new PrintJob(_printerSettings)) { pj.PrintOrientation = _printOrientation; pj.ThermalLabel = _currentThermalLabel; pj.Print(); } } catch (Exception ex) { MessageBox.Show("Error: " + ex); } } } }
private ThermalLabel GenerateAdvancedThermalLabel() { //Define a ThermalLabel object and set unit to inch and label size ThermalLabel tLabel = new ThermalLabel(UnitType.Inch, 4, 3); tLabel.GapLength = 0.2; //get ThermalLabel SDk install dir and get the sample images string imgFolder = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Neodynamic\\SDK\\ThermalLabel SDK 6.0 for .NET\\InstallDir").GetValue(null).ToString() + "\\Samples\\Images\\"; //Define an ImageItem for AdventureWorks logo ImageItem awLogo = new ImageItem(0.1, 0.1); awLogo.SourceFile = imgFolder + "adventureworks.jpg"; awLogo.Width = 1.5; awLogo.LockAspectRatio = LockAspectRatio.WidthBased; awLogo.MonochromeSettings.DitherMethod = DitherMethod.Threshold; awLogo.MonochromeSettings.Threshold = 80; //Define a TextItem for 'AW' id TextItem txtAW = new TextItem(2.8, 0.1, 1.1, 0.5, "AW"); //font settings txtAW.Font.Name = "Arial"; txtAW.Font.Bold = true; //stretch text txtAW.Sizing = TextSizing.Stretch; //border settings txtAW.BorderThickness = new FrameThickness(0.02); txtAW.CornerRadius = new RectangleCornerRadius(0.05); txtAW.TextPadding = new FrameThickness(0); //Define a TextItem for 'Model Name' TextItem txtModelName = new TextItem(0.1, 0.75, 3.8, 0.25, "Model Name: ROAD 150"); //font settings txtModelName.Font.Name = "Arial"; txtModelName.Font.Unit = FontUnit.Point; txtModelName.Font.Size = 12; //white text on black background txtModelName.BackColor = Neodynamic.SDK.Printing.Color.Black; txtModelName.ForeColor = Neodynamic.SDK.Printing.Color.White; //padding txtModelName.TextPadding = new FrameThickness(0.075, 0.03, 0, 0); //Define a TextItem for 'Model Code' (random code) TextItem txtModelCode = new TextItem(0.1, 1, 3.8, 0.25, "Model Code: " + Guid.NewGuid().ToString().ToUpper().Substring(0, 17)); //font settings txtModelCode.Font.Name = "Arial"; txtModelCode.Font.Unit = FontUnit.Point; txtModelCode.Font.Size = 12; //white text on black background txtModelCode.BackColor = Neodynamic.SDK.Printing.Color.Black; txtModelCode.ForeColor = Neodynamic.SDK.Printing.Color.White; //padding txtModelCode.TextPadding = new FrameThickness(0.075, 0.03, 0, 0); //Define a BarcodeItem for a random 'Serial Number' string serialNum = Guid.NewGuid().ToString().ToUpper().Substring(0, 8); BarcodeItem serialBarcode = new BarcodeItem(0.1, 1.25, 3.8, 0.5, BarcodeSymbology.Code39, serialNum); //Set bars height to .3inch serialBarcode.BarHeight = 0.3; //Set bars width to 0.02inch serialBarcode.BarWidth = 0.02; //disable checksum serialBarcode.AddChecksum = false; //hide human readable text serialBarcode.DisplayCode = false; //set border serialBarcode.BorderThickness = new FrameThickness(0.02); //align barcode serialBarcode.BarcodeAlignment = BarcodeAlignment.MiddleCenter; //Define a TextItem for 'Serial Num' TextItem txtSN = new TextItem(0.1, 1.75 - serialBarcode.BorderThickness.Bottom, 1.25, 0.3, "S/N: " + serialNum); //font settings txtSN.Font.Name = "Arial Narrow"; txtSN.Font.Bold = true; txtSN.Font.Unit = FontUnit.Point; txtSN.Font.Size = 12; //padding txtSN.TextPadding = new FrameThickness(0.03); //set border txtSN.BorderThickness = new FrameThickness(0.02); txtSN.TextAlignment = TextAlignment.Center; //Define a TextItem for legend TextItem txtLegend = new TextItem(txtSN.X + txtSN.Width - txtSN.BorderThickness.Right, txtSN.Y, 3.8 - txtSN.Width + txtSN.BorderThickness.Right, txtSN.Height, "This bike is ridden by race winners! Brought to you by Adventure Works Cycles professional race team."); //font settings txtLegend.Font.Name = "Arial"; txtLegend.Font.Unit = FontUnit.Point; txtLegend.Font.Size = 7.5; //padding txtLegend.TextPadding = new FrameThickness(0.03, 0, 0, 0); //set border txtLegend.BorderThickness = new FrameThickness(0.02); //Define another BarcodeItem for EAN-13 symbology BarcodeItem eanBarcode = new BarcodeItem(0.1, 2.1, 3, 0.9, BarcodeSymbology.Ean13, "0729507704739"); //Set barcode dimensions... eanBarcode.BarHeight = 0.5; eanBarcode.BarWidth = 0.02; eanBarcode.EanUpcGuardBarHeight = 0.55; //human readable text font settings eanBarcode.Font.Name = Neodynamic.SDK.Printing.Font.NativePrinterFontA; eanBarcode.Font.Unit = FontUnit.Point; eanBarcode.Font.Size = 5; //Define an ImageItem for NBDA logo ImageItem nbdaLogo = new ImageItem(2.9, 2.1); nbdaLogo.SourceFile = imgFolder + "nbda.jpg"; nbdaLogo.Width = 1; nbdaLogo.LockAspectRatio = LockAspectRatio.WidthBased; nbdaLogo.MonochromeSettings.DitherMethod = DitherMethod.Threshold; nbdaLogo.MonochromeSettings.Threshold = 50; nbdaLogo.MonochromeSettings.ReverseEffect = true; //Define a LineShapeItem LineShapeItem line = new LineShapeItem(0.1, 2.8, 3.8, 0.03); line.Orientation = LineOrientation.Horizontal; line.StrokeThickness = 0.03; //Add items to ThermalLabel object... tLabel.Items.Add(awLogo); tLabel.Items.Add(txtAW); tLabel.Items.Add(txtModelName); tLabel.Items.Add(txtModelCode); tLabel.Items.Add(serialBarcode); tLabel.Items.Add(txtSN); tLabel.Items.Add(txtLegend); tLabel.Items.Add(eanBarcode); tLabel.Items.Add(nbdaLogo); tLabel.Items.Add(line); return(tLabel); }