| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap09 | |
| 8: | { | |
| 9: | /// <summary> | |
| 10: | /// Barcodes without ttf | |
| 11: | /// </summary> | |
| 12: | public class Chap0907 | |
| 13: | { | |
| 14: | public Chap0907() | |
| 15: | { | |
| 16: | ||
| 17: | Console.WriteLine("Chapter 9 example 7: Barcodes without ttf"); | |
| 18: | ||
| 19: | // step 1: creation of a document-object | |
| 20: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
| 21: | ||
| 22: | try | |
| 23: | { | |
| 24: | ||
| 25: | // step 2: | |
| 26: | // we create a writer that listens to the document | |
| 27: | // and directs a PDF-stream to a file | |
| 28: | ||
| 29: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0907.pdf", FileMode.Create)); | |
| 30: | ||
| 31: | // step 3: we open the document | |
| 32: | document.Open(); | |
| 33: | ||
| 34: | // step 4: we add content to the document | |
| 35: | PdfContentByte cb = writer.DirectContent; | |
| 36: | Barcode39 code39 = new Barcode39(); | |
| 37: | code39.Code = "CODE39-1234567890"; | |
| 38: | code39.StartStopText = false; | |
| 39: | Image image39 = code39.CreateImageWithBarcode(cb, null, null); | |
| 40: | Barcode39 code39ext = new Barcode39(); | |
| 41: | code39ext.Code = "The willows."; | |
| 42: | code39ext.StartStopText = false; | |
| 43: | code39ext.Extended = true; | |
| 44: | Image image39ext = code39ext.CreateImageWithBarcode(cb, null, null); | |
| 45: | Barcode128 code128 = new Barcode128(); | |
| 46: | code128.Code = "1Z234786 hello"; | |
| 47: | Image image128 = code128.CreateImageWithBarcode(cb, null, null); | |
| 48: | BarcodeEAN codeEAN = new BarcodeEAN(); | |
| 49: | codeEAN.CodeType = BarcodeEAN.EAN13; | |
| 50: | codeEAN.Code = "9780201615883"; | |
| 51: | Image imageEAN = codeEAN.CreateImageWithBarcode(cb, null, null); | |
| 52: | BarcodeInter25 code25 = new BarcodeInter25(); | |
| 53: | code25.GenerateChecksum = true; | |
| 54: | code25.Code = "41-1200076041-001"; | |
| 55: | Image image25 = code25.CreateImageWithBarcode(cb, null, null); | |
| 56: | BarcodePostnet codePost = new BarcodePostnet(); | |
| 57: | codePost.Code = "12345"; | |
| 58: | Image imagePost = codePost.CreateImageWithBarcode(cb, null, null); | |
| 59: | BarcodePostnet codePlanet = new BarcodePostnet(); | |
| 60: | codePlanet.Code = "50201402356"; | |
| 61: | codePlanet.CodeType = BarcodePostnet.PLANET; | |
| 62: | Image imagePlanet = codePlanet.CreateImageWithBarcode(cb, null, null); | |
| 63: | PdfTemplate tp = cb.CreateTemplate(0, 0); | |
| 64: | PdfTemplate ean = codeEAN.CreateTemplateWithBarcode(cb, null, new Color(System.Drawing.Color.Blue)); | |
| 65: | BarcodeEAN codeSUPP = new BarcodeEAN(); | |
| 66: | codeSUPP.CodeType = BarcodeEAN.SUPP5; | |
| 67: | codeSUPP.Code = "54995"; | |
| 68: | codeSUPP.Baseline = -2; | |
| 69: | BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP); | |
| 70: | Image imageEANSUPP = eanSupp.CreateImageWithBarcode(cb, null, new Color(System.Drawing.Color.Blue)); | |
| 71: | PdfPTable table = new PdfPTable(2); | |
| 72: | table.WidthPercentage = 100; | |
| 73: | table.DefaultCell.Border = Rectangle.NO_BORDER; | |
| 74: | table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; | |
| 75: | table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; | |
| 76: | table.DefaultCell.FixedHeight = 70; | |
| 77: | table.AddCell("CODE 39"); | |
| 78: | table.AddCell(new Phrase(new Chunk(image39, 0, 0))); | |
| 79: | table.AddCell("CODE 39 EXTENDED"); | |
| 80: | table.AddCell(new Phrase(new Chunk(image39ext, 0, 0))); | |
| 81: | table.AddCell("CODE 128"); | |
| 82: | table.AddCell(new Phrase(new Chunk(image128, 0, 0))); | |
| 83: | table.AddCell("CODE EAN"); | |
| 84: | table.AddCell(new Phrase(new Chunk(imageEAN, 0, 0))); | |
| 85: | table.AddCell("CODE EAN\nWITH\nSUPPLEMENTAL 5"); | |
| 86: | table.AddCell(new Phrase(new Chunk(imageEANSUPP, 0, 0))); | |
| 87: | table.AddCell("CODE INTERLEAVED"); | |
| 88: | table.AddCell(new Phrase(new Chunk(image25, 0, 0))); | |
| 89: | table.AddCell("CODE POSTNET"); | |
| 90: | table.AddCell(new Phrase(new Chunk(imagePost, 0, 0))); | |
| 91: | table.AddCell("CODE PLANET"); | |
| 92: | table.AddCell(new Phrase(new Chunk(imagePlanet, 0, 0))); | |
| 93: | document.Add(table); | |
| 94: | } | |
| 95: | catch (Exception de) | |
| 96: | { | |
| 97: | Console.Error.WriteLine(de.StackTrace); | |
| 98: | } | |
| 99: | ||
| 100: | // step 5: we close the document | |
| 101: | document.Close(); | |
| 102: | } | |
| 103: | } | |
| 104: | } |