public static void AddBarcodeSeqence(string file, int step, List <string> barcodeList, int x, int y, bool replaceSource) { using (var ms = new MemoryStream()) { using (var reader = new PdfReader(file)) using (var stamper = new PdfStamper(reader, ms)) { for (int i = 1; i <= reader.NumberOfPages; i += step) { try { if (reader.NumberOfPages % step > 0) { throw new Exception("Заданный интервал step не вмещается в кол-во страниц целое число раз"); } if (barcodeList[i - 1].Length != 14) { throw new Exception(string.Format("Длина штрихкода #{0} должна быть 14 символов", i + 1)); } var stCb = stamper.GetOverContent(i); var bc = new BarcodeInter25() { Code = barcodeList[i - 1] }; stCb.SetColorFill(BaseColor.WHITE); stCb.SetColorStroke(BaseColor.WHITE); stCb.MoveTo(x - 15, y + 45); stCb.LineTo(x + 165, y + 45); stCb.LineTo(x + 165, y); stCb.LineTo(x - 15, y); stCb.Fill(); var bc_image = bc.CreateImageWithBarcode(stCb, BaseColor.BLACK, BaseColor.BLACK); bc_image.SetAbsolutePosition(x, y); bc_image.ScalePercent(117F); stCb.AddImage(bc_image); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error in PTools.dll", MessageBoxButton.OK, MessageBoxImage.Error); } } } ms.Flush(); if (replaceSource) { File.WriteAllBytes(file, ms.ToArray()); } else { File.WriteAllBytes(file.Insert(file.Length - 4, "_out"), ms.ToArray()); } } }
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 static void AddBarcode(string file, int page, string barcode, int x, int y, bool replaceSource) { try { using (var ms = new MemoryStream()) { using (var reader = new PdfReader(file)) using (var stamper = new PdfStamper(reader, ms)) { if (page < 1 || page > reader.NumberOfPages) { throw new Exception("Номер страницы для вставки штрихкода не входит в диапазон страниц файла"); } if (barcode.Length != 14) { throw new Exception("Длина штрихкода должна быть 14 символов"); } var stCb = stamper.GetOverContent(2); var bc = new BarcodeInter25() { Code = barcode }; stCb.SetColorFill(BaseColor.WHITE); stCb.SetColorStroke(BaseColor.WHITE); stCb.MoveTo(x - 15, y + 45); stCb.LineTo(x + 165, y + 45); stCb.LineTo(x + 165, y); stCb.LineTo(x - 15, y); stCb.Fill(); var bc_image = bc.CreateImageWithBarcode(stCb, BaseColor.BLACK, BaseColor.BLACK); bc_image.SetAbsolutePosition(x, y); bc_image.ScalePercent(117F); stCb.AddImage(bc_image); } ms.Flush(); if (replaceSource) { File.WriteAllBytes(file, ms.ToArray()); } else { File.WriteAllBytes(file.Insert(file.Length - 4, "_out"), ms.ToArray()); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error in PTools.dll", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Generar el Barcode 25 /// </summary> /// <param name="text">Mensaje que será pasado a 25</param> /// <param name="pdfDoc">PdfDocument del documento original</param> /// <returns>Retornar el barcode en una imágen</returns> private Image GetBarcode25(PdfDocument pdfDoc) { BarcodeInter25 barcode25 = new BarcodeInter25(pdfDoc); barcode25.SetCode("0600123456"); Image barcode = new Image(barcode25.CreateFormXObject(pdfDoc)); barcode.Scale(2, 2); barcode.SetHorizontalAlignment(HorizontalAlignment.LEFT); barcode.SetMarginLeft(20); barcode.SetMarginTop(10); return(barcode); }
public virtual void BarcodeInter25Test() { String outPdf = destinationFolder + "barcodeInter25Test.pdf"; String cmpPdf = cmpFolder + "cmp_barcodeInter25Test.pdf"; Document doc = CreatePdfATaggedDocument(outPdf); PdfFont font = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true); font.SetSubset(true); BarcodeInter25 codeInter25 = new BarcodeInter25(doc.GetPdfDocument(), font); FillBarcode1D(codeInter25, "1234567"); PdfFormXObject barcode = codeInter25.CreateFormXObject(doc.GetPdfDocument()); Image img = new Image(barcode).SetMargins(0, 0, 0, 0); img.GetAccessibilityProperties().SetAlternateDescription("hello world!"); doc.Add(img); doc.Close(); CompareResult(outPdf, cmpPdf); }
public IActionResult BarCode() { Document doc = new Document(PageSize.A4); doc.SetMargins(85f, 28.34f, 85f, 28.34f); // Igual a un cm MemoryStream ms = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(doc, ms); doc.AddAuthor("Carlos D Agostino"); doc.AddTitle("Pdf BarCode"); doc.Open(); BarcodeInter25 code25 = new BarcodeInter25(); Rectangle r = new iTextSharp.text.Rectangle(38, 152); code25.ChecksumText = false; code25.Code = "1462029681051408202019603171969320"; code25.BarHeight = 40; PdfContentByte cb = writer.DirectContent; iTextSharp.text.Image img = code25.CreateImageWithBarcode(cb, null, null); doc.Add(img); doc.Add(new Paragraph()); writer.Close(); doc.Close(); ms.Seek(0, SeekOrigin.Begin); //file.Dispose(); //return File(new FileStream("hola mundo.pdf",FileMode.Open,FileAccess.Read),"application/pdf"); return(File(ms.ToArray(), "application/pdf")); }
public void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc, new PageSize(340, 842)); // The default barcode EAN 13 type doc.Add(new Paragraph("Barcode EAN.UCC-13")); BarcodeEAN codeEAN = new BarcodeEAN(pdfDoc); codeEAN.SetCode("4512345678906"); doc.Add(new Paragraph("default:")); codeEAN.FitWidth(250); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); codeEAN.SetGuardBars(false); doc.Add(new Paragraph("without guard bars:")); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); codeEAN.SetBaseline(-1); codeEAN.SetGuardBars(true); doc.Add(new Paragraph("text above:")); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); codeEAN.SetBaseline(codeEAN.GetSize()); // Barcode EAN UPC A type doc.Add(new Paragraph("Barcode UCC-12 (UPC-A)")); codeEAN.SetCodeType(BarcodeEAN.UPCA); codeEAN.SetCode("785342304749"); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); // Barcode EAN 8 type doc.Add(new Paragraph("Barcode EAN.UCC-8")); codeEAN.SetCodeType(BarcodeEAN.EAN8); codeEAN.SetBarHeight(codeEAN.GetSize() * 1.5f); codeEAN.SetCode("34569870"); codeEAN.FitWidth(250); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); // Barcode UPC E type doc.Add(new Paragraph("Barcode UPC-E")); codeEAN.SetCodeType(BarcodeEAN.UPCE); codeEAN.SetCode("03456781"); codeEAN.FitWidth(250); doc.Add(new Image(codeEAN.CreateFormXObject(pdfDoc))); codeEAN.SetBarHeight(codeEAN.GetSize() * 3); // Barcode EANSUPP type doc.Add(new Paragraph("Bookland - BarcodeEANSUPP")); doc.Add(new Paragraph("ISBN 0-321-30474-8")); codeEAN = new BarcodeEAN(pdfDoc); codeEAN.SetCodeType(BarcodeEAN.EAN13); codeEAN.SetCode("9781935182610"); BarcodeEAN codeSUPP = new BarcodeEAN(pdfDoc); codeSUPP.SetCodeType(BarcodeEAN.SUPP5); codeSUPP.SetCode("55999"); codeSUPP.SetBaseline(-2); BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP); doc.Add(new Image(eanSupp.CreateFormXObject(null, ColorConstants.BLUE, pdfDoc))); // Barcode CODE 128 type doc.Add(new Paragraph("Barcode 128")); Barcode128 code128 = new Barcode128(pdfDoc); code128.SetCode("0123456789 hello"); code128.FitWidth(250); doc.Add(new Image(code128.CreateFormXObject(pdfDoc)) .SetRotationAngle(Math.PI / 2) .SetMargins(10, 10, 10, 10)); code128.SetCode("0123456789\uffffMy Raw Barcode (0 - 9)"); code128.SetCodeType(Barcode128.CODE128_RAW); code128.FitWidth(250); doc.Add(new Image(code128.CreateFormXObject(pdfDoc))); // 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(pdfDoc); shipBarCode.SetX(0.75f); shipBarCode.SetN(1.5f); shipBarCode.SetSize(10f); shipBarCode.SetTextAlignment(Barcode1D.ALIGN_CENTER); shipBarCode.SetBaseline(10f); shipBarCode.SetBarHeight(50f); shipBarCode.SetCode(data.ToString()); shipBarCode.FitWidth(250); doc.Add(new Image(shipBarCode.CreateFormXObject(ColorConstants.BLACK, ColorConstants.BLUE, pdfDoc))); // CODE 128 type barcode, which is composed of 3 blocks with AI 01, 3101 and 10 Barcode128 uccEan128 = new Barcode128(pdfDoc); uccEan128.SetCodeType(Barcode128.CODE128_UCC); uccEan128.SetCode("(01)00000090311314(10)ABC123(15)060916"); uccEan128.FitWidth(250); doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.BLACK, pdfDoc))); uccEan128.SetCode("0191234567890121310100035510ABC123"); uccEan128.FitWidth(250); doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.RED, pdfDoc))); uccEan128.SetCode("(01)28880123456788"); uccEan128.FitWidth(250); doc.Add(new Image(uccEan128.CreateFormXObject(ColorConstants.BLUE, ColorConstants.BLACK, pdfDoc))); // Barcode INTER25 type doc.Add(new Paragraph("Barcode Interrevealed 2 of 5")); BarcodeInter25 code25 = new BarcodeInter25(pdfDoc); code25.SetGenerateChecksum(true); code25.SetCode("41-1200076041-001"); code25.FitWidth(250); doc.Add(new Image(code25.CreateFormXObject(pdfDoc))); code25.SetCode("411200076041001"); code25.FitWidth(250); doc.Add(new Image(code25.CreateFormXObject(pdfDoc))); code25.SetCode("0611012345678"); code25.SetChecksumText(true); code25.FitWidth(250); doc.Add(new Image(code25.CreateFormXObject(pdfDoc))); // Barcode POSTNET type doc.Add(new Paragraph("Barcode Postnet")); BarcodePostnet codePost = new BarcodePostnet(pdfDoc); doc.Add(new Paragraph("ZIP")); codePost.SetCode("01234"); codePost.FitWidth(250); doc.Add(new Image(codePost.CreateFormXObject(pdfDoc))); doc.Add(new Paragraph("ZIP+4")); codePost.SetCode("012345678"); codePost.FitWidth(250); doc.Add(new Image(codePost.CreateFormXObject(pdfDoc))); doc.Add(new Paragraph("ZIP+4 and dp")); codePost.SetCode("01234567890"); codePost.FitWidth(250); doc.Add(new Image(codePost.CreateFormXObject(pdfDoc))); // Barcode PLANET type doc.Add(new Paragraph("Barcode Planet")); BarcodePostnet codePlanet = new BarcodePostnet(pdfDoc); codePlanet.SetCode("01234567890"); codePlanet.SetCodeType(BarcodePostnet.TYPE_PLANET); codePlanet.FitWidth(250); doc.Add(new Image(codePlanet.CreateFormXObject(pdfDoc))); // Barcode CODE 39 type doc.Add(new Paragraph("Barcode 3 of 9")); Barcode39 code39 = new Barcode39(pdfDoc); code39.SetCode("ITEXT IN ACTION"); code39.FitWidth(250); doc.Add(new Image(code39.CreateFormXObject(pdfDoc))); doc.Add(new Paragraph("Barcode 3 of 9 extended")); Barcode39 code39ext = new Barcode39(pdfDoc); code39ext.SetCode("iText in Action"); code39ext.SetStartStopText(false); code39ext.SetExtended(true); code39ext.FitWidth(250); doc.Add(new Image(code39ext.CreateFormXObject(pdfDoc))); // Barcode CODABAR type doc.Add(new Paragraph("Codabar")); BarcodeCodabar codabar = new BarcodeCodabar(pdfDoc); codabar.SetCode("A123A"); codabar.SetStartStopText(true); codabar.FitWidth(250); doc.Add(new Image(codabar.CreateFormXObject(pdfDoc))); doc.Add(new AreaBreak()); // Barcode PDF417 type doc.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.SetCode(text); PdfFormXObject xObject = pdf417.CreateFormXObject(pdfDoc); Image img = new Image(xObject); doc.Add(img.SetAutoScale(true)); doc.Add(new Paragraph("Barcode Datamatrix")); BarcodeDataMatrix datamatrix = new BarcodeDataMatrix(); datamatrix.SetCode(text); Image imgDM = new Image(datamatrix.CreateFormXObject(pdfDoc)); doc.Add(imgDM.ScaleToFit(250, 250)); // Barcode QRCode type doc.Add(new Paragraph("Barcode QRCode")); BarcodeQRCode qrcode = new BarcodeQRCode("Moby Dick by Herman Melville"); img = new Image(qrcode.CreateFormXObject(pdfDoc)); doc.Add(img.ScaleToFit(250, 250)); doc.Close(); }
/* a method that save the packing slip pdf */ public static void CreatePackingSlip(SearsValues 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.LineCount) { return; } // first check if the save directory exist -> if not create it if (!File.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } // print each item for packing slip for (int i = 0; i < value.LineCount; i++) { // check if the item is in cancel list bool cancelled = cancelIndex.Any(j => i == j); // the case if the item is not cancelled -> generate and export it if (!cancelled) { // initialize PdfWriter object Document doc = new Document(PageSize.LETTER, 0, 0, 0, 35); string file = SavePath + "\\" + value.TransactionId + '_' + (i + 1) + ".pdf"; PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(file, FileMode.Create)); // open the document doc.Open(); PdfContentByte contentByte = writer.DirectContent; #region Draw Line - Divided Half // drawline PdfContentByte draw = writer.DirectContent; draw.MoveTo(doc.PageSize.Width / 2, 0); draw.LineTo(doc.PageSize.Width / 2, doc.PageSize.Height); draw.Stroke(); #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); ColumnText ct = new ColumnText(draw); #region Shipping Address and Schedule // set bill to // title Phrase text = new Phrase("BILL TO/FACTURER A:", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 10f, 753f, 150f, 773f, 0f, Element.ALIGN_LEFT); ct.Go(); // bill recipient and address text = new Phrase(value.BillTo.Name + '\n' + value.BillTo.Address1 + '\n' + value.BillTo.Address2 + '\n' + value.BillTo.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 726f, 150f, 771f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.BillTo.State + '\n' + value.BillTo.PostalCode, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 120f, 704f, 170f, 744f, 9f, Element.ALIGN_LEFT); ct.Go(); // set ship to // title text = new Phrase("RECIPIENT/DESTINATAIRA:", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 10f, 693f, 150f, 713f, 0f, Element.ALIGN_LEFT); ct.Go(); // ship recipient and address text = new Phrase(value.Recipient.Name + '\n' + value.Recipient.Address1 + '\n' + value.Recipient.Address2 + '\n' + value.Recipient.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 666f, 150f, 711f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.Recipient.State + '\n' + value.Recipient.PostalCode, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 120f, 643f, 170f, 683f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.Recipient.DayPhone, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 645f, 150f, 655f, 0f, Element.ALIGN_LEFT); ct.Go(); // arrival date // title text = new Phrase("ARRIVAL DATE/D'ARRIVEE", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 208f, 745f, 308f, 765f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.OrderDate.ToString("MM/dd/yy"), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 226f, 745f, 276f, 755f, 0f, Element.ALIGN_LEFT); ct.Go(); // schedule text = new Phrase("SCHEDULE", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 227f, 727f, 312f, 737f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy"), new Font(baseFont, 10)); ct.SetSimpleColumn(text, 226f, 717f, 279f, 727f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion // sku description text = new Phrase(value.Description[i] + '\n' + value.Description2[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 616f, 150f, 646f, 10f, Element.ALIGN_LEFT); ct.Go(); #region Top Left Boxes #region First Box // upper and lower line for sku box draw.MoveTo(15, 616); draw.LineTo(118, 616); draw.Stroke(); draw.MoveTo(15, 594); draw.LineTo(118, 594); draw.Stroke(); // straight lines for sku box draw.MoveTo(15, 616); draw.LineTo(15, 594); draw.Stroke(); draw.MoveTo(38, 616); draw.LineTo(38, 594); draw.Stroke(); draw.MoveTo(61, 616); draw.LineTo(61, 594); draw.Stroke(); draw.MoveTo(95, 616); draw.LineTo(95, 594); draw.Stroke(); draw.MoveTo(118, 616); draw.LineTo(118, 594); draw.Stroke(); // title in the first box text = new Phrase("D M I SKU", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 23f, 599f, 173f, 609f, 0f, Element.ALIGN_LEFT); ct.Go(); // data in the first box string merchantSku = value.TrxMerchantSku[i]; text = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 23f, 587f, 38f, 597f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 46f, 587f, 61f, 597f, 0f, Element.ALIGN_LEFT); ct.Go(); int index = 2; if (merchantSku[2] == ' ') { index = 3; } text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 65f, 587f, 118f, 597f, 0f, Element.ALIGN_LEFT); ct.Go(); index = index + 5; if (merchantSku.Length <= index) { merchantSku = ""; } else if (merchantSku[index] == ' ') { index++; merchantSku = merchantSku.Substring(index); } else { merchantSku = merchantSku.Substring(index); } text = new Phrase(merchantSku, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 99f, 587f, 118f, 597f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Second Box // upper and lower line for second box draw.MoveTo(15, 589); draw.LineTo(130, 589); draw.Stroke(); draw.MoveTo(15, 558); draw.LineTo(130, 558); draw.Stroke(); // straight lines for sku box draw.MoveTo(15, 589); draw.LineTo(15, 558); draw.Stroke(); draw.MoveTo(55, 589); draw.LineTo(55, 558); draw.Stroke(); draw.MoveTo(90, 589); draw.LineTo(90, 558); draw.Stroke(); draw.MoveTo(130, 589); draw.LineTo(130, 558); draw.Stroke(); // title in the second box text = new Phrase(" D REASON DATE\nM.U.C RAISON", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 24f, 553.5f, 174f, 603.5f, 21.5f, Element.ALIGN_LEFT); ct.Go(); #endregion #endregion #region Price // price titles text = new Phrase("MERCH. PRICE\nPRIX DE MARCH", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 622f, 247f, 637f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("DISCOUNT\nESCOMPTE", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 610f, 247f, 625f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("G.S.T./H.S.T.\nT.P.S./T.V.H.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 598f, 247f, 613f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("P.S.T.\nT.V.P.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 586f, 247f, 601f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("Total", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 197f, 567f, 247f, 582f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("PRICE\nPRIX", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 546f, 247f, 561f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("DISCOUNT\nESCOMPTE", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 534f, 247f, 549f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("HANDLING\nMANUTENTION", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 522f, 247f, 537f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("ELEVY\nTAXE ENVIRO", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 510f, 247f, 525f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("DELIVERY\nLIVRAISON", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 498f, 247f, 513f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("G.S.T./H.S.T.\nT.P.S./T.V.H.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 486f, 247f, 501f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("P.S.T.\nT.V.P.", new Font(baseFont, 5)); ct.SetSimpleColumn(text, 197f, 474f, 247f, 489f, 5f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("Total", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 197f, 455f, 247f, 470f, 0f, Element.ALIGN_LEFT); ct.Go(); // price number char temp; if (value.GstHstExtended[i] > 0 && value.PstExtended[i] > 0) { temp = 'B'; } else if (value.GstHstExtended[i] > 0) { temp = 'T'; } else if (value.PstExtended[i] > 0) { temp = 'P'; } else { temp = ' '; } text = new Phrase(value.UnitPrice[i] + " " + temp, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 613f, 292f, 628f, 0f, Element.ALIGN_LEFT); ct.Go(); string[] tempTax = new string[2]; switch (temp) { case 'B': tempTax[0] = value.GstHstExtended[i].ToString(CultureInfo.InvariantCulture); tempTax[1] = value.PstExtended[i].ToString(CultureInfo.InvariantCulture); break; case 'T': tempTax[0] = value.GstHstExtended[i].ToString(CultureInfo.InvariantCulture); tempTax[1] = string.Empty; break; case 'P': tempTax[0] = string.Empty; tempTax[1] = value.PstExtended[i].ToString(CultureInfo.InvariantCulture); break; default: tempTax[0] = string.Empty; tempTax[1] = string.Empty; break; } text = new Phrase(tempTax[0], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 589.5f, 292f, 604.5f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(tempTax[1], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 579f, 292f, 594f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase((value.UnitPrice[i] + value.GstHstExtended[i] + value.PstExtended[i]).ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 562f, 292f, 582f, 0f, Element.ALIGN_LEFT); ct.Go(); if (value.GstHstTotal[i] > 0 && value.PstTotal[i] > 0) { temp = 'B'; } else if (value.GstHstTotal[i] > 0) { temp = 'T'; } else if (value.PstTotal[i] > 0) { temp = 'P'; } else { temp = ' '; } switch (temp) { case 'B': tempTax[0] = value.GstHstTotal[i].ToString(CultureInfo.InvariantCulture); tempTax[1] = value.PstTotal[i].ToString(CultureInfo.InvariantCulture); break; case 'T': tempTax[0] = value.GstHstTotal[i].ToString(CultureInfo.InvariantCulture); tempTax[1] = string.Empty; break; case 'P': tempTax[0] = string.Empty; tempTax[1] = value.PstTotal[i].ToString(CultureInfo.InvariantCulture); break; default: tempTax[0] = string.Empty; tempTax[1] = string.Empty; break; } text = new Phrase(value.UnitPrice[i] + " " + temp, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 533f, 293f, 553f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.LineHandling[i].ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 513f, 293f, 528f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.LineShipping[i].ToString(CultureInfo.InstalledUICulture), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 490f, 293f, 505f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(tempTax[0], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 478f, 293f, 493f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(tempTax[1], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 466f, 293f, 481f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.LineBalanceDue[i].ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 252f, 455f, 292f, 470f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Left Unknown Region // Other things that I don't know what is this for :( text = new Phrase("SEARS CANADA / VI", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 470f, 150f, 485f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("ORDER NO. DE COMMANDE", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 10f, 457f, 150f, 472f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.CustOrderNumber, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 446f, 150f, 462f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("VENDOR SKU\n" + value.TrxVendorSku[i], new Font(boldFont, 13)); ct.SetSimpleColumn(text, 10f, 400f, 150f, 450f, 11f, Element.ALIGN_LEFT); ct.Go(); // sku title text = new Phrase("D M I Q C SKU G", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 10f, 413.5f, 250f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); // sku number merchantSku = value.TrxMerchantSku[i]; text = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 24f, 413.5f, 39f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 57f, 413.5f, 72f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); index = 2; if (merchantSku[2] == ' ') { index = 3; } text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 83f, 413.5f, 123f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.TrxQty[i].ToString(), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 143f, 413.5f, 158f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); index = index + 5; if (merchantSku.Length <= index) { merchantSku = string.Empty; } else if (merchantSku[index] == ' ') { index++; merchantSku = merchantSku.Substring(index); } else { merchantSku = merchantSku.Substring(index); } text = new Phrase(merchantSku, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 166f, 413.5f, 186f, 428.5f, 10f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Left Bottom Additional Info // some number text = new Phrase(value.PoNumber, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 357f, 150f, 367f, 0f, Element.ALIGN_LEFT); ct.Go(); // sears infomation text = new Phrase("CUSTOMER INQUIRY/DE CLIENT", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 10f, 338f, 150f, 348f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("WWW.SEARS.CA", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 10f, 328f, 150f, 338f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("1-800-267-3277", new Font(baseFont, 10)); ct.SetSimpleColumn(text, 10f, 318f, 150f, 328f, 0f, Element.ALIGN_LEFT); ct.Go(); // note text = new Phrase("THIS BILL OF SALE IS REQUIRED FOR RETURN OR ADJUSTMENT\nOF PURCHASE.\nCETTE FACTURE EST REQUISE POUR TOUT RETROU DE\nMARCHANDIS OU RECLAMATION.", new Font(boldFont, 9)); ct.SetSimpleColumn(text, 10f, 277f, 320f, 317f, 9f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Button Return Region // draw line first draw.MoveTo(10, 255); draw.LineTo(doc.PageSize.Width / 2, 255); draw.Stroke(); #region Left Box // horizontal lines draw.MoveTo(14, 245); draw.LineTo(129, 245); draw.Stroke(); draw.MoveTo(14, 229.5); draw.LineTo(129, 229.5); draw.Stroke(); draw.MoveTo(14, 214); draw.LineTo(129, 214); draw.Stroke(); // vertical lines draw.MoveTo(14, 245); draw.LineTo(14, 214); draw.Stroke(); draw.MoveTo(129, 245); draw.LineTo(129, 214); draw.Stroke(); // text text = new Phrase("REASON\n RAISON", new Font(baseFont, 11)); ct.SetSimpleColumn(text, 47f, 208f, 97f, 250f, 16f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Right Box // horizontal lines draw.MoveTo(139, 245); draw.LineTo(254, 245); draw.Stroke(); draw.MoveTo(139, 214); draw.LineTo(254, 214); draw.Stroke(); // vertical lines draw.MoveTo(139, 245); draw.LineTo(139, 214); draw.Stroke(); draw.MoveTo(179, 245); draw.LineTo(179, 214); draw.Stroke(); draw.MoveTo(214, 245); draw.LineTo(214, 214); draw.Stroke(); draw.MoveTo(254, 245); draw.LineTo(254, 214); draw.Stroke(); // text text = new Phrase(" D REASON DATE\n RAISON", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 148f, 214f, 254f, 259f, 21f, Element.ALIGN_LEFT); ct.Go(); #endregion #endregion #region Barcode Left Bottom #region Barcode One // barcode number text = new Phrase(value.EncodedPrice[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 16f, 177f, 176f, 192f, 0f, Element.ALIGN_LEFT); ct.Go(); // add barcode Barcode128 barcode128 = new Barcode128 { Code = value.EncodedPrice[i], StartStopText = false, Font = null, Extended = true }; Image image = barcode128.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(43f); image.SetAbsolutePosition(24f, 145f); contentByte.AddImage(image); // bar code text under text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy") + " " + value.LineBalanceDue[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 16f, 123f, 176f, 133f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Barcode Two string code = value.TrxMerchantSku[i].Replace(" ", string.Empty); if (code.Length % 2 != 0) { code += '0'; } BarcodeInter25 barcode25 = new BarcodeInter25 { Code = code, StartStopText = false, Font = null, Extended = true }; image = barcode25.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(43f); image.SetAbsolutePosition(24f, 70f); contentByte.AddImage(image); // barcode text text = new Phrase(value.TrxMerchantSku[i] + '\n' + value.Description[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 16f, 48f, 156f, 68f, 9f, Element.ALIGN_LEFT); ct.Go(); // section description text = new Phrase("THIS BILL OF SALE IS\nREQUIRED FOR RETURN", new Font(boldFont, 9)); ct.SetSimpleColumn(text, 181f, 66f, 291f, 116f, 9f, Element.ALIGN_LEFT); ct.Go(); // useless stuff text = new Phrase("66", new Font(boldFont, 11)); ct.SetSimpleColumn(text, 200f, 61f, 220f, 71f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("V2C", new Font(boldFont, 13)); ct.SetSimpleColumn(text, 258f, 3f, 300f, 23f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #endregion #region Right Ship To Address // title text = new Phrase("RECIPIENT/DESTINATAIRA:", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 318f, 753f, 418f, 773f, 0f, Element.ALIGN_LEFT); ct.Go(); // ship to recipient and address text = new Phrase(value.Recipient.Name + '\n' + value.Recipient.Address1 + '\n' + value.Recipient.Address2 + '\n' + value.Recipient.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 726f, 458f, 771f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.Recipient.State + '\n' + value.Recipient.PostalCode + '\n' + value.ExpectedShipDate[i].ToString("MM/dd/yy"), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 428f, 704f, 488f, 744f, 9f, Element.ALIGN_LEFT); ct.Go(); // ship to phone and total price text = new Phrase(value.Recipient.DayPhone + '\n' + value.LineBalanceDue[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 515f, 729f, 605f, 779f, 17f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Barcode Right Top // barcode number text = new Phrase(value.EncodedPrice[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 683f, 468f, 693f, 0f, Element.ALIGN_LEFT); ct.Go(); // add barcode barcode128 = new Barcode128 { Code = value.EncodedPrice[i], StartStopText = false, Font = null, Extended = true }; image = barcode128.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(43f); image.SetAbsolutePosition(326f, 646f); contentByte.AddImage(image); // bar code text under text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy") + " " + value.LineBalanceDue[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 625f, 488f, 635f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Top Right Box // upper and lower line for sku box draw.MoveTo(318, 611); draw.LineTo(421, 611); draw.Stroke(); draw.MoveTo(318, 589); draw.LineTo(421, 589); draw.Stroke(); // straight lines for sku box draw.MoveTo(318, 611); draw.LineTo(318, 589); draw.Stroke(); draw.MoveTo(341, 611); draw.LineTo(341, 589); draw.Stroke(); draw.MoveTo(364, 611); draw.LineTo(364, 589); draw.Stroke(); draw.MoveTo(398, 611); draw.LineTo(398, 589); draw.Stroke(); draw.MoveTo(421, 611); draw.LineTo(421, 589); draw.Stroke(); // title in the first box text = new Phrase(" D M I SKU", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 326f, 594f, 476f, 604f, 0f, Element.ALIGN_LEFT); ct.Go(); // data in the first box merchantSku = value.TrxMerchantSku[i]; text = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 326f, 582f, 349f, 592f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("", new Font(baseFont, 9)); ct.SetSimpleColumn(text, 350f, 582f, 365f, 592f, 0f, Element.ALIGN_LEFT); ct.Go(); index = 2; if (merchantSku[2] == ' ') { index = 3; } text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9)); ct.SetSimpleColumn(text, 368f, 582f, 400f, 592f, 0f, Element.ALIGN_LEFT); ct.Go(); index = index + 5; if (merchantSku.Length <= index) { merchantSku = string.Empty; } else if (merchantSku[index] == ' ') { index++; merchantSku = merchantSku.Substring(index); } else { merchantSku = merchantSku.Substring(index); } text = new Phrase(merchantSku, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 402f, 582f, 422f, 592f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion // sku description text = new Phrase(value.Description[i] + '\n' + value.Description2[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 560f, 458f, 585f, 10f, Element.ALIGN_LEFT); ct.Go(); #region Right Unknown Region // determine if the order is direct shipment string take = value.PartnerPersonPlaceId == "" ? "DIRECT" : value.PartnerPersonPlaceId; text = new Phrase(take, new Font(boldFont, 16)); ct.SetSimpleColumn(text, 318f, 519f, 418f, 539f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase("CSU:", new Font(baseFont, 7)); ct.SetSimpleColumn(text, 318f, 518f, 418f, 528f, 0f, Element.ALIGN_LEFT); ct.Go(); if (take != "DIRECT") { // strange address text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 481f, 468f, 526f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.ShipTo.State + '\n' + value.ShipTo.PostalCode, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 428f, 459f, 488f, 499f, 9f, Element.ALIGN_LEFT); ct.Go(); // strange message text = new Phrase(value.PaymentMethod + " " + value.LineBalanceDue[i], new Font(baseFont, 13)); ct.SetSimpleColumn(text, 318f, 452f, 618f, 472f, 9f, Element.ALIGN_LEFT); ct.Go(); } // strange message continue text = new Phrase(value.PackSlipMessage, new Font(baseFont, 7)); ct.SetSimpleColumn(text, 318f, 441f, 418f, 451f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Buttom Right Ship To Address //title text = new Phrase("SHIP TO/EXPEDIER A:", new Font(boldFont, 10)); ct.SetSimpleColumn(text, 318f, 408f, 458f, 423f, 0f, Element.ALIGN_LEFT); ct.Go(); // address text = new Phrase(value.Recipient.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 375f, 468f, 420f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.ShipTo.State + '\n' + value.ShipTo.PostalCode, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 428f, 362f, 488f, 392f, 9f, Element.ALIGN_LEFT); ct.Go(); // freight info text = new Phrase("FREIGHE LANE/LIGNE DE FRET: SPUR/CONVOYEUR:", new Font(boldFont, 7)); ct.SetSimpleColumn(text, 318f, 348f, 568f, 358f, 0f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.FreightLane, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 348f, 358f, 358f, 9f, Element.ALIGN_LEFT); ct.Go(); text = new Phrase(value.Spur, new Font(baseFont, 9)); ct.SetSimpleColumn(text, 465f, 348f, 495f, 358f, 9f, Element.ALIGN_LEFT); ct.Go(); #endregion #region Right Buttom Barcode // barcode number text = new Phrase(value.ReceivingInstructions[i], new Font(baseFont, 9)); ct.SetSimpleColumn(text, 318f, 306f, 468f, 316f, 0f, Element.ALIGN_LEFT); ct.Go(); // add barcode code = value.ReceivingInstructions[i].Replace(" ", string.Empty); if (code.Length % 2 != 0) { code += '0'; } barcode25 = new BarcodeInter25 { Code = code, StartStopText = false, Font = null, Extended = true }; image = barcode25.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK); image.ScaleAbsoluteHeight(43f); image.SetAbsolutePosition(326f, 269f); contentByte.AddImage(image); // a minor stuff text = new Phrase("V2C", new Font(boldFont, 30)); ct.SetSimpleColumn(text, 480f, 85f, 550f, 135f, 0f, Element.ALIGN_LEFT); ct.Go(); #endregion doc.Close(); if (!preview) { continue; } // start the pdf for previewing if (System.Diagnostics.Process.GetProcessesByName(file).Length < 1) { System.Diagnostics.Process.Start(file); } } } }
// =========================================================================== 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); }
public MemoryStream GerarBoleto(Boleto document, MemoryStream streamReport) { //using (var streamReport = new MemoryStream()) //{ var pdfDocument = new Document(PageSize.A4); PdfWriter writer = PdfWriter.GetInstance(pdfDocument, streamReport); var receiptTable = new PdfPTable(6); receiptTable.SetWidthPercentage(new float[] { 15, 15, 15, 15, 15, 25 }, pdfDocument.PageSize); receiptTable.WidthPercentage = 100; PdfPCell cell; Chunk chunk; var smallFont = new Font(Font.FontFamily.HELVETICA, 6); var regularFont = new Font(Font.FontFamily.HELVETICA, 7); var boldFont = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD); var boldMediumFont = new Font(Font.FontFamily.HELVETICA, 9, iTextSharp.text.Font.BOLD); var boldBigFont = new Font(Font.FontFamily.HELVETICA, 15, iTextSharp.text.Font.BOLD); config.Logotipo.ScalePercent(9, 8); cell = new PdfPCell(); cell.AddElement(config.Logotipo); cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthRight = 0; receiptTable.AddCell(cell); cell = new PdfPCell(new Phrase(new String(' ', 3) + config.NumeroBanco, boldBigFont)); cell.Colspan = 3; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthRight = 0; receiptTable.AddCell(cell); cell = new PdfPCell(new Phrase("\n\n" + new String(' ', 30) + "RECIBO DO PAGADOR", boldMediumFont)); cell.Colspan = 2; cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthRight = 0; receiptTable.AddCell(cell); for (int line = 2; line <= 6; line++) { _GerarLinhaBoleto(document, config, line, receiptTable); } chunk = new Chunk("Mensagens/Instruções (Texto de Responsabilidade do Cedente) \n", smallFont); var messagesText = ""; foreach (var item in document.InstrucoesDoBoleto) { messagesText += item.TextoInstrucao + " \n"; } chunk = new Chunk(messagesText, regularFont); cell = new PdfPCell(); cell.MinimumHeight = 140; cell.AddElement(chunk); cell.Colspan = 6; receiptTable.AddCell(cell); // ***** Boleto - Documento de pagamento var documentTable = new PdfPTable(6); documentTable.SetWidthPercentage(new float[] { 15, 15, 15, 15, 15, 25 }, pdfDocument.PageSize); documentTable.WidthPercentage = 100; // line 1 cell = new PdfPCell(); cell.AddElement(config.Logotipo); cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthRight = 0; documentTable.AddCell(cell); cell = new PdfPCell(new Phrase(new String(' ', 5) + config.NumeroBanco, boldBigFont)); cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.BorderWidthRight = 0; documentTable.AddCell(cell); cell = new PdfPCell(new Phrase("\n\n" + new String(' ', 27) + document.LinhaDigitavelBoleto, boldMediumFont)); cell.Colspan = 4; cell.BorderWidthLeft = 0; cell.BorderWidthTop = 0; cell.BorderWidthRight = 0; documentTable.AddCell(cell); for (int line = 2; line <= 5; line++) { _GerarLinhaBoleto(document, config, line, documentTable); } // Bloco Instruções, Juros, Abatimentos chunk = new Chunk("Instruções \n", smallFont); var messagesTextDoc = ""; foreach (var item in document.InstrucoesDoBoleto) { messagesTextDoc += item.TextoInstrucao + " \n"; } chunk = new Chunk(messagesText, regularFont); cell = new PdfPCell(); cell.MinimumHeight = 140; cell.AddElement(chunk); cell.Colspan = 5; documentTable.AddCell(cell); var innerTable = new PdfPTable(1); var innerCell = new PdfPCell(); chunk = new Chunk("(-) Descontos/Abatimentos \n", smallFont); var discount = Convert.ToDecimal(document.ValorAbatimento) + Convert.ToDecimal(document.ValorDesconto); var discountFmt = discount > 0 ? new String(' ', 43) + discount.ToString("C") : ""; chunk = new Chunk(discountFmt, regularFont); innerCell.AddElement(chunk); innerCell.AddElement(chunk); innerTable.AddCell(innerCell); chunk = new Chunk("(+) Moras/Multa \n", smallFont); var fineInterest = Convert.ToDecimal(document.JurosMora) + Convert.ToDecimal(document.ValorMulta); var fineInterestFmt = fineInterest > 0 ? new String(' ', 43) + fineInterest.ToString("C") : ""; chunk = new Chunk(fineInterestFmt, regularFont); innerCell = new PdfPCell(); innerCell.AddElement(chunk); innerCell.AddElement(chunk); innerTable.AddCell(innerCell); chunk = new Chunk("(=) Valor Cobrado", smallFont); var totalCharged = Convert.ToDecimal(document.ValorCobrado); var totalChargedFmt = totalCharged > 0 ? new String(' ', 43) + totalCharged.ToString("C") : ""; chunk = new Chunk(totalChargedFmt, regularFont); innerCell = new PdfPCell(); innerCell.AddElement(chunk); innerTable.AddCell(innerCell); cell = new PdfPCell(innerTable); documentTable.AddCell(cell); // line 6 _GerarLinhaBoleto(document, config, 6, documentTable); pdfDocument.Open(); // Código de Barras cell = new PdfPCell(); cell.Colspan = 6; cell.BorderWidth = 0; BarcodeInter25 code25 = new BarcodeInter25(); code25.Code = document.CodigoBarraBoleto; code25.BarHeight = 40; code25.Font = null; PdfContentByte cb = writer.DirectContent; var imgBarcode = code25.CreateImageWithBarcode(cb, null, null); imgBarcode.ScalePercent(120); cell.AddElement(imgBarcode); documentTable.AddCell(cell); pdfDocument.Add(receiptTable); pdfDocument.Add(new Phrase("\n\n Corte aqui " + new StringBuilder().Insert(0, "- ", 110), regularFont)); pdfDocument.Add(documentTable); pdfDocument.Close(); //var bytesFile = streamReport.ToArray(); //return bytesFile; return(streamReport); //} }
public static void AddAddresseBlockSeqence(string file, int startBeforePage, int step, bool doublesided, List <Addressee> roll, int x, int y, bool replaceSource) //llx:345 lly:550 defaults { using (var ms = new MemoryStream()) { using (var doc = new Document(iTextSharp.text.PageSize.A4)) { var reader = new PdfReader(file); var writer = PdfWriter.GetInstance(doc, ms); writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_5); string ttf = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "TIMES.TTF"); var baseFont = BaseFont.CreateFont(ttf, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); var timesN = new Font(baseFont, 9, Font.NORMAL); var timesB = new Font(baseFont, 9, Font.BOLD); doc.Open(); var cb = writer.DirectContent; int n = 0; for (int i = startBeforePage; i <= reader.NumberOfPages; i++) { if (startBeforePage > 1) { for (int j = 1; j <= startBeforePage; j++) { cb.AddTemplate(writer.GetImportedPage(reader, j), 0, 0); doc.NewPage(); } } if (roll[n].Barcode != null && roll[n].Barcode != "") { var bc = new BarcodeInter25() { Code = roll[n].Barcode }; var bc_image = bc.CreateImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLACK); bc_image.SetAbsolutePosition(x + 10, y + 115); bc_image.ScalePercent(117F); cb.AddImage(bc_image); } var ct = new ColumnText(cb); ct.SetSimpleColumn(new Rectangle(x, y, x + 205, y + 115)); ct.AddElement(new Paragraph("Кому: " + roll[n].Name, timesN)); ct.AddElement(new Paragraph("Куда: " + roll[n].Address, timesN)); ct.Go(); cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 15); //llx:345 lly:550 if (roll[n].Index != 0) { cb.BeginText(); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, roll[n].Index.ToString(), x + 120, y + 130, 0); cb.EndText(); } cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 5); cb.BeginText(); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, (n + 1).ToString(), x + 120, y + 120, 0); cb.EndText(); doc.NewPage(); if (doublesided) { doc.Add(new Chunk()); doc.NewPage(); } for (int j = 0; j < step; j++) { cb.AddTemplate(writer.GetImportedPage(reader, i), 0, 0); doc.NewPage(); } n++; } } ms.Flush(); if (replaceSource) { File.WriteAllBytes(file, ms.ToArray()); } else { File.WriteAllBytes(file.Insert(file.Length - 4, "_out"), ms.ToArray()); } } }
public static void AddAddresseBlock(string file, int beforePage, bool doublesided, Addressee person, int x, int y, bool replaceSource) { using (var ms = new MemoryStream()) { using (var doc = new Document(iTextSharp.text.PageSize.A4)) { var reader = new PdfReader(file); var writer = PdfWriter.GetInstance(doc, ms); writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7); writer.CompressionLevel = PdfStream.NO_COMPRESSION; string ttf = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "TIMES.TTF"); var baseFont = BaseFont.CreateFont(ttf, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); var timesN = new Font(baseFont, 9, Font.NORMAL); var timesB = new Font(baseFont, 9, Font.BOLD); doc.Open(); var cb = writer.DirectContent; int n = 1; if (beforePage > 1) { for (; n <= beforePage; n++) { cb.AddTemplate(writer.GetImportedPage(reader, n), 0, 0); doc.NewPage(); } } if (person.Barcode != null) { var bc = new BarcodeInter25() { Code = person.Barcode }; var bc_image = bc.CreateImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLACK); bc_image.SetAbsolutePosition(355, 665); bc_image.ScalePercent(117F); cb.AddImage(bc_image); } var ct = new ColumnText(cb); ct.SetSimpleColumn(new Rectangle(345, 550, 550, 665)); if (person.Name != null) { ct.AddElement(new Paragraph("Кому: " + person.Name, timesN)); } if (person.Address != null) { ct.AddElement(new Paragraph("Куда: " + person.Address, timesN)); } ct.Go(); if (person.Index != 0) { cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 15); cb.BeginText(); cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, person.Index.ToString(), 465, 680, 0); cb.EndText(); } doc.NewPage(); if (doublesided) { doc.Add(new Chunk()); doc.NewPage(); } for (; n <= reader.NumberOfPages; n++) { cb.AddTemplate(writer.GetImportedPage(reader, n), 0, 0); doc.NewPage(); } } ms.Flush(); if (replaceSource) { File.WriteAllBytes(file, ms.ToArray()); } else { File.WriteAllBytes(file.Insert(file.Length - 4, "_out"), ms.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); }
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(); }