Пример #1
0
        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"));
        }
Пример #2
0
        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);
        }
Пример #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);
        }
Пример #4
0
        public void generarCodigoBarras(Consumidor t)
        {
            //Toma el RUN del consumidor guardado en la sesion del consumidor, con el cual se generara el código de barras para el PDF
            string    code       = t.runConsumidor;
            Barcode39 barcodeImg = new Barcode39();

            barcodeImg.Code = code.ToString();
            barcodeImg.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White).Save(@"C:\Users\nicolas\Documents\Visual Studio 2015\Projects\webMisOfertasResponsive\webMisOfertasResponsive\tempDocs\barcode" + t.runConsumidor + ".png", System.Drawing.Imaging.ImageFormat.Png);
        }
Пример #5
0
        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);
        }
Пример #6
0
        public static void Gen(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc, new PageSize(60, 140));

            doc.SetMargins(5, 5, 5, 5);

            PdfFont   bold    = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD);
            PdfFont   regular = PdfFontFactory.CreateFont(StandardFonts.HELVETICA);
            PdfFont   mrv39s  = PdfFontFactory.CreateFont(@"fonts/mrvcode39s.ttf", true);
            Paragraph p1      = new Paragraph();

            p1.Add(new Text("23").SetFont(bold).SetFontSize(12));
            p1.Add(new Text("000").SetFont(bold).SetFontSize(6));
            doc.Add(p1);

            Paragraph p2 = new Paragraph("T.T.C.").SetFont(regular).SetFontSize(6);

            p2.SetTextAlignment(TextAlignment.RIGHT);
            doc.Add(p2);

            // CODE 39
            Paragraph pc3 = new Paragraph("*10000100*").SetFont(mrv39s).SetFontSize(6);

            pc3.SetTextAlignment(TextAlignment.LEFT);
            pc3.SetRotationAngle(Math.PI / 2);
            doc.Add(pc3);

            Barcode39 barcode = new Barcode39(pdfDoc);

            barcode.SetCode("12345678");
            Rectangle      rect           = barcode.GetBarcodeSize();
            PdfFormXObject template       = new PdfFormXObject(new Rectangle(rect.GetWidth(), rect.GetHeight() + 10));
            PdfCanvas      templateCanvas = new PdfCanvas(template, pdfDoc);

            new Canvas(templateCanvas, pdfDoc, new Rectangle(rect.GetWidth(), rect.GetHeight() + 10))
            .ShowTextAligned(new Paragraph("DARK GRAY").SetFont(regular).SetFontSize(6), 0, rect.GetHeight() + 2, TextAlignment.LEFT);
            barcode.PlaceBarcode(templateCanvas, DeviceRgb.BLACK, DeviceRgb.BLACK);
            Image image = new Image(template);

            image.SetRotationAngle(Math.PI / 4);
            image.SetAutoScale(true);
            doc.Add(image);

            Paragraph p3 = new Paragraph("SMALL").SetFont(regular).SetFontSize(6);

            p3.SetTextAlignment(TextAlignment.CENTER);
            doc.Add(p3);

            doc.Close();
        }
Пример #7
0
        public static byte[] WriteToPdf(FileInfo sourceFile, string stringToWriteToPdf)
        {
            PdfReader reader = new PdfReader(sourceFile.FullName);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                //
                // PDFStamper is the class we use from iTextSharp to alter an existing PDF.
                //
                PdfStamper pdfStamper = new PdfStamper(reader, memoryStream);

                for (int i = 1; i <= reader.NumberOfPages; i++) // Must start at 1 because 0 is not an actual page.
                {
                    iTextSharp.text.Rectangle pageSize = reader.GetPageSizeWithRotation(i);

                    PdfContentByte pdfPageContents = pdfStamper.GetOverContent(i);
                    pdfPageContents.BeginText(); // Start working with text.

                    BaseFont baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, false);
                    //pdfPageContents.SetFontAndSize(baseFont, 15);
                    //pdfPageContents.SetRGBColorFill(255, 0, 0);
                    int       dpi = 100;
                    Barcode39 br  = new Barcode39();
                    br.Code = stringToWriteToPdf;

                    iTextSharp.text.Image barcodeImage = iTextSharp.text.Image.GetInstance(br.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), BaseColor.BLACK);

                    barcodeImage.SetAbsolutePosition((pageSize.Width / 2) + (barcodeImage.Width / 2), pageSize.Height - 20);// pageSize.Height - 150

                    barcodeImage.ScalePercent(72f / (float)dpi * 100f);

                    //float textAngle =
                    //    (float)FooTheoryMath.GetHypotenuseAngleInDegreesFrom(pageSize.Height, pageSize.Width);


                    //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, stringToWriteToPdf,
                    //                                pageSize.Width/2,
                    //                                pageSize.Height/2,
                    //                                textAngle);

                    pdfPageContents.AddImage(barcodeImage, true);
                    //pdfPageContents.ShowTextAligned(PdfContentByte.ALIGN_CENTER, stringToWriteToPdf, (pageSize.Width / 5) *4, pageSize.Height - 150, 0);
                    pdfPageContents.EndText();
                }

                pdfStamper.FormFlattening = true;
                pdfStamper.Close();

                return(memoryStream.ToArray());
            }
        }
