Beispiel #1
0
        public string BuildPrintFile(List <PackPageData> pageDatas, string appUser)
        {
            string fileName = string.Format("CustPack-{0}.pdf", DateTime.Now.ToString("yyyyMMddHHmm"));
            string fullPath = BasePath + fileName;


            List <string> sData = new List <string>();

            //each page size get from header ,
            Document doc = new Document(pdfUtility.GetDocRectangle(pageDatas[0].Header.PAPER_HORIZONTAL, pageDatas[0].Header.PAPER_VERTICAL));

            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(fullPath, FileMode.Create));

            //string imagePath = BasePath.Replace("temp", "images") + pageDatas[0].Header.LOGO; //;"custpack.png";
            PackPageEventHelper pHelper = new PackPageEventHelper();

            if (!string.IsNullOrEmpty(pageDatas[0].Header.LOGO))
            {
                pHelper.LogoPath = BasePath.Replace("temp", "images") + pageDatas[0].Header.LOGO;
            }
            writer.PageEvent = pHelper;

            doc.SetMargins(10f, 10f, 10f, 36f);

            pHelper.CurrentGroup = pageDatas[0].Header.LODNUM;
            for (int i = 0; i < pageDatas.Count; i++)
            {
                //pHelper.CurrentGroup = pageDatas[i].Header.SHIP_ID;
                if (i != 0)
                {
                    doc.SetPageSize(pdfUtility.GetDocRectangle(pageDatas[i].Header.PAPER_HORIZONTAL, pageDatas[i].Header.PAPER_VERTICAL));
                    doc.NewPage();
                }
                else
                {
                    doc.Open();
                }


                PdfPCell cellUnit;
                //Content part
                PdfPTable contentTable = new PdfPTable(3);
                contentTable.WidthPercentage = 90f;
                contentTable.SetWidths(new float[] { 200f, 190f, 185f });//575

                cellUnit             = new PdfPCell(new Paragraph(pageDatas[i].Header.HEADER1, new iTextSharp.text.Font(BF_Light, HeaderFontSize)));
                cellUnit.BorderWidth = 0;
                contentTable.AddCell(cellUnit);
                cellUnit             = new PdfPCell(new Paragraph(pageDatas[i].Header.HEADER2, new iTextSharp.text.Font(BF_Light, HeaderFontSize)));
                cellUnit.BorderWidth = 0;
                contentTable.AddCell(cellUnit);
                cellUnit             = new PdfPCell(new Paragraph(pageDatas[i].Header.HEADER3, new iTextSharp.text.Font(BF_Light, HeaderFontSize)));
                cellUnit.BorderWidth = 0;
                contentTable.AddCell(cellUnit);
                doc.Add(contentTable);
                doc.Add(new Paragraph(Environment.NewLine));

                //part 2
                PdfPTable table_2 = new PdfPTable(2);
                table_2.WidthPercentage = 90f;
                table_2.SetWidths(new float[] { 285f, 285f });//575
                Paragraph p21 = new Paragraph();
                p21.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.NOTE1, pageDatas[i].Header.FLEX1), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p21.Add(System.Environment.NewLine);
                p21.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.COMPANY), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p21.Add(System.Environment.NewLine);
                p21.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.ADDRESS), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p21.Add(System.Environment.NewLine);
                p21.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.CONTACT, pageDatas[i].Header.TELEPHONE), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p21.Add(System.Environment.NewLine);
                cellUnit             = new PdfPCell(p21);
                cellUnit.BorderWidth = 0;
                table_2.AddCell(cellUnit);

                Paragraph p22 = new Paragraph();
                p22.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.NOTE2, pageDatas[i].Header.FLEX2), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                p22.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.ADRNAM, pageDatas[i].Header.ADRCTY), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                p22.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.ADRLN1), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                p22.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.ADRLN2, pageDatas[i].Header.ADRLN3), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                p22.Add(new Phrase(string.Format("{0}    {1}", pageDatas[i].Header.LAST_NAME, pageDatas[i].Header.PHNNUM), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p22.Add(System.Environment.NewLine);
                cellUnit             = new PdfPCell(p22);
                cellUnit.BorderWidth = 0;
                table_2.AddCell(cellUnit);

                doc.Add(table_2);
                doc.Add(new Paragraph(Environment.NewLine));

                //part 3
                PdfPTable table_3 = new PdfPTable(3);
                table_3.WidthPercentage = 90f;
                table_3.SetWidths(new float[] { 200f, 190f, 185f });//575
                Paragraph p31 = new Paragraph();
                p31.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.NOTE3), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p31.Add(System.Environment.NewLine);
                p31.Add(System.Environment.NewLine);
                p31.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.FLEX3), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                cellUnit             = new PdfPCell(p31);
                cellUnit.BorderWidth = 0;
                table_3.AddCell(cellUnit);

                Paragraph p32 = new Paragraph();
                p32.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.NOTE4), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p32.Add(System.Environment.NewLine);
                p32.Add(System.Environment.NewLine);
                p32.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.FLEX4), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                cellUnit             = new PdfPCell(p32);
                cellUnit.BorderWidth = 0;
                table_3.AddCell(cellUnit);

                Paragraph p33 = new Paragraph();
                p33.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.NOTE5), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                p33.Add(System.Environment.NewLine);
                p33.Add(System.Environment.NewLine);
                p33.Add(new Phrase(string.Format("{0}", pageDatas[i].Header.FLEX5), new iTextSharp.text.Font(BF_Light, ContentFontSize)));
                cellUnit             = new PdfPCell(p33);
                cellUnit.BorderWidth = 0;
                table_3.AddCell(cellUnit);

                doc.Add(table_3);
                doc.Add(new Paragraph(Environment.NewLine));

                //Table part
                PdfPTable dTable = new PdfPTable(11);
                dTable.WidthPercentage = 90f;
                dTable.SetWidths(new float[] { 30f, 52f, 98f, 25f, 30f, 47f, 47f, 47f, 47f, 47f, 47f });
                dTable.AddCell(pdfUtility.BuildCell("Index", new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL01, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL02, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL03, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL04, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL05, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL06, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL07, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL08, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL09, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                dTable.AddCell(pdfUtility.BuildCell(pageDatas[i].Header.COL10, new iTextSharp.text.Font(BF_Light, TableFontSize)));

                if (pageDatas[i].Details != null && pageDatas[i].Details.Count > 0)
                {
                    //order
                    //pageDatas[i].Details.OrderBy(a => a.COL01);

                    int indexPoint = 1;
                    foreach (var item in pageDatas[i].Details)
                    {
                        dTable.AddCell(pdfUtility.BuildCell(indexPoint.ToString(), new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        indexPoint++;
                        dTable.AddCell(pdfUtility.BuildCell(item.COL01, new iTextSharp.text.Font(BF_Light, BigTableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL02, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL03, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL04, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL05, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL06, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL07, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL08, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL09, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                        dTable.AddCell(pdfUtility.BuildCell(item.COL10, new iTextSharp.text.Font(BF_Light, TableFontSize)));
                    }
                    doc.Add(dTable);

                    Paragraph pLast = new Paragraph(string.Format("Total Items:{0}          ", pageDatas[i].Details.Count.ToString()), new iTextSharp.text.Font(BF_Light, ContentFontSize));
                    pLast.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(pLast);
                }

                //footer  part
                //
                sData.Clear();
                sData.Add(pageDatas[i].Header.FOOTER1 ?? string.Empty);
                sData.Add(pageDatas[i].Header.FOOTER2 ?? string.Empty);
                sData.Add(pageDatas[i].Header.FOOTER3 ?? string.Empty);

                PdfContentByte cb = writer.DirectContent;
                ColumnText     ct = new ColumnText(cb);
                cb.BeginText();
                cb.SetFontAndSize(BF_Light, FooterFontSize);
                cb.SetTextMatrix(doc.LeftMargin, doc.BottomMargin);
                cb.ShowText(pdfUtility.GetLineString(sData));
                cb.EndText();

                if ((i + 1) < pageDatas.Count)
                {
                    pHelper.CurrentGroup = pageDatas[i + 1].Header.LODNUM;
                    if (!string.IsNullOrEmpty(pageDatas[i + 1].Header.LOGO))
                    {
                        pHelper.LogoPath = BasePath.Replace("temp", "images") + pageDatas[i + 1].Header.LOGO;
                    }
                    else
                    {
                        pHelper.LogoPath = null;
                    }
                }
            }

            doc.Close();

            //add track data

            //string sourceString1 = hData.SHIP_ID + "C";
            //RP_SHIP_TRACK_BLL trackBLL = new RP_SHIP_TRACK_BLL();
            //foreach (var item in dPrintList)
            //{
            //    RP_SHIP_TRACK track = new RP_SHIP_TRACK();
            //    track.WH_ID = item.WH_ID;
            //    track.SHIP_ID = item.SHIP_ID;

            //    if (wbType.TRACK_NUM_BY_IHUB == CHubConstValues.IndY)
            //        track.TRACK_NUM_IHUB = sourceString1;
            //    else
            //        track.TRACK_NUM_IHUB = "IHUB_Printed";

            //    track.RECORD_DATE = DateTime.Now;
            //    track.UPDATED_BY = appUser;
            //    trackBLL.AddOrUpdate(track);
            //}


            return(fileName);
        }
Beispiel #2
0
        public string BuildPDF(List <V_PLABEL_PRINT> printDatas, List <LabelPrintItem> labelItems)
        {
            string fileName = string.Format("labelPrint-{0}.pdf", DateTime.Now.ToString("yyyyMMddHHmm"));
            string fullPath = BasePath + fileName;

            //List<string> sData = new List<string>();

            //each page size get from header ,
            Document doc = new Document(pdfUtility.GetDocRectangle(printDatas[0].PAPER_HORIZONTAL.Value, printDatas[0].PAPER_VERTICAL.Value));

            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(fullPath, FileMode.Create));


            // PackPageEventHelper pHelper = new PackPageEventHelper();
            //writer.PageEvent = pHelper;

            doc.SetMargins(10f, 10f, 0f, 0f);

            int headerHeight = fontHelper.GetFontHeight(printDatas[0].HEADER, new System.Drawing.Font("黑体", ContentFontSize, System.Drawing.FontStyle.Bold));

            int ColumnHeight = fontHelper.GetFontHeight("柳工", new System.Drawing.Font("黑体", ContentFontSize)) + 1;
            int lineCount    = (int)((doc.Top - headerHeight) / ColumnHeight);
            int linePointer  = 1;

            for (int i = 0; i < printDatas.Count; i++)
            {
                //pHelper.CurrentGroup = pageDatas[i].Header.SHIP_ID;
                if (i != 0)
                {
                    doc.SetPageSize(pdfUtility.GetDocRectangle(printDatas[i].PAPER_HORIZONTAL.Value, printDatas[i].PAPER_VERTICAL.Value));
                    doc.NewPage();
                }
                else
                {
                    doc.Open();
                }

                int copies = (labelItems.FirstOrDefault(a => a.partNo == printDatas[i].PART_NO) ?? new LabelPrintItem()).copies;
                //in case senerio 0
                if (copies == 0)
                {
                    copies = 1;
                }

                for (int j = 0; j < copies; j++)
                {
                    if (j != 0)
                    {
                        doc.NewPage();
                    }

                    linePointer = 1;

                    Paragraph pUnit = new Paragraph(printDatas[i].HEADER, BoldFont);
                    doc.Add(pUnit);
                    linePointer++;

                    doc.Add(new Paragraph(Environment.NewLine, BoldFont));
                    linePointer++;

                    PdfPCell cellUnit;
                    //Content part
                    PdfPTable contentTable = new PdfPTable(4);
                    contentTable.WidthPercentage = 100f;
                    //contentTable.SplitRows = false;
                    contentTable.SetWidths(new float[] { 4f, 4f, 3f, 2f });

                    //line 1
                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T01, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C01, BoldFont));
                    cellUnit.BorderWidth = 0;
                    cellUnit.Colspan     = 3;
                    contentTable.AddCell(cellUnit);

                    linePointer++;

                    //Line 2
                    cellUnit             = new PdfPCell();
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    //picture
                    if (string.IsNullOrEmpty(printDatas[i].C01))
                    {
                        cellUnit = new PdfPCell();
                    }
                    else
                    {
                        cellUnit = new PdfPCell(pdfUtility.GetCode128Img(printDatas[i].C01, 9), true);
                    }
                    cellUnit.BorderWidth = 0;
                    cellUnit.Colspan     = 2;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell();
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    linePointer++;

                    //Line3
                    if (linePointer > lineCount)
                    {
                        doc.Add(contentTable);
                        continue;
                    }
                    //C09 prepare
                    string c09 = printDatas[i].C09;
                    if (string.IsNullOrEmpty(c09))
                    {
                        c09 = (labelItems.FirstOrDefault(a => a.partNo == printDatas[i].PART_NO) ?? new LabelPrintItem()).MOQ.ToString();
                    }

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T02, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C02, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T09, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(c09, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    linePointer++;


                    //Line 4
                    if (linePointer > lineCount)
                    {
                        doc.Add(contentTable);
                        continue;
                    }
                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T03, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C03, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    //picture
                    if (string.IsNullOrEmpty(c09))
                    {
                        cellUnit = new PdfPCell();
                    }
                    else
                    {
                        cellUnit = new PdfPCell(pdfUtility.GetCode128Img(c09, 9), false);
                    }
                    cellUnit.BorderWidth = 0;
                    cellUnit.Colspan     = 2;
                    contentTable.AddCell(cellUnit);

                    linePointer++;

                    //line 5
                    if (linePointer > lineCount)
                    {
                        doc.Add(contentTable);
                        continue;
                    }
                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T04, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C04, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T10, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C10, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    linePointer++;
                    //line 6
                    if (linePointer > lineCount)
                    {
                        doc.Add(contentTable);
                        continue;
                    }
                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T05, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C05, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    //picture
                    if (string.IsNullOrEmpty(printDatas[i].C10))
                    {
                        cellUnit = new PdfPCell();
                    }
                    else
                    {
                        cellUnit = new PdfPCell(pdfUtility.GetCode128Img(printDatas[i].C10, 9), false);
                    }
                    cellUnit.BorderWidth = 0;
                    cellUnit.Colspan     = 2;
                    contentTable.AddCell(cellUnit);

                    linePointer++;

                    //line 7
                    if (linePointer > lineCount)
                    {
                        doc.Add(contentTable);
                        continue;
                    }
                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T06, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C06, BoldFont));
                    cellUnit.BorderWidth = 0;
                    cellUnit.Colspan     = 3;
                    contentTable.AddCell(cellUnit);


                    linePointer++;
                    //c07 may have new line, if have new line ,need add linePointer
                    //int c01Line = printDatas[i].C07.Count<char>(a => a == Environment.NewLine);
                    //if (printDatas[i].C07.Contains(Environment.NewLine))
                    Regex           rg = new Regex("\n");
                    MatchCollection mc = rg.Matches(printDatas[i].C07);
                    linePointer += mc.Count;

                    //Line 8
                    if (linePointer > lineCount)
                    {
                        doc.Add(contentTable);
                        continue;
                    }
                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T07, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C07, BoldFont));
                    cellUnit.BorderWidth = 0;
                    cellUnit.Colspan     = 3;
                    contentTable.AddCell(cellUnit);


                    //line9
                    if (linePointer > lineCount)
                    {
                        doc.Add(contentTable);
                        continue;
                    }
                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].T08, BoldFont));
                    cellUnit.BorderWidth = 0;
                    contentTable.AddCell(cellUnit);

                    cellUnit             = new PdfPCell(new Paragraph(printDatas[i].C08, BoldFont));
                    cellUnit.BorderWidth = 0;
                    cellUnit.Colspan     = 3;
                    contentTable.AddCell(cellUnit);


                    doc.Add(contentTable);
                }
            }
            doc.Close();

            return(fileName);
        }