예제 #1
0
        public void makeCollectionPlusLabel(string filepath)
        {
            Document   document = new Document();
            FileStream fs       = new FileStream(filepath, FileMode.Create);
            PdfWriter  writer   = PdfWriter.GetInstance(document, fs);

            document.SetPageSize(new Rectangle(358, 418));//1/0.9  288, 437
            document.Open();
            document.NewPage();
            iTextSharp.text.io.StreamUtil.AddToResourceSearch(Assembly.Load("iTextAsian"));
            iTextSharp.text.io.StreamUtil.AddToResourceSearch(Assembly.Load("iTextAsianCmaps"));
            BaseFont baseFT = BaseFont.CreateFont("C:/WINDOWS/Fonts/Arial.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

            FontFactory.RegisterDirectory("C:\\WINDOWS\\Fonts");
            Font arial = FontFactory.GetFont("Arial");

            //BaseFont baseFT = BaseFont.CreateFont(BaseFont.TIMES_ROMAN,BaseFont.CP1252, false);

            iTextSharp.text.Font font = new iTextSharp.text.Font(baseFT, 15);

            //大的table
            PdfPTable table = new PdfPTable(1);

            table.WidthPercentage = 100;
            table.TotalWidth      = 286; //101mm

            //code128 client
            //Code128B co128 = new Code128B();
            ////co128.ValueFont = new System.Drawing.Font("宋体", 20);
            //System.Drawing.Bitmap imgTemp = co128.GetCodeImage(this.ClientBarcodeNumber, Code128B.Encode.Code128A);//Code128S传入,不能有“|”???
            //iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance((System.Drawing.Image)imgTemp, iTextSharp.text.BaseColor.WHITE);

            PdfPCell cell;
            //PdfPTable code128Table = new PdfPTable(1);
            ////code128Table.TotalWidth = 286;
            //////img.ScalePercent(70f);
            //img.ScaleAbsoluteHeight(28f);//10mm
            //img.ScaleAbsoluteWidth(193);//68mm
            //cell = new PdfPCell(img);
            //cell.BorderWidthBottom = 0;
            //cell.BorderWidthTop = 0;
            //cell.BorderWidthRight = 0;
            //cell.BorderWidthLeft = 0;
            //cell.Colspan = 1;
            //cell.HorizontalAlignment = Element.ALIGN_CENTER;
            //code128Table.AddCell(cell);



            //cell = new PdfPCell(new Phrase(this.ClientBarcodeNumber.ToUpper(), new Font(baseFT, 10)));
            //cell.BorderWidthTop = 0;
            //cell.BorderWidthBottom = 0;
            //cell.BorderWidthLeft = 0;
            //cell.BorderWidthRight = 0;
            //cell.HorizontalAlignment = Element.ALIGN_CENTER;
            //cell.PaddingTop = 2f;
            //cell.FixedHeight = 21f;//总高度8mm
            //code128Table.AddCell(cell);

            //cell = new PdfPCell(code128Table);
            ////cell.BorderWidthLeft = 0;
            ////cell.BorderWidthTop = 0;
            ////cell.BorderWidthBottom = 0;
            ////cell.BorderWidthRight = 0;
            //cell.PaddingTop = 15;
            //cell.FixedHeight = 70f;//总的高度为 mm

            //table.AddCell(cell);
            ////128 client二维码部分完成
            //Console.WriteLine("128二维码部分完成");

            //第二部分 clientName那一行
            PdfPTable table2 = new PdfPTable(2);

            table2.SetWidths(new int[] { 70, 30 });
            Phrase phrase = new Phrase(this.ClientName, new Font(baseFT, 15, Font.BOLD));

            cell = new PdfPCell(phrase);
            cell.BorderWidthTop      = 0;
            cell.BorderWidthBottom   = 0;
            cell.BorderWidthLeft     = 0;
            cell.BorderWidthRight    = 0;
            cell.Colspan             = 1;
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            cell.PaddingTop          = 8;
            cell.PaddingLeft         = 5;
            table2.AddCell(cell);

            string path = AppDomain.CurrentDomain.BaseDirectory + "\\image\\images\\collect_plus_logo.png";
            //Console.WriteLine(path);
            Image collect_plus_logo = Image.GetInstance(path);

            collect_plus_logo.ScaleAbsoluteHeight(30f);
            collect_plus_logo.ScaleAbsoluteWidth(75f);
            cell = new PdfPCell(collect_plus_logo);
            cell.BorderWidthTop      = 0;
            cell.BorderWidthBottom   = 0;
            cell.BorderWidthLeft     = 0;
            cell.BorderWidthRight    = 0;
            cell.Colspan             = 1;
            cell.HorizontalAlignment = Element.ALIGN_RIGHT;
            cell.PaddingTop          = 0;
            cell.PaddingBottom       = 3;
            table2.AddCell(cell);
            table.AddCell(table2);

            PdfPTable table3 = new PdfPTable(2);

            table3.SetWidths(new int[] { 40, 60 });    // 设置各列宽度,单位是百分比
            PdfPTable tableLeft  = new PdfPTable(1);
            PdfPTable tableRight = new PdfPTable(1);

            Chunk chunk1 = new Chunk("Depot\n", new Font(baseFT, 10));
            Chunk chunk2 = new Chunk(this.RoutDepotNumber + " " + this.RoutDepotName, new Font(baseFT, 15, Font.BOLD));
            Chunk chunk3;
            Chunk chunk4;
            Chunk chunk5;
            Chunk chunk6;

            phrase = new Phrase();
            phrase.Add(chunk1);
            phrase.Add(chunk2);
            cell = new PdfPCell(phrase);
            cell.PaddingBottom = 10;
            tableLeft.AddCell(cell);

            chunk1 = new Chunk("Label Date\n", new Font(baseFT, 10));
            chunk2 = new Chunk(this.LabelDate, new Font(baseFT, 15, Font.BOLD));
            phrase = new Phrase();
            phrase.Add(chunk1);
            phrase.Add(chunk2);
            cell = new PdfPCell(phrase);
            cell.PaddingBottom = 5;
            tableLeft.AddCell(cell);

            chunk1 = new Chunk("Returns Reference\n", new Font(baseFT, 10));
            chunk2 = new Chunk(this.ReturnsReference, new Font(baseFT, 15, Font.BOLD));
            phrase = new Phrase();
            phrase.Add(chunk1);
            phrase.Add(chunk2);
            cell = new PdfPCell(phrase);
            cell.PaddingBottom = 5;
            tableLeft.AddCell(cell);


            chunk1 = new Chunk("Lydia\n".ToUpper(), new Font(baseFT, 10));
            chunk2 = new Chunk("The Old Bus Garage\n".ToUpper(), new Font(baseFT, 10));
            chunk3 = new Chunk("Harborne Lane\n".ToUpper(), new Font(baseFT, 10));
            chunk4 = new Chunk("Selly Oak\n".ToUpper(), new Font(baseFT, 10));
            chunk5 = new Chunk("Birmingham\n".ToUpper(), new Font(baseFT, 10));
            chunk6 = new Chunk("B29 6SN", new Font(baseFT, 20, Font.BOLD));
            phrase = new Phrase();
            phrase.Add(chunk1);
            phrase.Add(Chunk.NEWLINE.setLineHeight(3));
            phrase.Add(chunk2);
            phrase.Add(Chunk.NEWLINE.setLineHeight(3));
            phrase.Add(chunk3);
            phrase.Add(Chunk.NEWLINE.setLineHeight(3));
            phrase.Add(chunk4);
            phrase.Add(Chunk.NEWLINE.setLineHeight(3));
            phrase.Add(chunk5);
            phrase.Add(chunk6);
            cell               = new PdfPCell(phrase);
            cell.PaddingTop    = 10;
            cell.PaddingBottom = 10;
            tableRight.AddCell(cell);


            //去除边框
            cell = new PdfPCell(tableLeft);
            cell.BorderWidthLeft   = 0;
            cell.BorderWidthTop    = 0;
            cell.BorderWidthBottom = 0;
            cell.BorderWidthRight  = 0;
            table3.AddCell(cell);

            cell = new PdfPCell(tableRight);
            cell.BorderWidthLeft   = 0;
            cell.BorderWidthTop    = 0;
            cell.BorderWidthBottom = 0;
            cell.BorderWidthRight  = 0;
            table3.AddCell(cell);

            cell = new PdfPCell(table3);
            cell.BorderWidthLeft   = 0;
            cell.BorderWidthTop    = 0;
            cell.BorderWidthBottom = 0;
            cell.BorderWidthRight  = 0;
            //第三大行完成
            table.AddCell(cell);

            //第四行 Storekeeper Instruction
            PdfPTable table4 = new PdfPTable(1);

            chunk1 = new Chunk("Storekeeper Instruction\n", new Font(baseFT, 8, Font.BOLD));
            chunk2 = new Chunk("GIVE TO THE DRIVER", new Font(baseFT, 15, Font.BOLD));
            phrase = new Phrase();
            phrase.Add(chunk1);
            phrase.Add(Chunk.NEWLINE.setLineHeight(5));
            phrase.Add(chunk2);
            cell = new PdfPCell(phrase);
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.BorderWidthLeft     = 0;
            cell.BorderWidthTop      = 0;
            cell.BorderWidthBottom   = 0;
            cell.BorderWidthRight    = 0;
            cell.PaddingTop          = 3;
            cell.PaddingBottom       = 10;
            table4.AddCell(cell);
            table.AddCell(table4);

            //第五行,二维码部分
            //第五行,头一行文字
            PdfPTable table5 = new PdfPTable(1);

            phrase = new Phrase("COLLECTION+ BARCODE BELOW", new Font(baseFT, 12, Font.BOLD));
            cell   = new PdfPCell(phrase);
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.BorderWidthLeft     = 0;
            cell.BorderWidthTop      = 0;
            cell.BorderWidthBottom   = 0;
            cell.BorderWidthRight    = 0;
            cell.PaddingTop          = 10;
            cell.PaddingBottom       = 15;
            table5.AddCell(cell);

            //第五部分collectBarcode
            Code128B collectBarcode = new Code128B();

            //co128.ValueFont = new System.Drawing.Font("宋体", 20);
            System.Drawing.Bitmap imgCollectBarcode = collectBarcode.GetCodeImage(this.BarcodeNumber, Code128B.Encode.Code128A);//Code128S传入,不能有“|”???

            iTextSharp.text.Image imgcollectBarcode = iTextSharp.text.Image.GetInstance(imgCollectBarcode, iTextSharp.text.BaseColor.WHITE);
            imgcollectBarcode.ScaleAbsoluteHeight(77f); //27mm
            imgcollectBarcode.ScaleAbsoluteWidth(199f); //70.2mm
            cell = new PdfPCell(imgcollectBarcode);
            cell.BorderWidthBottom   = 0;
            cell.BorderWidthTop      = 0;
            cell.BorderWidthRight    = 0;
            cell.BorderWidthLeft     = 0;
            cell.Colspan             = 1;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            table5.AddCell(cell);

            //第五部分CodeString
            this.BarcodeNumber = this.BarcodeNumber.Replace("0", "Ø");
            phrase             = new Phrase(this.BarcodeNumber, new Font(baseFT, 15, Font.BOLD));//"883KØØØØ7116AØ51"
            cell = new PdfPCell(phrase);
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            cell.BorderWidthLeft     = 0;
            cell.BorderWidthTop      = 0;
            cell.BorderWidthBottom   = 0;
            cell.BorderWidthRight    = 0;
            cell.PaddingTop          = 10;
            cell.PaddingBottom       = 10;
            table5.AddCell(cell);

            table.AddCell(table5);

            document.Add(table);
            document.Close();
            Console.WriteLine("全部完成");
        }
예제 #2
0
        public UkmailLabel(string Ordernum, string Tracknum, string SenderAdress, double Weight, string ShippingDate, int totalParcel)
        {
            try
            {
                Code128B co128    = new Code128B();
                Document document = new Document(PageSize.A4);
                document.SetPageSize(new Rectangle(460, 320));
                co128.ValueFont = new System.Drawing.Font("Calibri", 20);
                System.Drawing.Bitmap imgTemp = co128.GetCodeImage(Tracknum, Code128B.Encode.Code128A);
                iTextSharp.text.Image img     = iTextSharp.text.Image.GetInstance((System.Drawing.Image)imgTemp, iTextSharp.text.BaseColor.WHITE);
                img.ScaleAbsoluteHeight(70);
                img.ScaleAbsoluteWidth(240);
                System.Drawing.Bitmap imgTemp1 = co128.GetCodeImage(Ordernum, Code128B.Encode.Code128A);
                iTextSharp.text.Image img1     = iTextSharp.text.Image.GetInstance((System.Drawing.Image)imgTemp1, iTextSharp.text.BaseColor.WHITE);
                img1.ScaleAbsoluteWidth(163);

                string     filename = "\\views\\pdf\\" + Ordernum + "2.pdf";
                FileStream fs       = new FileStream(AppDomain.CurrentDomain.BaseDirectory + filename, FileMode.Create);
                PdfWriter  writer   = PdfWriter.GetInstance(document, fs);
                document.SetMargins(10, 10, 2, 2);
                document.Open();
                PdfPTable table = new PdfPTable(1);
                table.WidthPercentage = 100;
                table.TotalWidth      = 1200;
                PdfPCell cell;
                BaseFont baseFT1 = BaseFont.CreateFont("C:/WINDOWS/Fonts/Helvetica.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                BaseFont baseFT  = BaseFont.CreateFont("C:/WINDOWS/Fonts/Helvetica Bold.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
                for (int i = 0; i < totalParcel; i++)
                {
                    document.NewPage();
                    PdfPTable table1 = new PdfPTable(4);
                    PdfPTable table2 = new PdfPTable(1);
                    cell = new PdfPCell(new Phrase("www.ukmail.com", new Font(baseFT1, 8)));
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    cell.BorderWidthLeft     = 0;
                    cell.BorderWidthRight    = 0;
                    cell.BorderWidthTop      = 0;
                    cell.BorderWidthBottom   = 0;
                    table2.AddCell(cell);
                    Phrase ph = new Phrase();
                    Chunk  chunkCollection = new Chunk("Domestic Collection\r\nLIVE OPSYS\r\nLabel Produces:\r\n" + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss") + "\r\n \r\n ", new Font(baseFT, 10));
                    ph.Add(chunkCollection);
                    cell = new PdfPCell(ph);
                    cell.BorderWidthLeft     = 0;
                    cell.BorderWidthRight    = 0;
                    cell.BorderWidthTop      = 0;
                    cell.BorderWidthBottom   = 0;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    table2.AddCell(cell);
                    cell = new PdfPCell(table2);
                    cell.BorderWidthLeft   = 0;
                    cell.BorderWidthRight  = 0;
                    cell.BorderWidthTop    = 0;
                    cell.BorderWidthBottom = 0;
                    cell.Colspan           = 1;
                    table1.AddCell(cell);
                    cell = new PdfPCell(img);
                    cell.BorderWidthLeft     = 0;
                    cell.BorderWidthRight    = 0;
                    cell.BorderWidthTop      = 0;
                    cell.BorderWidthBottom   = 0;
                    cell.Colspan             = 3;
                    cell.PaddingTop          = 10;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    table1.AddCell(cell);
                    PdfPTable table3   = new PdfPTable(5);
                    Phrase    chunkFAO = new Phrase("FAO:Customer Import\r\nETAO LTD\r\nC/O ACCESS SELF STORAGE,OFFIC\r\nHARBORNE LANE SELLY OAK\r\nBIRMINGHAM", new Font(baseFT, 10));
                    cell = new PdfPCell(chunkFAO);
                    cell.BorderWidthLeft     = 0;
                    cell.BorderWidthRight    = 0;
                    cell.BorderWidthTop      = 0;
                    cell.BorderWidthBottom   = 0;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    cell.Colspan             = 2;

                    table3.AddCell(cell);
                    Phrase chunkConsignment = new Phrase("Consignment NO:    " + Tracknum + "\r\nWeight:                      " + Weight.ToString() + " Kg\r\nParcel:                       " + (i + 1).ToString() + " of " + totalParcel.ToString() + "\r\nTelephone:                0121 448 6510\r\nReference 1:\r\nnReference 2:\r\nCollection Driver:\r\nCollection Address:  " + SenderAdress, new Font(baseFT, 10));
                    cell = new PdfPCell(chunkConsignment);
                    cell.BorderWidthLeft     = 0;
                    cell.BorderWidthRight    = 0;
                    cell.BorderWidthTop      = 0;
                    cell.BorderWidthBottom   = 0;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    cell.Colspan             = 3;
                    table3.AddCell(cell);
                    //table.AddCell(table3);
                    PdfPTable table4 = new PdfPTable(5);
                    PdfPTable table5 = new PdfPTable(1);
                    Phrase    phrase = new Phrase();
                    Chunk     chk1   = new Chunk("B29 6SN\r\n", new Font(baseFT, 14));
                    Chunk     chk2   = new Chunk("Special Instructions\r\n \r\n", new Font(baseFT1, 8));
                    Chunk     chk3   = new Chunk(" \r\n" + Ordernum, new Font(baseFT1, 8));
                    Chunk     chk4   = new Chunk("\r\nETAO LTD", new Font(baseFT, 8));
                    phrase.Add(chk1);
                    phrase.Add(chk2);
                    cell = new PdfPCell(phrase);
                    cell.BorderWidthLeft   = 0;
                    cell.BorderWidthRight  = 0;
                    cell.BorderWidthTop    = 0;
                    cell.BorderWidthBottom = 0;
                    cell.Colspan           = 1;
                    table5.AddCell(cell);
                    cell = new PdfPCell(img1);
                    cell.BorderWidthLeft   = 0;
                    cell.BorderWidthRight  = 0;
                    cell.BorderWidthTop    = 0;
                    cell.BorderWidthBottom = 0;
                    cell.Colspan           = 1;
                    table5.AddCell(cell);
                    Phrase phrase1 = new Phrase();
                    phrase1.Add(chk3);
                    phrase1.Add(chk4);
                    cell = new PdfPCell(phrase1);
                    cell.BorderWidthLeft   = 0;
                    cell.BorderWidthRight  = 0;
                    cell.BorderWidthTop    = 0;
                    cell.BorderWidthBottom = 0;
                    cell.Colspan           = 1;
                    table5.AddCell(cell);
                    cell = new PdfPCell(table5);
                    cell.BorderWidthLeft     = 0;
                    cell.BorderWidthRight    = 0;
                    cell.BorderWidthTop      = 0;
                    cell.BorderWidthBottom   = 0;
                    cell.Colspan             = 2;
                    cell.PaddingTop          = 5;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    table4.AddCell(cell);

                    Phrase phraseHome = new Phrase("HomeService           " + DateTime.Parse(ShippingDate).ToString("dd/MM/yyyy") + "\r\nNextDay\r\n \r\n \r\nBirmingham", new Font(baseFT, 17));
                    cell = new PdfPCell(phraseHome);
                    cell.BorderWidthLeft     = 0;
                    cell.BorderWidthRight    = 0;
                    cell.BorderWidthTop      = 0;
                    cell.BorderWidthBottom   = 0;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    cell.PaddingTop          = 5;
                    cell.Colspan             = 3;
                    cell.PaddingLeft         = 10;
                    table4.AddCell(cell);


                    cell = new PdfPCell(table1);
                    cell.BorderWidthLeft   = 0;
                    cell.BorderWidthRight  = 0;
                    cell.BorderWidthTop    = 0;
                    cell.BorderWidthBottom = 0;
                    cell.Colspan           = 1;
                    table.AddCell(cell);

                    cell = new PdfPCell(table3);
                    cell.BorderWidthLeft   = 0;
                    cell.BorderWidthRight  = 0;
                    cell.BorderWidthTop    = 0;
                    cell.BorderWidthBottom = 0;
                    cell.Colspan           = 1;
                    cell.FixedHeight       = 100;
                    table.AddCell(cell);
                    cell = new PdfPCell(table4);
                    cell.BorderWidthLeft   = 0;
                    cell.BorderWidthRight  = 0;
                    cell.BorderWidthTop    = 0;
                    cell.BorderWidthBottom = 0;
                    cell.Colspan           = 1;
                    table.AddCell(cell);
                    document.Add(table);
                }
                document.Close();
                fs.Close();
            }
            catch (DocumentException de)
            {
            }
            catch (IOException ioe)
            {
            }
        }