Пример #8
0
        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);
        }
Пример #9
0
        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();
        }
Пример #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool      isPreview = chb_preview.Checked;
            Barcode39 barcode39 = new Barcode39();

            barcode39.Code      = "20201209/WED";
            barcode39.BarHeight = 50f;

            //save image file
            //barcode39.CreateDrawingImage(Color.Black, Color.White).Save(@"C:\Users\Chanos\Desktop\git\barcode.png");

            Image barcodeImage = barcode39.CreateDrawingImage(Color.Black, Color.White);

            PrintDocument printDocument = new PrintDocument();

            printDocument.PrintPage += (printSender, printEvent) =>
            {
                printEvent.Graphics.DrawImage(barcodeImage, new Point(0, 0));
            };

            using (PageSetupDialog pageSetupDialog = new PageSetupDialog())
            {
                pageSetupDialog.Document = printDocument;
                pageSetupDialog.ShowDialog();
            }

            using (PrintDialog printDialog = new PrintDialog())
            {
                printDialog.Document = printDocument;
                printDialog.ShowDialog();
            }

            if (!isPreview)
            {
                printDocument.Print();
            }
            else
            {
                using (PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog())
                {
                    printPreviewDialog.Document = printDocument;
                    printPreviewDialog.ShowDialog();
                }
            }
        }
        public virtual void Barcode39Test()
        {
            String   outPdf = destinationFolder + "barcode39Test.pdf";
            String   cmpPdf = cmpFolder + "cmp_barcode39Test.pdf";
            Document doc    = CreatePdfATaggedDocument(outPdf);
            PdfFont  font   = PdfFontFactory.CreateFont(sourceFolder + "FreeSans.ttf", "WinAnsi", true);

            font.SetSubset(true);
            Barcode39 code39 = new Barcode39(doc.GetPdfDocument(), font);

            FillBarcode1D(code39, "1234567");
            PdfFormXObject barcode = code39.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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        public static Bitmap CodigosBarraPLU(string _Code, Single Height = 0)
        {
            Barcode39 uccEan128 = new Barcode39();

            uccEan128.CodeType = Barcode39.CODABAR;
            if (Height != 0)
            {
                uccEan128.BarHeight = 10;
            }
            uccEan128.Code = _Code;
            try
            {
                Bitmap bm = new Bitmap(uccEan128.CreateDrawingImage(Color.Black, Color.White));
                return(bm);
            }
            catch (Exception ex)
            {
                throw new Exception("Error al generar el codigo" + ex.ToString());
            }
        }
Пример #15
0
        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})");
        }
Пример #16
0
        public void ProcessRequest(System.Web.HttpContext context)
        {
            HttpRequest  Request  = context.Request;
            HttpResponse response = context.Response;

            Barcode39 bc39 = new Barcode39();

            if (Request["code"] != null)
            {
                bc39.Code = Request["code"];
            }
            else
            {
                bc39.Code = DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString();
            }

            System.Drawing.Image bc = bc39.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
            response.ContentType = "image/gif";

            bc.Save(response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        }
        /**
         * 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);
        }
Пример #18
0
        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));
        }
Пример #19
0
        private Cell CreateBarcode(string code, PdfDocument pdfDoc, PDFQRConfiguration settings)
        {
            var barcode = new Barcode39(pdfDoc);

            barcode.SetCodeType(Barcode39.ALIGN_CENTER);
            barcode.SetCode(code);
            barcode.SetBarHeight(settings.Height);
            barcode.FitWidth(settings.Width);

            // Create barcode object to put it to the cell as image
            var barcodeObject = barcode.CreateFormXObject(null, null, pdfDoc);
            var cell          = new Cell().Add(new Image(barcodeObject));

            cell.SetPaddingTop(settings.CellPaddingTop);
            cell.SetPaddingRight(settings.CellPaddingRight);
            cell.SetPaddingBottom(settings.CellPaddingBottom);
            cell.SetPaddingLeft(settings.CellPaddingLeft);

            cell.SetBorder(new iText.Layout.Borders.DottedBorder(iText.Kernel.Colors.ColorConstants.LIGHT_GRAY, 1));


            return(cell);
        }
        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);
        }
Пример #21
0
            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();
            }
Пример #22
0
        /**
         * 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);
        }
Пример #23
0
// ===========================================================================
        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);
            }
        }
Пример #24
0
        /// <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);
        }
Пример #25
0
        /* 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);
            }
        }
Пример #26
0
        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!");
            }
        }
Пример #27
0
        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();
        }
Пример #28
0
        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();
        }