private void Form1_Load(object sender, EventArgs e) { string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(216f, 1000f); Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(@"HelloWorld.pdf", FileMode.Create)); document.Open(); /* chapter05/FoxDogImageTypes.java */ iText.Image img1 = iText.Image.GetInstance(iText.Image.GetInstance(string.Concat(appPath, "\\", "fox.jpg"))); img1.Alignment = iText.Image.ALIGN_MIDDLE; img1.ScaleAbsolute(100f, 100f); document.Add(img1); /* chapter05/Barcodes.java */ PdfContentByte cb = writer.DirectContent; 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.Close(); webBrowser1.Navigate(string.Concat(appPath, "\\", @"HelloWorld.pdf")); }
public bool AddCell(PdfPTable t, string desc, int code) { var bc = new Barcode39(); bc.X = 1.2f; bc.Font = null; bc.Code = code.ToString(); var img = bc.CreateImageWithBarcode(dc, null, null); var p = new Phrase(); p.Add(new Chunk(img, 0, 0)); p.Add(new Phrase("\n" + code.ToString().Insert(3, " "), font)); p.Add(new Phrase("\n" + desc, smallfont)); var c = new PdfPCell(p); c.HorizontalAlignment = PdfPCell.ALIGN_CENTER; c.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; c.Border = PdfPCell.NO_BORDER; c.FixedHeight = H * 72f; t.AddCell(c); n++; if (n % 3 > 0) { t.AddCell(""); } return(n % 3 == 0); }
public void AddRow(PdfPTable t, string fname, string lname, string phone, int pid) { var bc = new Barcode39(); bc.X = 1.2f; bc.Font = null; bc.Code = pid.ToString(); var img = bc.CreateImageWithBarcode(dc, null, null); var p1 = new Phrase(); p1.Add(new Chunk(img, 0, 0)); p1.Add(new Phrase("\n\n" + fname + " " + lname + " (" + pid + ")", smallfont)); var c = new PdfPCell(p1); c.HorizontalAlignment = PdfPCell.ALIGN_CENTER; c.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; c.Border = PdfPCell.NO_BORDER; c.FixedHeight = H * 72f; var t2 = new PdfPTable(2); t2.WidthPercentage = 100f; t2.DefaultCell.Border = PdfPCell.NO_BORDER; var cc = new PdfPCell(new Phrase(fname, font)); cc.Border = PdfPCell.NO_BORDER; cc.Colspan = 2; t2.AddCell(cc); cc = new PdfPCell(new Phrase(lname, font)); cc.Border = PdfPCell.NO_BORDER; cc.Colspan = 2; t2.AddCell(cc); var pcell = new PdfPCell(new Phrase(pid.ToString(), smallfont)); pcell.Border = PdfPCell.NO_BORDER; pcell.HorizontalAlignment = Element.ALIGN_LEFT; t2.AddCell(pcell); pcell = new PdfPCell(new Phrase(phone.FmtFone(), smallfont)); pcell.Border = PdfPCell.NO_BORDER; pcell.HorizontalAlignment = Element.ALIGN_RIGHT; t2.AddCell(pcell); var cell = new PdfPCell(t2); cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; cell.PaddingLeft = 8f; cell.PaddingRight = 8f; cell.Border = PdfPCell.NO_BORDER; cell.FixedHeight = H * 72f; t.AddCell(c); t.AddCell(""); t.AddCell(cell); t.AddCell(""); t.AddCell(cell); }
private Image GetImage(string text, CodeType codeType, PdfContentByte pcb) { switch (codeType) { case CodeType.Code128: Barcode128 barcode128 = new Barcode128 { AltText = text, Code = text }; return(barcode128.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK)); case CodeType.Code39: Barcode39 barcode39 = new Barcode39 { Code = text, AltText = text }; return(barcode39.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK)); case CodeType.Codabar: BarcodeCodabar barcodeCodabar = new BarcodeCodabar { Code = text, AltText = text }; return(barcodeCodabar.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK)); case CodeType.Datamatrix: BarcodeDatamatrix barcodeDatamatrix = new BarcodeDatamatrix(); barcodeDatamatrix.Generate(text); return(barcodeDatamatrix.CreateImage()); case CodeType.EAN: BarcodeEAN barcodeEAN = new BarcodeEAN { CodeType = Barcode.EAN13, Code = text, AltText = text }; return(barcodeEAN.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK)); case CodeType.Inter25: BarcodeInter25 barcodeInter25 = new BarcodeInter25 { AltText = text, Code = text, GenerateChecksum = true }; return(barcodeInter25.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK)); case CodeType.PDF417: BarcodePDF417 barcodePDF417 = new BarcodePDF417(); barcodePDF417.SetText(text); return(barcodePDF417.GetImage()); case CodeType.Postnet: BarcodePostnet barcodePostnet = new BarcodePostnet { AltText = text, Code = text }; return(barcodePostnet.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK)); } return(null); }
public Image GenerateBarCode(PdfWriter writer, string data, float height) { var code39ext = new Barcode39(); code39ext.Code = data; code39ext.StartStopText = false; code39ext.Extended = false; code39ext.BarHeight = height; code39ext.Size = 5f; code39ext.Baseline = 0f; code39ext.X = 1.09f; var imageCode39 = code39ext.CreateImageWithBarcode(writer.DirectContent, null, BaseColor.WHITE); return(imageCode39); }
public void BarcodesTest1() { Document document = new Document(); PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "barcodesTest1.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_3A); writer.SetTagged(); document.Open(); writer.ViewerPreferences = PdfWriter.DisplayDocTitle; document.AddTitle("Some title"); document.AddLanguage("en-us"); writer.CreateXmpMetadata(); document.NewPage(); // Set output intent. PDF/A requirement. FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read); ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream); iccProfileFileStream.Close(); writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); // All fonts shall be embedded. PDF/A requirement. Font normal9 = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 9); Font normal8 = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 8); BaseColor color = new BaseColor(111, 211, 11); normal8.Color = color; PdfContentByte cb = writer.DirectContent; String code = "119716-500023718"; Barcode barcode = new Barcode39(); barcode.Code = code; barcode.StartStopText = false; barcode.Font = normal9.BaseFont; barcode.Extended = true; Image image = barcode.CreateImageWithBarcode(cb, color, color); image.Alt = "Bla Bla"; document.Add(image); document.Close(); }
private PdfPTable AddRow(string Code, string name, int pid, string dob, string highlight, Font font) { var t = new PdfPTable(4); //t.SplitRows = false; t.WidthPercentage = 100; t.SetWidths(new[] { 30, 4, 6, 30 }); t.DefaultCell.Border = Rectangle.NO_BORDER; var bc = new Barcode39(); bc.X = 1.2f; bc.Font = null; bc.Code = pid.ToString(); var img = bc.CreateImageWithBarcode(dc, null, null); var c = new PdfPCell(img, false); c.PaddingTop = 3f; c.Border = Rectangle.NO_BORDER; c.HorizontalAlignment = Element.ALIGN_RIGHT; t.AddCell(c); t.AddCell(""); t.AddCell(box); DateTime bd; DateTime.TryParse(dob, out bd); var p = new Phrase(name, font); p.Add("\n"); p.Add(new Chunk(" ", medfont)); p.Add(new Chunk($"({Code}) {bd:MMM d}", smallfont)); if (highlight.HasValue()) { p.Add("\n" + highlight); } t.AddCell(p); hasRows = true; return(t); }
iTextSharp.text.Image creaCodiceBarre(PdfContentByte cb, string cf, int n) { var code39ext = new Barcode39(); code39ext.Code = cf; code39ext.Font = BaseFont.CreateFont("Courier-Bold", "winansi", false); code39ext.StartStopText = false; code39ext.Extended = false; code39ext.BarHeight = 26f; code39ext.Size = 12f; code39ext.N = 3.2f; code39ext.Baseline = 12f; code39ext.X = 0.83f; iTextSharp.text.Image imageCode39 = code39ext.CreateImageWithBarcode(cb, null, null); var delta = 53 * (n - n % 2); imageCode39.SetAbsolutePosition((n % 2 == 0) ? 20 : 315, 762 - delta); return(imageCode39); }
/** * Metodo que genera un PDF con codigos de barras. * **/ private PdfPTable Codigo39(string[] datos, PdfWriter writer, int codigos_por_fila) { PdfPTable table = new PdfPTable(codigos_por_fila); table.WidthPercentage = 100; //****Se agregan elementos for (int i = 0; i < datos.Length; i++) { Barcode39 bc = new Barcode39(); PdfContentByte cb = new PdfContentByte(writer); bc.Code = datos[i]; bc.N = 3; bc.X = 1; bc.AltText = "OET - " + datos[i].ToString(); PdfPCell cell = new PdfPCell(table.DefaultCell); cell.AddElement(bc.CreateImageWithBarcode(cb, null, null)); table.AddCell(cell); } table.CompleteRow(); return(table); }
private void AddRow(string name, int pid, int?oid, Font font) { var bco = new Barcode39(); bco.X = 1.2f; bco.Font = null; bco.Code = $"M.{oid}.{pid}"; var img = bco.CreateImageWithBarcode(dc, null, null); var c = new PdfPCell(img, false); c.PaddingTop = 3f; c.Border = PdfPCell.NO_BORDER; c.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; t.AddCell(c); t.AddCell(""); t.AddCell(box); t.AddCell(name); t.AddCell($"({oid?.ToString() ?? " N/A "}, {pid})"); }
private void AddRow(string name, int pid, int?oid, Font font) { var bco = new Barcode39(); bco.X = 1.2f; bco.Font = null; bco.Code = "M.{0}.{1}".Fmt(oid, pid); var img = bco.CreateImageWithBarcode(dc, null, null); var c = new PdfPCell(img, false); c.PaddingTop = 3f; c.Border = PdfPCell.NO_BORDER; c.HorizontalAlignment = PdfPCell.ALIGN_RIGHT; t.AddCell(c); t.AddCell(""); t.AddCell(box); t.AddCell(name); t.AddCell("({0}, {1})".Fmt( oid.HasValue ? oid.ToString() : " N/A ", pid)); }
// =========================================================================== 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 Verify_Barcodes_CanBeCreated() { var pdfFilePath = TestUtils.GetOutputFileName(); var stream = new FileStream(pdfFilePath, FileMode.Create); // step 1 var document = new Document(new Rectangle(340, 842)); // step 2 PdfWriter writer = PdfWriter.GetInstance(document, stream); // step 3 document.AddAuthor(TestUtils.Author); document.Open(); // step 4 PdfContentByte cb = writer.DirectContent; // EAN 13 document.Add(new Paragraph("Barcode EAN.UCC-13")); BarcodeEan codeEan = new BarcodeEan { 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 { CodeType = Barcode.SUPP5, Code = "55999", 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 { 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 { X = 0.75f, N = 1.5f, Size = 10f, TextAlignment = Element.ALIGN_CENTER, Baseline = 10f, BarHeight = 50f, 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 { CodeType = Barcode.CODE128_UCC, 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 { GenerateChecksum = true, 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 { Code = "01234567890", CodeType = Barcode.PLANET }; document.Add(codePlanet.CreateImageWithBarcode(cb, null, null)); // CODE 39 document.Add(new Paragraph("Barcode 3 of 9")); Barcode39 code39 = new Barcode39 { Code = "ITEXT IN ACTION" }; document.Add(code39.CreateImageWithBarcode(cb, null, null)); document.Add(new Paragraph("Barcode 3 of 9 extended")); Barcode39 code39Ext = new Barcode39 { Code = "iText in Action", StartStopText = false, Extended = true }; document.Add(code39Ext.CreateImageWithBarcode(cb, null, null)); // CODABAR document.Add(new Paragraph("Codabar")); BarcodeCodabar codabar = new BarcodeCodabar { Code = "A123A", 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.Close(); stream.Dispose(); TestUtils.VerifyPdfFileIsReadable(pdfFilePath); }
private void btnExportMoviesToPDF_Click(object sender, RoutedEventArgs e) { try { if (lstReturnedMovies.HasItems) { //Exporting to PDF string folderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}\\"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } using (FileStream stream = new FileStream($"{folderPath}CreatedMovies{DateTime.Now.ToString("yyyyMMddHHmmss")}.pdf", FileMode.Create)) { Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f); var pdfWriter = PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); PdfContentByte cb = new PdfContentByte(pdfWriter); PdfPTable pdfTable = new PdfPTable(3); pdfTable.DefaultCell.Padding = 20; pdfTable.WidthPercentage = 50; pdfTable.HorizontalAlignment = Element.ALIGN_LEFT; pdfTable.DefaultCell.BorderWidth = 1; PdfPCell cell = new PdfPCell(new Phrase("Title")); pdfTable.AddCell(cell); cell = new PdfPCell(new Phrase("ID")); pdfTable.AddCell(cell); cell = new PdfPCell(new Phrase("Barcode")); pdfTable.AddCell(cell); foreach (Movie item in lstReturnedMovies.Items) { pdfTable.AddCell(item.title); pdfTable.AddCell(item.upc.ToString()); Barcode39 barcode39 = new Barcode39(); barcode39.StartStopText = true; barcode39.Code = item.upc.ToString(); iTextSharp.text.Image image39 = barcode39.CreateImageWithBarcode(cb, null, null); pdfTable.AddCell(image39); } pdfDoc.Add(pdfTable); pdfDoc.Close(); stream.Close(); } } else { MessageBox.Show("You need to create a movie first."); return; } MessageBox.Show($"Report Created Successfully", "Report Created"); } catch (Exception exp) { MessageBox.Show("Error Exporting Report!"); } }
public MemoryStream CreatePDF(string rmaNo) { var doc = new Document(); using (MemoryStream memoryStream = new MemoryStream()) { try { //string path = HttpContext.Current.Server.MapPath("../PDFs"); //writer = PdfWriter.GetInstance(doc, new FileStream(path + "/" + rmaNo + ".pdf", FileMode.Create)); writer = PdfWriter.GetInstance(doc, memoryStream); doc.Open(); barcodeByte = writer.DirectContent; mainHeading = new Paragraph("Return Merchandise Authorization Instructions", new Font(Font.HELVETICA, 20f, Font.BOLD)) { Alignment = Element.ALIGN_CENTER, SpacingAfter = 40f }; text = @"Thank you for the opportunity to help you. We understand the importance of processing your return in a timely manner. Please print this check list, complete the items below and place inside of the box to ensure prompt resolution for your return."; detail = new Paragraph(text, new Font(Font.HELVETICA, 11f)) { SpacingAfter = 40f }; heading2 = new Paragraph("All Returns:", new Font(Font.HELVETICA, 20f, Font.BOLD)) { SpacingAfter = 20f }; returnAddressList.SetListSymbol(""); returnAddressList.IndentationLeft = 30f; returnAddressList.Add(new ListItem(" ", font)); returnAddressList.Add(new ListItem("RETURNS DEPT", font)); returnAddressList.Add(new ListItem(rmaNo, font)); returnAddressList.Add(new ListItem("20000 NE, 15TH CT", font)); returnAddressList.Add(new ListItem("Miami, FL 33179", font)); returnAddressList.Add(new ListItem(" ", font)); checkList.IndentationLeft = 30f; checkList.SetListSymbol("O"); checkList.Add(new ListItem("RMA is clearly written on box along with the return address", font)); checkList.Add(returnAddressList); checkList.Add(new ListItem("Print Return Authorization sheet with the barcode and place inside box", font)); heading3 = new Paragraph("For Cell phones, Tablets or Smart watches", new Font(Font.HELVETICA, 20f, Font.BOLD)) { SpacingBefore = 20f, SpacingAfter = 20f }; checkList2.IndentationLeft = 30f; checkList2.SetListSymbol("O"); checkList2.Add(new ListItem("Remove all passwords from the device", font)); checkList2.Add(new ListItem("Go to the cloud or account and remove the device from your account", font)); checkList2.Add(new ListItem(@"Only return the device. Do not include any accessories such as cases, headphones etc.", font)); checkList2.Add(new ListItem("Remove your memory card and/or SIM card", font)); checkList2.Add(new ListItem("Remove only screen locks or passwords enabled on the device", font)); mainHeading2 = new Paragraph("Return Merchandise Authorization Sheet", new Font(Font.HELVETICA, 20f, Font.BOLD)) { Alignment = Element.ALIGN_CENTER, SpacingAfter = 20f }; subHeading = new Paragraph("Must Be Printed and Placed Inside Return Box", new Font(Font.HELVETICA, 14f, Font.BOLD | Font.UNDERLINE)) { Alignment = Element.ALIGN_CENTER, SpacingAfter = 40f }; displayRMA = new Paragraph(rmaNo, new Font(Font.HELVETICA, 20f, Font.BOLD)) { SpacingAfter = 50f }; barcode.Code = rmaNo; barcode.Size = 48f; barcode.Font = null; barcodeImage = barcode.CreateImageWithBarcode(barcodeByte, null, null); barcodeRMA = new Phrase(new Chunk(barcodeImage, 0, 0)); text = "Your RMA number is valid for 15 days. Once the return arrives it takes 3-5 business days to process."; detail2 = new Paragraph(text, new Font(Font.HELVETICA, 11f)) { SpacingBefore = 50f, SpacingAfter = 10f }; text = @"Please retain your RMA number if you need to contact us by email or phone to check the status of your return."; detail3 = new Paragraph(text, new Font(Font.HELVETICA, 11f)) { SpacingAfter = 10f }; text = @"Warranty is only for manufacturer defects, warranty doesn't cover any physical damage (cracked screen, dents) or water damage."; detail4 = new Paragraph(text, new Font(Font.HELVETICA, 11f)) { SpacingAfter = 10f }; text = @"If your device has any physical or water damage your exchange will be denied and you will be responsible to provide us with a pre-paid return label so we can ship the device back to you."; detail5 = new Paragraph(text, new Font(Font.HELVETICA, 11f)) { SpacingAfter = 20f }; thankYou = new Paragraph("Thank you,", new Font(Font.HELVETICA, 11f)) { SpacingAfter = 10f }; customerService = new Paragraph("Customer Service", new Font(Font.HELVETICA, 11f)); doc.Add(mainHeading); doc.Add(detail); doc.Add(heading2); doc.Add(checkList); doc.Add(heading3); doc.Add(checkList2); doc.NewPage(); doc.Add(mainHeading2); doc.Add(subHeading); doc.Add(displayRMA); doc.Add(barcodeRMA); doc.Add(detail2); doc.Add(detail3); doc.Add(detail4); doc.Add(detail5); doc.Add(thankYou); doc.Add(customerService); } catch (DocumentException dex) { Log.Error(dex.Message, dex); throw (dex); } catch (IOException ioex) { Log.Error(ioex.Message, ioex); throw (ioex); } catch (Exception ex) { Log.Error(ex.Message, ex); throw (ex); } finally { doc.Close(); } return(memoryStream); } }
/** * Builds an output pdf file regarding to a tube serial number, essentially it is the tube record form in output form. * Paramaters : SN-serial number, forms-List of all the information to be outputted, path-path of where the pdf should be outputted. * Return : A message of passing failing. * */ public string iTextBuildDocument(string sn, List <VTFormObject> forms, string path) { var doc = new Document(); try { var curr_serial = sn; var subtitle = 15f; var field_font_size = 10f; var form_header_font_size = 12f; PdfWriter writer = null; //String path_name = Properties.Settings.Default.FilePathOutput + sn + "_output.pdf"; //PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@path, FileMode.Create)); try { writer = PdfWriter.GetInstance(doc, new FileStream(path, FileMode.Create)); } catch (Exception e) { return(e.Message); } BaseFont helvetica = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); doc.SetMargins(0f, 0f, 0f, 0f); doc.Open(); PdfContentByte cb = writer.DirectContent; PdfPTable table = new PdfPTable(2); //table.HorizontalAlignment = Element.ALIGN_LEFT; PdfPCell main_title_cell = new PdfPCell(new Phrase("Tube Record Sheet", new Font(helvetica, 30f))); main_title_cell.Colspan = 2; main_title_cell.HorizontalAlignment = 1; table.AddCell(main_title_cell); // Serial Barcode, Image initalization Barcode39 sn_code = new Barcode39(); sn_code.Code = sn; Image sn_code_image = sn_code.CreateImageWithBarcode(cb, null, null); sn_code_image.ScalePercent(80f); Barcode39 tube_code = new Barcode39(); tube_code.Code = forms[0].TubeType; Image tube_code_image = tube_code.CreateImageWithBarcode(cb, null, null); tube_code_image.ScalePercent(80f); PdfPCell sn_image_cell = new PdfPCell(sn_code_image); sn_image_cell.HorizontalAlignment = 1; PdfPCell tube_image_cell = new PdfPCell(tube_code_image); tube_image_cell.HorizontalAlignment = 1; PdfPCell sn_label_cell = new PdfPCell(new Phrase(sn, new Font(helvetica, subtitle))); sn_label_cell.HorizontalAlignment = 1; PdfPCell tube_label_cell = new PdfPCell(new Phrase(forms[0].TubeType, new Font(helvetica, subtitle))); tube_label_cell.HorizontalAlignment = 1; table.AddCell(sn_label_cell); table.AddCell(sn_image_cell); table.AddCell(tube_image_cell); table.AddCell(tube_label_cell); int cell_count = 0; for (int i = 0; i < forms.Count; i++) { int j = 0; if (curr_serial != forms[i].SerialNumber) { doc.Add(table); // Add the last table to the document table = new PdfPTable(2); // Reset the table curr_serial = forms[i].SerialNumber; // Set the current serial to current doc.NewPage(); // Page break; PdfPCell curr_title_cell = new PdfPCell(new Phrase(forms[i].TubeType, new Font(helvetica, 30f))); curr_title_cell.Colspan = 2; curr_title_cell.HorizontalAlignment = 1; table.AddCell(curr_title_cell); cell_count = cell_count + 2; // Adds a serial number as a title to the new page break. PdfPCell curr_sn_cell = new PdfPCell(new Phrase(curr_serial, new Font(helvetica, 20f))); curr_sn_cell.Colspan = 2; curr_sn_cell.HorizontalAlignment = 1; table.AddCell(curr_sn_cell); cell_count = cell_count + 2; } // If i is not even add a blank cell. if (!((cell_count % 2) == 0)) { table.AddCell(""); cell_count++; } PdfPCell header_cell = new PdfPCell(new Phrase(forms[i].HeaderTitle, new Font(helvetica, form_header_font_size, Font.BOLD))); header_cell.Colspan = 2; header_cell.HorizontalAlignment = 1; table.AddCell(header_cell); cell_count = cell_count + 2; // Timestamp PdfPCell timestamp_cell = new PdfPCell(new Phrase("Date: " + forms[i].TimeStamp, new Font(helvetica, field_font_size))); table.AddCell(timestamp_cell); cell_count++; for (j = 0; j < forms[i].FieldList.Count; j++) { PdfPCell field_cell = new PdfPCell(new Phrase(forms[i].FieldList[j].Label + forms[i].FieldList[j].Value, new Font(helvetica, field_font_size))); table.AddCell(field_cell); cell_count++; } } doc.Add(table); doc.Close(); // Copy over to the Shared Drive //File.Copy("@" + path, "@" + Properties.Settings.Default.SharedMappedOutput); String dest_path = Properties.Settings.Default.SharedMappedOutput; String test = Path.Combine(dest_path, Path.GetFileName(path)); File.Copy(path, Path.Combine(@dest_path, @Path.GetFileName(path))); } catch (Exception e) { doc.Close(); return(e.Message); } return(null); }
public override void OnEndPage(PdfWriter writer, Document document) { base.OnEndPage(writer, document); if (npages.juststartednewset) { EndPageSet(); } string text; float len; //---Header left text = HeadText; const float HeadFontSize = 11f; len = font.GetWidthPoint(text, HeadFontSize); dc.BeginText(); dc.SetFontAndSize(font, HeadFontSize); dc.SetTextMatrix(30, document.PageSize.Height - 30); dc.ShowText(text); dc.EndText(); dc.BeginText(); dc.SetFontAndSize(font, HeadFontSize); dc.SetTextMatrix(30, document.PageSize.Height - 30 - (HeadFontSize * 1.5f)); dc.ShowText(HeadText2); dc.EndText(); //---Barcode right var bc = new Barcode39(); bc.Font = null; bc.Code = Barcode; bc.X = 1.2f; var img = bc.CreateImageWithBarcode(dc, null, null); var h = font.GetAscentPoint(text, HeadFontSize); img.SetAbsolutePosition(document.PageSize.Width - img.Width - 30, document.PageSize.Height - 30 - img.Height + h); dc.AddImage(img); //---Column 1 text = "Page " + (pg) + " of "; len = font.GetWidthPoint(text, 8); dc.BeginText(); dc.SetFontAndSize(font, 8); dc.SetTextMatrix(30, 30); dc.ShowText(text); dc.EndText(); dc.AddTemplate(npages.template, 30 + len, 30); npages.n = pg++; //---Column 2 text = "Attendance Rollsheet"; len = font.GetWidthPoint(text, 8); dc.BeginText(); dc.SetFontAndSize(font, 8); dc.SetTextMatrix(document.PageSize.Width / 2 - len / 2, 30); dc.ShowText(text); dc.EndText(); //---Column 3 text = Util.Now.ToShortDateString(); len = font.GetWidthPoint(text, 8); dc.BeginText(); dc.SetFontAndSize(font, 8); dc.SetTextMatrix(document.PageSize.Width - 30 - len, 30); dc.ShowText(text); dc.EndText(); }
/* a method that save the packing slip pdf */ public static void CreatePackingSlip(GiantTigerValues value, int[] cancelIndex, bool preview) { // the case if all of the items in the order are cancelled -> don't need to print the packing slip if (cancelIndex.Length >= value.VendorSku.Count) { return; } // first check if the save directory exist -> if not create it if (!File.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } // initialize fields Document doc = new Document(PageSize.LETTER, 0, 0, 0, 0); string file = SavePath + "\\" + value.PoNumber + ".pdf"; PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(file, FileMode.Create)); // open the documents doc.Open(); PdfContentByte contentByte = writer.DirectContent; PdfContentByte draw = writer.DirectContent; #region Logo and Barcode Set Up // add giant tiger logo Image logo = Image.GetInstance(Properties.Resources.giantTigerPackSlip, System.Drawing.Imaging.ImageFormat.Png); logo.ScalePercent(20f); logo.SetAbsolutePosition(40f, doc.PageSize.Height - 100f); doc.Add(logo); // add barcode Barcode39 barcode39 = new Barcode39 { Code = value.OmsOrderNumber, StartStopText = false, Font = null, Extended = true }; Image image = barcode39.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(40f); image.SetAbsolutePosition(340f, doc.PageSize.Height - 80f); contentByte.AddImage(image); #endregion // initialize local fields for text BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false); BaseFont boldFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false); CMYKColor white = new CMYKColor(0f, 0f, 0f, 0f); CMYKColor black = new CMYKColor(0f, 0f, 0f, 1f); ColumnText ct = new ColumnText(draw); #region Sold To // sold to Phrase text = new Phrase("SOLD TO / VENDU A", new Font(boldFont, 10)); ct.SetSimpleColumn(text, 40f, 655f, 200f, 670f, 0f, Element.ALIGN_LEFT); ct.Go(); // sold to address text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City + ", " + value.ShipTo.State + ' ' + value.ShipTo.PostalCode + "\nCanada", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 42f, 568f, 177f, 668f, 10f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Ship To // ship to text = new Phrase("SHIP TO / EXPEDIE A", new Font(boldFont, 10f)); ct.SetSimpleColumn(text, 300f, 655f, 450f, 670f, 0f, Element.ALIGN_LEFT); ct.Go(); // ship to address text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City + ", " + value.ShipTo.State + ' ' + value.ShipTo.PostalCode + "\nCanada\n" + value.ShipTo.DayPhone, new Font(baseFont, 9f)); ct.SetSimpleColumn(text, 302f, 568f, 447f, 668f, 10f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Draw First Box draw.SetColorFill(black); draw.MoveTo(40f, 580f); draw.LineTo(doc.PageSize.Width - 40f, 580f); draw.LineTo(doc.PageSize.Width - 40f, 543f); draw.LineTo(40f, 543f); draw.LineTo(40f, 580f); draw.ClosePathFillStroke(); draw.SetColorStroke(white); draw.MoveTo(160f, 580f); draw.LineTo(160f, 543f); draw.Stroke(); draw.MoveTo(280f, 580f); draw.LineTo(280f, 543f); draw.Stroke(); draw.MoveTo(320f, 580f); draw.LineTo(320f, 543f); draw.Stroke(); draw.MoveTo(500f, 580f); draw.LineTo(500f, 543f); draw.Stroke(); draw.SetColorStroke(black); draw.MoveTo(40f, 543f); draw.LineTo(40f, 530f); draw.Stroke(); draw.MoveTo(40f, 530f); draw.LineTo(doc.PageSize.Width - 40f, 530f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 530f); draw.LineTo(doc.PageSize.Width - 40f, 543f); draw.Stroke(); draw.MoveTo(160f, 543f); draw.LineTo(160f, 530f); draw.Stroke(); draw.MoveTo(280f, 543f); draw.LineTo(280f, 530f); draw.Stroke(); draw.MoveTo(320f, 543f); draw.LineTo(320f, 530f); draw.Stroke(); draw.MoveTo(500f, 543f); draw.LineTo(500f, 530f); draw.Stroke(); #endregion #region Messgae in First Box text = new Phrase("SHIPPING METHOD \\\nMODE D'EXPEDITION", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 40f, 550f, 160f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("ORDER DATE \\\nDATE DE LA\nCOMMANDE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 160f, 540f, 280f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("PAGE", new Font(boldFont, 10, Font.NORMAL, new CMYKColor(0f, 0f, 0f, 0f))); ct.SetSimpleColumn(text, 280f, 550f, 320f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("ORDER NUMBER \\\nNUMERO DE COMMANDE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 320f, 550f, 500f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("PO NUMBER \\\nBON DE\nCOMMANDE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 500f, 540f, doc.PageSize.Width - 40f, 580f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("Canada Post Ground", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 40f, 523f, 160f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase(value.OrderDate.ToString("MM/dd/yyyy"), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 160f, 523f, 280f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("1 of 1", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 280f, 523f, 320f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase(value.WebOrderNo, new Font(baseFont, 10)); ct.SetSimpleColumn(text, 320f, 523f, 500f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase(value.PoNumber, new Font(baseFont, 10)); ct.SetSimpleColumn(text, 500f, 523f, doc.PageSize.Width - 40f, 533f, 0f, Element.ALIGN_CENTER); ct.Go(); #endregion #region Draw Second Box draw.MoveTo(40f, 520f); draw.LineTo(doc.PageSize.Width - 40f, 520f); draw.LineTo(doc.PageSize.Width - 40f, 483f); draw.LineTo(40f, 483f); draw.LineTo(40f, 520f); draw.ClosePathFillStroke(); draw.SetColorStroke(white); draw.MoveTo(130f, 520f); draw.LineTo(130f, 483f); draw.Stroke(); draw.MoveTo(220f, 520f); draw.LineTo(220f, 483f); draw.Stroke(); draw.MoveTo(400f, 520f); draw.LineTo(400f, 483f); draw.Stroke(); draw.MoveTo(480f, 520f); draw.LineTo(480f, 483f); draw.Stroke(); #endregion #region Message in Second Box text = new Phrase("QTY ORDERED \\\nQTE\nCOMMANDEE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 40f, 480f, 130f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("ITEM \\\nARTICLE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 130f, 480f, 220f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("DESCRIPTION", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 220f, 480f, 400f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("QTY SHIPPED \\\nQTE EXPEDIEE", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 400f, 480f, 480f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); text = new Phrase("VENDOR SKU \\\nNO D'ARTICLE DU\nFOURNISSEUR", new Font(boldFont, 10, Font.NORMAL, white)); ct.SetSimpleColumn(text, 480f, 480f, doc.PageSize.Width - 40f, 520f, 11f, Element.ALIGN_CENTER); ct.Go(); // item addition draw.SetColorStroke(black); draw.SetLineWidth(0.25f); float height = 480f; // adding items for (int i = 0; i < value.VendorSku.Count; i++) { // if the item is cancelled, skip this item if (cancelIndex.Any(j => i == j)) { continue; } // draw box draw.MoveTo(40f, height); draw.LineTo(40f, height - 10f); draw.Stroke(); draw.MoveTo(40f, height - 10f); draw.LineTo(doc.PageSize.Width - 40f, height - 10f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, height - 10f); draw.LineTo(doc.PageSize.Width - 40f, height); draw.Stroke(); draw.MoveTo(130f, height); draw.LineTo(130f, height - 10f); draw.Stroke(); draw.MoveTo(220f, height); draw.LineTo(220f, height - 10f); draw.Stroke(); draw.MoveTo(400f, height); draw.LineTo(400f, height - 10f); draw.Stroke(); draw.MoveTo(480f, height); draw.LineTo(480f, height - 10f); draw.Stroke(); // qty text = new Phrase(value.Quantity[i].ToString(), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 40f, height - 19f, 130, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // item text = new Phrase(value.ClientItemId[i], new Font(baseFont, 10)); ct.SetSimpleColumn(text, 130f, height - 19f, 220f, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // description text = new Phrase("", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 220f, height - 19f, 400f, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // qty shipped text = new Phrase(value.Quantity[i].ToString(), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 400f, height - 19f, 480f, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // vendor sku text = new Phrase(value.VendorSku[i], new Font(baseFont, 10)); ct.SetSimpleColumn(text, 480f, height - 19f, doc.PageSize.Width - 40f, height - 9f, 0f, Element.ALIGN_CENTER); ct.Go(); // decrease height for next item height -= 10f; } #endregion #region Ending Boxes #region Top Box // restore width draw.SetLineWidth(1f); // draw box draw.MoveTo(40f, 250f); draw.LineTo(doc.PageSize.Width - 40f, 250f); draw.LineTo(doc.PageSize.Width - 40f, 235f); draw.LineTo(40f, 235f); draw.LineTo(40f, 250f); draw.ClosePathFillStroke(); // message in the box text = new Phrase("Thank you for ordering from Giant Tiger! Merci d’avoir placé une commande chez Tigre Géant!", new Font(boldFont, 10f, Font.NORMAL, white)); ct.SetSimpleColumn(text, 40f, 224f, doc.PageSize.Width - 40f, 239f, 0f, Element.ALIGN_CENTER); ct.Go(); #endregion #region Bottom Box // draw box draw.MoveTo(40f, 225f); draw.LineTo(doc.PageSize.Width - 40f, 225f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 225f); draw.LineTo(doc.PageSize.Width - 40f, 50f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width - 40f, 50f); draw.LineTo(40f, 50f); draw.Stroke(); draw.MoveTo(40f, 50f); draw.LineTo(40f, 225f); draw.Stroke(); draw.MoveTo(doc.PageSize.Width / 2, 225f); draw.LineTo(doc.PageSize.Width / 2, 50f); draw.Stroke(); // message in the left box text = new Phrase("Didn't receive your entire order or questions about your order?\n" + "You may receive your order in separate shipments. To track your order status. Please log into My Account at gianttiger.com.\n\r" + "Want to Return or Exchange an Item?\n" + "If you are not satisfied with your order for any reason please contact our Customer Service Team at 1-844-99-GIANT (44268) or email [email protected]. " + "For in-store returns or exchanges, your shipment confirmation email is required. To review our return policy, please visit gianttiger.com/ReturnPolicy.", new Font(baseFont, 9f)); ct.SetSimpleColumn(text, 50f, 55f, doc.PageSize.Width / 2 - 10, 225f, 10f, Element.ALIGN_LEFT); ct.Go(); // message in the right box text = new Phrase("Votre commande est incomplète ou vous avez des questions à son sujet?\n" + "Il se peut que vous receviez votre commande dans des envois distincts. Pour suivre l'état de votre commande, s’il vous plaît vous connecter à Mon Compte au tigregeant.com.\n\r" + "Vous voulez retourner ou échanger un article?\nSi vous n'êtes pas satisfait avec votre achat, veuillez communiquer avec notre service à la clientèle au 1-844-99-GIANT (44268) " + "ou envoyer un courriel à [email protected]. Les échanges et les remboursements peuvent être effectués à n’importe quel de nos magasins avec la présentation du courriel confirmant " + "l'expédition de votre commande. Pour consulter notre politique de retour, s'il vous plaît visitez tigregeant.com/PolitiqueRetour.", new Font(baseFont, 9f)); ct.SetSimpleColumn(text, doc.PageSize.Width / 2 + 10f, 55f, doc.PageSize.Width - 50f, 225f, 10f, Element.ALIGN_LEFT); ct.Go(); #endregion #endregion doc.Close(); if (!preview) { return; } // start the pdf for previewing if (System.Diagnostics.Process.GetProcessesByName(file).Length < 1) { System.Diagnostics.Process.Start(file); } }
public Chap0907() { Console.WriteLine("Chapter 9 example 7: Barcodes without ttf"); // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); try { // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0907.pdf", FileMode.Create)); // step 3: we open the document document.Open(); // step 4: we add content to the document PdfContentByte cb = writer.DirectContent; Barcode39 code39 = new Barcode39(); code39.Code = "CODE39-1234567890"; code39.StartStopText = false; Image image39 = code39.CreateImageWithBarcode(cb, null, null); Barcode39 code39ext = new Barcode39(); code39ext.Code = "The willows."; code39ext.StartStopText = false; code39ext.Extended = true; Image image39ext = code39ext.CreateImageWithBarcode(cb, null, null); Barcode128 code128 = new Barcode128(); code128.Code = "1Z234786 hello"; Image image128 = code128.CreateImageWithBarcode(cb, null, null); BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.CodeType = BarcodeEAN.EAN13; codeEAN.Code = "9780201615883"; Image imageEAN = codeEAN.CreateImageWithBarcode(cb, null, null); BarcodeInter25 code25 = new BarcodeInter25(); code25.GenerateChecksum = true; code25.Code = "41-1200076041-001"; Image image25 = code25.CreateImageWithBarcode(cb, null, null); BarcodePostnet codePost = new BarcodePostnet(); codePost.Code = "12345"; Image imagePost = codePost.CreateImageWithBarcode(cb, null, null); BarcodePostnet codePlanet = new BarcodePostnet(); codePlanet.Code = "50201402356"; codePlanet.CodeType = BarcodePostnet.PLANET; Image imagePlanet = codePlanet.CreateImageWithBarcode(cb, null, null); PdfTemplate tp = cb.CreateTemplate(0, 0); PdfTemplate ean = codeEAN.CreateTemplateWithBarcode(cb, null, new Color(System.Drawing.Color.Blue)); BarcodeEAN codeSUPP = new BarcodeEAN(); codeSUPP.CodeType = BarcodeEAN.SUPP5; codeSUPP.Code = "54995"; codeSUPP.Baseline = -2; BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP); Image imageEANSUPP = eanSupp.CreateImageWithBarcode(cb, null, new Color(System.Drawing.Color.Blue)); PdfPTable table = new PdfPTable(2); table.WidthPercentage = 100; table.DefaultCell.Border = Rectangle.NO_BORDER; table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; table.DefaultCell.FixedHeight = 70; table.AddCell("CODE 39"); table.AddCell(new Phrase(new Chunk(image39, 0, 0))); table.AddCell("CODE 39 EXTENDED"); table.AddCell(new Phrase(new Chunk(image39ext, 0, 0))); table.AddCell("CODE 128"); table.AddCell(new Phrase(new Chunk(image128, 0, 0))); table.AddCell("CODE EAN"); table.AddCell(new Phrase(new Chunk(imageEAN, 0, 0))); table.AddCell("CODE EAN\nWITH\nSUPPLEMENTAL 5"); table.AddCell(new Phrase(new Chunk(imageEANSUPP, 0, 0))); table.AddCell("CODE INTERLEAVED"); table.AddCell(new Phrase(new Chunk(image25, 0, 0))); table.AddCell("CODE POSTNET"); table.AddCell(new Phrase(new Chunk(imagePost, 0, 0))); table.AddCell("CODE PLANET"); table.AddCell(new Phrase(new Chunk(imagePlanet, 0, 0))); document.Add(table); } catch (Exception de) { Console.Error.WriteLine(de.StackTrace); } // step 5: we close the document document.Close(); }