// =========================================================================== public void Write(Stream stream) { // step 1 using (Document document = new Document(new Rectangle(340, 842))) { // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); // step 3 document.Open(); // step 4 PdfContentByte cb = writer.DirectContent; // EAN 13 document.Add(new Paragraph("Barcode EAN.UCC-13")); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.Code = "4512345678906"; document.Add(new Paragraph("default:")); document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); codeEAN.GuardBars = false; document.Add(new Paragraph("without guard bars:")); document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); codeEAN.Baseline = -1f; codeEAN.GuardBars = true; document.Add(new Paragraph("text above:")); document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); codeEAN.Baseline = codeEAN.Size; // UPC A document.Add(new Paragraph("Barcode UCC-12 (UPC-A)")); codeEAN.CodeType = Barcode.UPCA; codeEAN.Code = "785342304749"; document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); // EAN 8 document.Add(new Paragraph("Barcode EAN.UCC-8")); codeEAN.CodeType = Barcode.EAN8; codeEAN.BarHeight = codeEAN.Size * 1.5f; codeEAN.Code = "34569870"; document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); // UPC E document.Add(new Paragraph("Barcode UPC-E")); codeEAN.CodeType = Barcode.UPCE; codeEAN.Code = "03456781"; document.Add(codeEAN.CreateImageWithBarcode(cb, null, null)); codeEAN.BarHeight = codeEAN.Size * 3f; // EANSUPP document.Add(new Paragraph("Bookland")); document.Add(new Paragraph("ISBN 0-321-30474-8")); codeEAN.CodeType = Barcode.EAN13; codeEAN.Code = "9781935182610"; BarcodeEAN codeSUPP = new BarcodeEAN(); codeSUPP.CodeType = Barcode.SUPP5; codeSUPP.Code = "55999"; codeSUPP.Baseline = -2; BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP); document.Add(eanSupp.CreateImageWithBarcode(cb, null, BaseColor.BLUE)); // CODE 128 document.Add(new Paragraph("Barcode 128")); Barcode128 code128 = new Barcode128(); code128.Code = "0123456789 hello"; document.Add(code128.CreateImageWithBarcode(cb, null, null)); code128.Code = "0123456789\uffffMy Raw Barcode (0 - 9)"; code128.CodeType = Barcode.CODE128_RAW; document.Add(code128.CreateImageWithBarcode(cb, null, null)); // Data for the barcode : String code402 = "24132399420058289"; String code90 = "3700000050"; String code421 = "422356"; StringBuilder data = new StringBuilder(code402); data.Append(Barcode128.FNC1); data.Append(code90); data.Append(Barcode128.FNC1); data.Append(code421); Barcode128 shipBarCode = new Barcode128(); shipBarCode.X = 0.75f; shipBarCode.N = 1.5f; shipBarCode.Size = 10f; shipBarCode.TextAlignment = Element.ALIGN_CENTER; shipBarCode.Baseline = 10f; shipBarCode.BarHeight = 50f; shipBarCode.Code = data.ToString(); document.Add(shipBarCode.CreateImageWithBarcode( cb, BaseColor.BLACK, BaseColor.BLUE )); // it is composed of 3 blocks whith AI 01, 3101 and 10 Barcode128 uccEan128 = new Barcode128(); uccEan128.CodeType = Barcode.CODE128_UCC; uccEan128.Code = "(01)00000090311314(10)ABC123(15)060916"; document.Add(uccEan128.CreateImageWithBarcode( cb, BaseColor.BLUE, BaseColor.BLACK )); uccEan128.Code = "0191234567890121310100035510ABC123"; document.Add(uccEan128.CreateImageWithBarcode( cb, BaseColor.BLUE, BaseColor.RED )); uccEan128.Code = "(01)28880123456788"; document.Add(uccEan128.CreateImageWithBarcode( cb, BaseColor.BLUE, BaseColor.BLACK )); // INTER25 document.Add(new Paragraph("Barcode Interleaved 2 of 5")); BarcodeInter25 code25 = new BarcodeInter25(); code25.GenerateChecksum = true; code25.Code = "41-1200076041-001"; document.Add(code25.CreateImageWithBarcode(cb, null, null)); code25.Code = "411200076041001"; document.Add(code25.CreateImageWithBarcode(cb, null, null)); code25.Code = "0611012345678"; code25.ChecksumText = true; document.Add(code25.CreateImageWithBarcode(cb, null, null)); // POSTNET document.Add(new Paragraph("Barcode Postnet")); BarcodePostnet codePost = new BarcodePostnet(); document.Add(new Paragraph("ZIP")); codePost.Code = "01234"; document.Add(codePost.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("ZIP+4")); codePost.Code = "012345678"; document.Add(codePost.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("ZIP+4 and dp")); codePost.Code = "01234567890"; document.Add(codePost.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("Barcode Planet")); BarcodePostnet codePlanet = new BarcodePostnet(); codePlanet.Code = "01234567890"; codePlanet.CodeType = Barcode.PLANET; document.Add(codePlanet.CreateImageWithBarcode(cb, null, null)); // CODE 39 document.Add(new Paragraph("Barcode 3 of 9")); Barcode39 code39 = new Barcode39(); code39.Code = "ITEXT IN ACTION"; document.Add(code39.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("Barcode 3 of 9 extended")); Barcode39 code39ext = new Barcode39(); code39ext.Code = "iText in Action"; code39ext.StartStopText = false; code39ext.Extended = true; document.Add(code39ext.CreateImageWithBarcode(cb, null, null)); // CODABAR document.Add(new Paragraph("Codabar")); BarcodeCodabar codabar = new BarcodeCodabar(); codabar.Code = "A123A"; codabar.StartStopText = true; document.Add(codabar.CreateImageWithBarcode(cb, null, null)); // PDF417 document.Add(new Paragraph("Barcode PDF417")); BarcodePDF417 pdf417 = new BarcodePDF417(); String text = "Call me Ishmael. Some years ago--never mind how long " + "precisely --having little or no money in my purse, and nothing " + "particular to interest me on shore, I thought I would sail about " + "a little and see the watery part of the world." ; pdf417.SetText(text); Image img = pdf417.GetImage(); img.ScalePercent(50, 50 * pdf417.YHeight); document.Add(img); document.Add(new Paragraph("Barcode Datamatrix")); BarcodeDatamatrix datamatrix = new BarcodeDatamatrix(); datamatrix.Generate(text); img = datamatrix.CreateImage(); document.Add(img); document.Add(new Paragraph("Barcode QRCode")); BarcodeQRCode qrcode = new BarcodeQRCode( "Moby Dick by Herman Melville", 1, 1, null ); img = qrcode.GetImage(); document.Add(img); } }
public void CreaTimbre(String dd) { BarcodePDF417 pdf417 = new BarcodePDF417(); pdf417.Options = BarcodePDF417.PDF417_USE_ASPECT_RATIO; pdf417.ErrorLevel = 8; //"<TED version='1.0'><DD><RE>97975000-5</RE><TD>33</TD><F>1</F><FE>2014-05-28</FE><RR>77777777-7</RR><RSR>Pc Factory</RSR><MNT>119000</MNT><IT1>Parlantes Multimedia 180W.</IT1><CAF version='1.0'><DA><RE>10207640-0</RE><RS>JUAN CARLOS AGUIRRE RODRIGUEZ</RS><TD>33</TD><RNG><D>1</D><H>50</H></RNG><FA>2014-05-26</FA><RSAPK><M>uJ+OZ5qO9diB/c9MoZuwPs9ltKGAS1IbEymF7W3X3ZTq6ElExVkrlfp7uDoGR0DiBndor6Vyc+X4MRbsk6KC9w==</M><E>Aw==</E></RSAPK><IDK>100</IDK></DA><FRMA algoritmo='SHA1withRSA'>SGKR9otZoN8/5sIaKFJIbo08Jbt95UBh76fcFv21lfNsgauAcyzUF0FARrMyphMagJ0zzChJzU7R/Q0mrDvYvQ==</FRMA></CAF><TSTED>2014-05-28T09:33:20</TSTED></DD><FRMT algoritmo='SHA1withRSA'>GK7FRnNjgHLyRspdygg2WudvqqJ+OQchn8k/6TUrndBBNHsFHInEN34+KLTy\nFgRG/bmDIjclV4VTlgs3TIg/7A==\n</FRMT></TED>"; pdf417.Options = BarcodePDF417.PDF417_FORCE_BINARY; Encoding iso = Encoding.GetEncoding("ISO-8859-1"); byte[] isoBytes = iso.GetBytes(dd); pdf417.Text = isoBytes; // pdf417.SetText(contenido); System.Drawing.Bitmap imagen = new Bitmap(pdf417.CreateDrawingImage(Color.Black, Color.White)); imagen.Save("Timbre.jpg"); }
private void agregarCodigoBarras(ref Document doc) { iTextSharp.text.pdf.BarcodePDF417 objBarcodePDF417 = new iTextSharp.text.pdf.BarcodePDF417(); objBarcodePDF417.SetText("*7Y0012351007181031072020*"); objBarcodePDF417.YHeight = Convert.ToSingle(1.9); objBarcodePDF417.Options = iTextSharp.text.pdf.BarcodePDF417.PDF417_FORCE_BINARY; objBarcodePDF417.ErrorLevel = 5; objBarcodePDF417.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White).Save("C:\\Users\\galvarez\\Desktop\\Ticket\\barritas.png", System.Drawing.Imaging.ImageFormat.Jpeg); // Creamos la imagen y le ajustamos el tamaño iTextSharp.text.Image imagenBarras = iTextSharp.text.Image.GetInstance("C:\\Users\\galvarez\\Desktop\\Ticket\\barritas.png"); imagenBarras.BorderWidth = 0; imagenBarras.Alignment = Element.ALIGN_LEFT; float percentageBarra = 0.0f; percentageBarra = 100 / imagenBarras.Width; imagenBarras.ScalePercent(percentageBarra * 100); doc.Add(imagenBarras); }
// --------------------------------------------------------------------------- /** * Creates a PDF document. */ public byte[] CreatePdf() { using (MemoryStream ms = new MemoryStream()) { using (Document document = new Document() ) { PdfWriter writer = PdfWriter.GetInstance(document, ms); document.Open(); Image img = null; for (int i = 0; i < RESOURCES.Length; i++) { img = Image.GetInstance(Path.Combine(Utility.ResourceImage, RESOURCES[i])); if (img.ScaledWidth > 300 || img.ScaledHeight > 300) { img.ScaleToFit(300, 300); } document.Add(new Paragraph(String.Format( "{0} is an image of type {1}", RESOURCES[i], img.GetType()) )); document.Add(img); } /* * you DO NOT want to use classes within the System.Drawing namespace to * manipulate image files in ASP.NET applications, see the warning here: * http://msdn.microsoft.com/en-us/library/system.drawing.aspx */ using (System.Drawing.Image dotnet_img = System.Drawing.Image.FromFile( Path.Combine(Utility.ResourceImage, RESOURCE) )) { img = Image.GetInstance( dotnet_img, System.Drawing.Imaging.ImageFormat.Png ); document.Add(new Paragraph(String.Format( "{0} is an image of type {1}", "System.Drawing.Image", img.GetType()) )); document.Add(img); } BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.CodeType = Barcode.EAN13; codeEAN.Code = "9781935182610"; img = codeEAN.CreateImageWithBarcode(writer.DirectContent, null, null); document.Add(new Paragraph(String.Format( "{0} is an image of type {1}", "barcode", img.GetType()) )); document.Add(img); BarcodePDF417 pdf417 = new BarcodePDF417(); string text = "iText in Action, a book by Bruno Lowagie."; pdf417.SetText(text); img = pdf417.GetImage(); document.Add(new Paragraph(String.Format( "{0} is an image of type {1}", "barcode", img.GetType()) )); document.Add(img); } return ms.ToArray(); } }
private static void Render_BackContent(PdfContentByte canvas, Member member, bool passport) { Font f = new Font(baseFont, 12, Font.BOLD); int bottom = CARD_HEIGHT - 32; Phrase p = new Phrase(member.FullName, f); ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, bottom, 0); if (passport) { bottom = CARD_HEIGHT - 170; f = new Font(baseFont, 16f, Font.BOLD); p = new Phrase("PASSPORT", f); ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, bottom, 0); } else { bottom = CARD_HEIGHT - 159; f = new Font(baseFont, 11f); p = new Phrase(member.WacLevel.ToString(), f); ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, bottom, 0); bottom -= 12; p = new Phrase("KCSO DEM# " + member.DEM, f); ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, bottom, 0); } BarcodePDF417 barcode = new BarcodePDF417(); barcode.SetText(string.Format("Unknown Text. To be added. KCSAR{0}{1}{2}", member.LastName, member.FirstName, member.DEM)); barcode.CodeRows = 9; barcode.CodeColumns = 7; barcode.Options = BarcodePDF417.PDF417_FIXED_RECTANGLE; var img = barcode.GetImage(); img.ScaleAbsolute(CARD_WIDTH - 30, 14); img.SetAbsolutePosition((CARD_WIDTH - img.ScaledWidth) / 2, 50); canvas.AddImage(img); }
private static void Render_FrontContent(PdfContentByte canvas, Member member) { Font f = new Font(baseFont, 12, Font.BOLD) { Color = BaseColor.WHITE }; int bottom = CARD_HEIGHT - (UPPER_BAR_HEIGHT + PHOTO_BAR_HEIGHT) - 12 - 2; Phrase p = new Phrase(member.FullName, f); ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, bottom, 0); bottom -= 14; f = new Font(baseFont, 12) { Color = BaseColor.WHITE }; p = new Phrase(member.WacLevel.ToString(), f); ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, bottom, 0); bottom -= 12; f = new Font(baseFont, 10, Font.BOLD) { Color = BaseColor.WHITE }; p = new Phrase("KCSO DEM# " + member.DEM, f); ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, p, CARD_WIDTH / 2, bottom, 0); BarcodePDF417 barcode = new BarcodePDF417(); barcode.SetText(string.Format("Unknown Text. To be added. King County Search and Rescue{0}{1}{2}", member.LastName, member.FirstName, member.DEM)); barcode.CodeRows = 20; barcode.CodeColumns = 7; barcode.Options = BarcodePDF417.PDF417_FIXED_RECTANGLE; var img = barcode.GetImage(); img.ScaleAbsolute(CARD_WIDTH - 30, 28); img.SetAbsolutePosition((CARD_WIDTH - img.ScaledWidth) / 2, CARD_HEIGHT - UPPER_BAR_HEIGHT - PHOTO_BAR_HEIGHT - LOWER_BAR_HEIGHT - img.ScaledHeight - 8); canvas.AddImage(img); if (!string.IsNullOrWhiteSpace(member.PhotoFile)) { var file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content", "auth", "members", member.PhotoFile); if (File.Exists(file)) { img = Image.GetInstance(file); img.ScaleToFit(PHOTO_WIDTH, PHOTO_BAR_HEIGHT); img.SetAbsolutePosition(CARD_WIDTH - img.ScaledWidth, CARD_HEIGHT - (UPPER_BAR_HEIGHT + img.ScaledHeight)); canvas.AddImage(img); } } }