public void generarCodigoBarras(Consumidor t) { //Toma el RUN del consumidor guardado en la sesion del consumidor, con el cual se generara el código de barras para el PDF string code = t.runConsumidor; Barcode39 barcodeImg = new Barcode39(); barcodeImg.Code = code.ToString(); barcodeImg.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White).Save(@"C:\Users\nicolas\Documents\Visual Studio 2015\Projects\webMisOfertasResponsive\webMisOfertasResponsive\tempDocs\barcode" + t.runConsumidor + ".png", System.Drawing.Imaging.ImageFormat.Png); }
private void button1_Click(object sender, EventArgs e) { bool isPreview = chb_preview.Checked; Barcode39 barcode39 = new Barcode39(); barcode39.Code = "20201209/WED"; barcode39.BarHeight = 50f; //save image file //barcode39.CreateDrawingImage(Color.Black, Color.White).Save(@"C:\Users\Chanos\Desktop\git\barcode.png"); Image barcodeImage = barcode39.CreateDrawingImage(Color.Black, Color.White); PrintDocument printDocument = new PrintDocument(); printDocument.PrintPage += (printSender, printEvent) => { printEvent.Graphics.DrawImage(barcodeImage, new Point(0, 0)); }; using (PageSetupDialog pageSetupDialog = new PageSetupDialog()) { pageSetupDialog.Document = printDocument; pageSetupDialog.ShowDialog(); } using (PrintDialog printDialog = new PrintDialog()) { printDialog.Document = printDocument; printDialog.ShowDialog(); } if (!isPreview) { printDocument.Print(); } else { using (PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog()) { printPreviewDialog.Document = printDocument; printPreviewDialog.ShowDialog(); } } }
public static Bitmap CodigosBarraPLU(string _Code, Single Height = 0) { Barcode39 uccEan128 = new Barcode39(); uccEan128.CodeType = Barcode39.CODABAR; if (Height != 0) { uccEan128.BarHeight = 10; } uccEan128.Code = _Code; try { Bitmap bm = new Bitmap(uccEan128.CreateDrawingImage(Color.Black, Color.White)); return(bm); } catch (Exception ex) { throw new Exception("Error al generar el codigo" + ex.ToString()); } }
public void ProcessRequest(System.Web.HttpContext context) { HttpRequest Request = context.Request; HttpResponse response = context.Response; Barcode39 bc39 = new Barcode39(); if (Request["code"] != null) { bc39.Code = Request["code"]; } else { bc39.Code = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString(); } System.Drawing.Image bc = bc39.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White); response.ContentType = "image/gif"; bc.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); }
public static byte[] WriteToPdf(FileInfo sourceFile, string stringToWriteToPdf) { PdfReader reader = new PdfReader(sourceFile.FullName); using (MemoryStream memoryStream = new MemoryStream()) { // // PDFStamper is the class we use from iTextSharp to alter an existing PDF. // PdfStamper pdfStamper = new PdfStamper(reader, memoryStream); for (int i = 1; i <= reader.NumberOfPages; i++) // Must start at 1 because 0 is not an actual page. { iTextSharp.text.Rectangle pageSize = reader.GetPageSizeWithRotation(i); PdfContentByte pdfPageContents = pdfStamper.GetOverContent(i); pdfPageContents.BeginText(); // Start working with text. BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, false); //pdfPageContents.SetFontAndSize(baseFont, 15); //pdfPageContents.SetRGBColorFill(255, 0, 0); int dpi = 100; Barcode39 br = new Barcode39(); br.Code = stringToWriteToPdf; iTextSharp.text.Image barcodeImage = iTextSharp.text.Image.GetInstance(br.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), BaseColor.BLACK); barcodeImage.SetAbsolutePosition((pageSize.Width / 2) + (barcodeImage.Width / 2), pageSize.Height - 20);// pageSize.Height - 150 barcodeImage.ScalePercent(72f / (float)dpi * 100f); //float textAngle = // (float)FooTheoryMath.GetHypotenuseAngleInDegreesFrom(pageSize.Height, pageSize.Width); //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, stringToWriteToPdf, // pageSize.Width/2, // pageSize.Height/2, // textAngle); pdfPageContents.AddImage(barcodeImage, true); //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, stringToWriteToPdf, (pageSize.Width / 5) *4, pageSize.Height - 150, 0); pdfPageContents.EndText(); } pdfStamper.FormFlattening = true; pdfStamper.Close(); return(memoryStream.ToArray()); } }
/// <summary> /// 获取条码图片 /// </summary> /// <param name="content">条码内容</param> /// <param name="type">编码类型</param> /// <param name="height">高度(磅)</param> /// <param name="unit">单位宽度(磅)</param> /// <param name="fore">前景色/条码颜色</param> /// <param name="back">背景色</param> /// <returns>条码Image</returns> public static Image getBarcode(string content, BarcodeType type, float height, float unit, Color fore, Color back) { if (content.isNull()) { content = "1234567"; } try { var test = Convert.ToInt64(content); if (test < 0) { content = "1234567"; } } catch { content = "1234567"; } Image img = null; if (fore.A == 0) { fore = Color.Black; } if (back.A == 0) { back = Color.White; } try { switch (type) { case BarcodeType.Code39: default: Barcode39 code39 = new Barcode39(); code39.BarHeight = height; code39.Code = content; if (unit > 0) { code39.N = unit; } img = code39.CreateDrawingImage(fore, back); break; case BarcodeType.Code128: Barcode128 code128 = new Barcode128(); code128.BarHeight = height; code128.Code = content; if (unit > 0) { code128.N = unit; } code128.CodeType = Barcode.CODE128; img = code128.CreateDrawingImage(fore, back); break; case BarcodeType.Inter25: BarcodeInter25 codeInter25 = new BarcodeInter25(); codeInter25.BarHeight = height; codeInter25.Code = content; if (unit > 0) { codeInter25.N = unit; } img = codeInter25.CreateDrawingImage(fore, back); break; case BarcodeType.Postnet: BarcodePostnet codePostnet = new BarcodePostnet(); codePostnet.BarHeight = height; codePostnet.Code = content; if (unit > 0) { codePostnet.N = unit; } img = codePostnet.CreateDrawingImage(fore, back); break; case BarcodeType.CodeBar: BarcodeCodabar codeCodeBar = new BarcodeCodabar(); codeCodeBar.BarHeight = height; codeCodeBar.Code = "A" + content + "A"; if (unit > 0) { codeCodeBar.N = unit; } img = codeCodeBar.CreateDrawingImage(fore, back); break; } } catch { } return(img); }