本文介绍了ASP.Net C#PDFPTable打印头表上面的详细信息表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,

我目前正在构建一个PDF文档,并显示有关游乐设施和驱动程序的信息。在每个页面的顶部,我想要一个标题,并在所有游乐设施的桌子下面。

我所有游乐设施的桌子都没有任何问题。

至于我什么时候在每个页面的顶部创建表格我在每页的顶部都会重复4次。

我一直试图解决这个问题几个小时,到目前为止没有运气

Hello All,
I am currently building a PDF document and having it show information about rides and drivers. At the top of each page i want a header and underneath a table of all the rides.
my table of all the rides works without any problems.
As for when i create the table on the top of each page i get duplicates 4 times on top of every page.
I have been trying to solve this for hours and so far no luck

class PrintForAccess
    {
        Document PrintDoc;
        const int LINES_PER_ACCESS2CARE_DOC = 5;
        int pageCount = 0;
        PdfWriter writer;
        int patientCounter = 0;

        public void PrintPDF(IEnumerable<ride> records, DateTime ridedate, int driverid,
            bool groupByDriver, string username, Stream outputstream, int tenantid, bool splitByDriver = false)
        {
            var db = new DBDataContext(tenantid);
            tenant tenant = db.tenants.SingleOrDefault(t => t.id == tenantid);
            string city = tenant != null ? tenant.defaultcity : "";
            string state = tenant != null ? tenant.defaultstate : "";

            PrintDoc = new iTextSharp.text.Document(PageSize.LETTER.Rotate(), .2f, .2f, .2f, .2f);
            writer = PdfWriter.GetInstance(PrintDoc, outputstream);
            PdfAcroForm acroForm = writer.AcroForm;

            PrintDoc.Open();
            BaseFont times = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
            float fontSize = 9;
            float titleFontSize = 10;
            var defaultFont = new iTextSharp.text.Font(times, fontSize);
            var boldHeaderFont = new iTextSharp.text.Font(times, titleFontSize, iTextSharp.text.Font.BOLD);
            var headerFont = new iTextSharp.text.Font(times, titleFontSize);
            var largeTitleFont = new iTextSharp.text.Font(times, 15, iTextSharp.text.Font.BOLD);

            string strTenant = new DriveApp.Controllers.AdminController().GetTenantName(username);
            string strDate = ridedate.ToShortDateString();

            DateTime now = DateTime.Today;
            string strDateToday = now.ToString("mm/dd/yyyy");

            PdfPTable headerTable = new PdfPTable(6);
            PdfPCell c1r1head = new PdfPCell(new Phrase("Provider: ", boldHeaderFont));
            c1r1head.PaddingTop = 5f;
            c1r1head.BorderWidth = 0f;
            c1r1head.PaddingLeft = -30f;
            PdfPCell c2r1head = new PdfPCell(new Phrase(strTenant, headerFont));
            c2r1head.PaddingTop = 5f;
            c2r1head.PaddingLeft = -60f;
            c2r1head.BorderWidth = 0f;
            PdfPCell c3r1head = new PdfPCell(new Phrase("Date Of Service: ", boldHeaderFont));
            c3r1head.PaddingTop = 5f;
            c3r1head.PaddingLeft = -30f;
            c3r1head.BorderWidth = 0f;
            PdfPCell c4r1head = new PdfPCell(new Phrase(strDateToday, headerFont));
            c4r1head.PaddingTop = 5f;
            c4r1head.PaddingLeft = -50f;
            c4r1head.BorderWidth = 0f;
            PdfPCell c5r1head = new PdfPCell(new Phrase("Check In____:____AM PM",headerFont));
            c5r1head.PaddingTop = 5f;
            c5r1head.PaddingLeft = -30f;
            c5r1head.BorderWidth = 0f;
            PdfPCell c6r1head = new PdfPCell(new Phrase("Check Out____:____AM PM",headerFont));
            c6r1head.PaddingLeft = -10f;
            c6r1head.PaddingRight = -20f;
            c6r1head.PaddingTop = 5f;
            c6r1head.BorderWidth = 0f;
            //row 2
            PdfPCell c1r2head = new PdfPCell(new Phrase("Vehicle/VIN: ", boldHeaderFont));
            c1r2head.PaddingTop = 4f;
            c1r2head.PaddingLeft = -30f;
            c1r2head.BorderWidth = 0f;
            PdfPCell c2r2head = new PdfPCell(new Phrase("vehicle# "+vinLast4digits, headerFont));
            c2r2head.PaddingLeft = -60f;
            c2r2head.BorderWidth = 0f;
            PdfPCell c3r2head = new PdfPCell(new Phrase("Driver Name: ", boldHeaderFont));
            c3r2head.PaddingLeft = -30f;
            c3r2head.BorderWidth = 0f;
            PdfPCell c4r2head = new PdfPCell(new Phrase("", headerFont));
            c4r2head.PaddingLeft = -50f;
            c4r2head.BorderWidth = 0f;
            //PdfPCell c5r2head = new PdfPCell(new Phrase("", boldHeaderFont));
            //row 3
            PdfPCell c1r3head = new PdfPCell(new Phrase("Driver Signature: ", boldHeaderFont));
            c1r3head.PaddingLeft = -30f;
            c1r3head.BorderWidth = 0f;
            PdfPCell c2r3head = new PdfPCell(new Phrase(""));
            c2r3head.BorderWidth = 0f;
            PdfPCell c4r3head = new PdfPCell(new Phrase("AccessPDF", largeTitleFont));
            c4r3head.Colspan = 2;
            c4r3head.Border = 0;
            c4r3head.PaddingTop = 2f;
            PdfPCell c5r3head = new PdfPCell(new Phrase("Check In____:____AM PM", headerFont));
            c5r3head.PaddingTop = 5f;
            c5r3head.PaddingLeft = -30f;
            c5r3head.BorderWidth = 0f;
            PdfPCell c6r3head = new PdfPCell(new Phrase("Check Out____:____AM PM", headerFont));
            c6r3head.PaddingRight = -20f;
            c6r3head.PaddingTop = 5f;
            c6r3head.PaddingLeft = -10f;
            c6r3head.BorderWidth = 0f;

            headerTable.AddCell(c4r3head);            
            headerTable.AddCell(c3r1head);
            headerTable.AddCell(c4r1head);
            headerTable.AddCell(c5r1head);
            headerTable.AddCell(c6r1head);
            //row2
            headerTable.AddCell(c1r2head);
            headerTable.AddCell(c2r2head);
            headerTable.AddCell(c3r2head);
            headerTable.AddCell(c4r2head);
            headerTable.AddCell(c2r3head);
            headerTable.AddCell(c2r3head);
            //row3
            headerTable.AddCell(c1r1head);
            headerTable.AddCell(c2r1head);
            headerTable.AddCell(c1r3head);
            headerTable.AddCell(c2r3head);
            //headerTable.AddCell(c4r3head);
            //headerTable.AddCell(c2r3head);
            headerTable.AddCell(c5r3head);
            headerTable.AddCell(c6r3head);            

            //PrintDoc.Add(headerTable);

            PdfPTable table = printAccessInitTable(defaultFont);
            PdfPTable headTable = printHeadTableAccess(headerFont);

            int detailLine = 0;
            driver previousDriver = null;
            bool firstRec = true;
foreach(ride record in records)
            {
                if(groupByDriver && record.driver != previousDriver || firstRec)
                {
                    detailLine = 0;
                    if(!firstRec)
                    {
                        //print5blanksmethod
                    }
                    previousDriver = record.driver;
                    detailLine = 0;
                    //printAccess2CareHeader(headTable, record, ridedate, username);
                    printAccess2CareNewPage(ref table, ref headTable, defaultFont, headerFont, firstRec);

                    //if(record.driver != null && (driverid != 0 || groupByDriver))
                    //{
                    //    //pageHeaderWithDriver.Add(new Phrase(titlec1 + record.driver.person.fullname, headerFont));
                    //    c4r2head = new PdfPCell(new Phrase(record.driver.person.fullname, headerFont));
                    //    headerTable.AddCell(c4r2head);
                    //}
                  //  printAccess2CareDoc.Add(headerTable);
                   // table = printAccess2CareInitTable(defaultFont);
                }
                //printAccess2CareHeader(headTable, record, ridedate, username);
                printAccess2CareDetail(table, defaultFont, writer, record, ridedate);

                if((++detailLine) == LINES_PER_ACCESS2CARE_DOC)
                {
                    detailLine = 0;
                    //print new page
                    printAccess2CareNewPage(ref table, ref headTable, defaultFont, headerFont, false);
                }
                firstRec = false;
            }
            //print 5 blanks
            printAccess2CareFooter(defaultFont);
            //printAccess2CareHeader(headTable, record, ridedate, username);
            printAccess2CareDoc.Add(headTable);
            printAccess2CareDoc.Add(table);

            if (!splitByDriver)
                printAccess2CareDoc.Close();
            else
                printAccess2CareDoc.CloseDocument();
            return;        }
        private void printAccessNewPage(ref PdfPTable table, ref PdfPTable headTable, iTextSharp.text.Font defaultFont, iTextSharp.text.Font headerFont, bool suppressFooter)
        {
            if(!suppressFooter)
            {
                PrintDoc.Add(headTable);
                PrintDoc.Add(table);  
                printAccess2CareFooter(defaultFont);
                PrintDoc.NewPage();
            }
            headTable = printHeadTableAccess(headerFont);
            table = printAccessInitTable(defaultFont);
        }
        private PdfPTable printAccessInitTable(iTextSharp.text.Font defaultFont)
        {
            const int COLUMN_COUNT = 4;
            PdfPTable table = new PdfPTable(COLUMN_COUNT);
            table.DefaultCell.Phrase = new Phrase("", defaultFont);
            table.TotalWidth = 760f;
            table.LockedWidth = true;
            float[] widths = new float[] { 120f, 200f, 150f, 130f };
            table.SetWidths(widths);
            table.SpacingBefore = 5f;
            return table;
        }

        private PdfPTable printHeadTableAccess(iTextSharp.text.Font headfont)
        {
            const int COLUMNS = 3;
            PdfPTable table = new PdfPTable(COLUMNS);
            table.DefaultCell.Phrase = new Phrase("", headfont);
            table.DefaultCell.Border = Rectangle.NO_BORDER;
            table.TotalWidth = 760f;
            table.LockedWidth = true;
            float[] widths = new float[] { 250f, 250f, 260f };
            table.SetWidths(widths);
            table.SpacingBefore = 1f;
            return table;
        }

        private void printAccessHeader(PdfPTable table, ride ride, DateTime rideDate, string usernam)
        {
            BaseFont times = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
            float titleFontSize = 10;
            var boldHeaderFont = new iTextSharp.text.Font(times, titleFontSize, iTextSharp.text.Font.BOLD);
            var headerFont = new iTextSharp.text.Font(times, titleFontSize);
            var largeTitleFont = new iTextSharp.text.Font(times, 15, iTextSharp.text.Font.BOLD);
            /** Ride Date **/
            string theRideDate = rideDate.ToString();
            /** Member Name **/
            string strMemberName = ride.customer.person.fullname != null ? ride.customer.person.fullname : "";
            /** Provider Tenant **/
            string strTenant = new DriveApp.Controllers.AdminController().GetTenantName(usernam);
            /** Last 4 digits of VIN # **/
            string wholeVIN = ride.vehicle.vehicleidentificationnumber;
            //string lastFourOfVIN = wholeVIN.Substring(wholeVIN.Length - 4, wholeVIN.Length-1);

            PdfPTable headerTable1 = new PdfPTable(2);// (6);
            PdfPCell c1r1head = new PdfPCell(new Phrase("Provider: ", boldHeaderFont));
            c1r1head.PaddingTop = 5f;
            c1r1head.BorderWidth = 0f;
            c1r1head.PaddingLeft = -30f;
            PdfPCell c2r1head = new PdfPCell(new Phrase(strTenant, headerFont));
            c2r1head.PaddingTop = 5f;
            c2r1head.PaddingLeft = -60f;
            c2r1head.BorderWidth = 0f;
            PdfPCell c3r1head = new PdfPCell(new Phrase("Date Of Service: ", boldHeaderFont));
            c3r1head.PaddingTop = 5f;
            c3r1head.PaddingLeft = -30f;
            c3r1head.BorderWidth = 0f;
            PdfPCell c4r1head = new PdfPCell(new Phrase(theRideDate, headerFont));
            c4r1head.PaddingTop = 5f;
            c4r1head.PaddingLeft = -50f;
            c4r1head.BorderWidth = 0f;
            PdfPCell c5r1head = new PdfPCell(new Phrase("Check In____:____AM PM", headerFont));
            c5r1head.PaddingTop = 5f;
            c5r1head.PaddingLeft = -30f;
            c5r1head.BorderWidth = 0f;
            PdfPCell c6r1head = new PdfPCell(new Phrase("Check Out____:____AM PM", headerFont));
            c6r1head.PaddingLeft = -10f;
            c6r1head.PaddingRight = -20f;
            c6r1head.PaddingTop = 5f;
            c6r1head.BorderWidth = 0f;
            //row 2
            PdfPTable headerTable2 = new PdfPTable(6);
            PdfPCell c1r2head = new PdfPCell(new Phrase("Vehicle/VIN: ", boldHeaderFont));
            c1r2head.PaddingTop = 4f;
            c1r2head.PaddingLeft = -30f;
            c1r2head.BorderWidth = 0f;
            PdfPCell c2r2head = new PdfPCell(new Phrase("vehicle# " /*+ vinLast4digits*/, headerFont));
            c2r2head.PaddingLeft = -60f;
            c2r2head.BorderWidth = 0f;
            PdfPCell c3r2head = new PdfPCell(new Phrase("Driver Name: ", boldHeaderFont));
            c3r2head.PaddingLeft = -30f;
            c3r2head.BorderWidth = 0f;
            PdfPCell c4r2head = new PdfPCell(new Phrase(/*record.driver.person.fullname*/"", headerFont));
            c4r2head.PaddingLeft = -50f;
            c4r2head.BorderWidth = 0f;
            //PdfPCell c5r2head = new PdfPCell(new Phrase("", boldHeaderFont));
            //row 3
            PdfPTable headerTable3 = new PdfPTable(6);
            PdfPCell c1r3head = new PdfPCell(new Phrase("Driver Signature: ", boldHeaderFont));
            //c1r3head.PaddingTop = 10f;
            c1r3head.PaddingLeft = -30f;
            c1r3head.BorderWidth = 0f;
            PdfPCell c2r3head = new PdfPCell(new Phrase(""));
            c2r3head.BorderWidth = 0f;
            PdfPCell c4r3head = new PdfPCell(new Phrase("Access2Care", largeTitleFont));
            c4r3head.Colspan = 2;
            c4r3head.Border = 0;
            c4r3head.PaddingTop = 2f;
            PdfPCell c5r3head = new PdfPCell(new Phrase("Check In____:____AM PM", headerFont));
            //c5r3head.PaddingRight = 20f;
            c5r3head.PaddingTop = 5f;
            c5r3head.PaddingLeft = -30f;
            c5r3head.BorderWidth = 0f;
            PdfPCell c6r3head = new PdfPCell(new Phrase("Check Out____:____AM PM", headerFont));
            c6r3head.PaddingRight = -20f;
            c6r3head.PaddingTop = 5f;
            c6r3head.PaddingLeft = -10f;
            c6r3head.BorderWidth = 0f;

            headerTable1.AddCell(c4r3head);
            headerTable1.AddCell(c1r2head);
            headerTable1.AddCell(c2r2head);
            headerTable1.AddCell(c1r1head);
            headerTable1.AddCell(c2r1head);

            headerTable2.AddCell(c3r1head);
            headerTable2.AddCell(c4r1head);
            headerTable2.AddCell(c3r2head);
            headerTable2.AddCell(c4r2head);
            headerTable2.AddCell(c1r3head);
            headerTable2.AddCell(c2r3head);

            headerTable3.AddCell(c5r1head);
            headerTable3.AddCell(c6r1head);
            headerTable3.AddCell(c2r3head);
            headerTable3.AddCell(c2r3head);
            headerTable3.AddCell(c5r3head);
            headerTable3.AddCell(c6r3head);
            
            table.AddCell(headerTable1);            
            table.AddCell(headerTable2);
            table.AddCell(headerTable3);
        }

        private void printAccessFivelengths(ref PdfPTable table, iTextSharp.text.Font defaultFont, int currentLines, PdfPTable myHeader, iTextSharp.text.Font headerFont)
        {
            var boldFont = new iTextSharp.text.Font(defaultFont);
            boldFont.SetStyle(iTextSharp.text.Font.BOLD);

            for (int i = 0; i < 5; ++i)
            {
                if (i + currentLines == LINES_PER_ACCESS2CARE_DOC)
                {
                    currentLines = 0;
                    printAccessNewPage(ref table, ref myHeader, defaultFont, headerFont, false);
                    PdfPTable tablecell1 = new PdfPTable(2);
                    Phrase cell1word = new Phrase();
                    cell1word.Add(new Chunk(".Pickup: ", defaultFont));
                    PdfPCell cell1table = new PdfPCell(cell1word);
                    cell1table.Border = 0;
                    PdfPCell cell2table = new PdfPCell(new Phrase("", defaultFont));
                    cell2table.Border = 0;
                    PdfPCell cell1row2 = new PdfPCell(new Phrase("Drop Off:\nTrip No: ", defaultFont));
                    cell1row2.Border = 0;
                    PdfPCell cell2row2 = new PdfPCell(new Phrase("" + "\n" + "", defaultFont));
                    cell2row2.Border = 0;
                    PdfPCell cell1row3 = new PdfPCell(new Phrase("Mobility: \nPolicy No:", defaultFont));
                    cell1row3.Border = 0;
                    PdfPCell cell2row3 = new PdfPCell(new Phrase("" + "\n" + "", defaultFont));
                    cell2row3.Border = 0;
                    PdfPCell cell1row4 = new PdfPCell(new Phrase("Notes: ", defaultFont));
                    cell1row4.Border = 0;
                    PdfPCell cell2row4 = new PdfPCell(new Phrase("", defaultFont));
                    cell2row4.Border = 0;
                    tablecell1.AddCell(cell1table);
                    tablecell1.AddCell(cell2table);
                    tablecell1.AddCell(cell1row2);
                    tablecell1.AddCell(cell2row2);
                    tablecell1.AddCell(cell1row3);
                    tablecell1.AddCell(cell2row3);
                    tablecell1.AddCell(cell1row4);
                    tablecell1.AddCell(cell2row4);
                    PdfPTable tablecell2 = new PdfPTable(3);
                    PdfPCell cell3row1 = new PdfPCell(new Phrase("Pick-Up:\n\nHome #", defaultFont));
                    cell3row1.Colspan = 3;
                    cell3row1.Border = 0;
                    PdfPCell cell3row2 = new PdfPCell(new Phrase("Destination:\n\nCell #", defaultFont));
                    cell3row2.Colspan = 3;
                    cell3row2.Border = 0;
                    PdfPCell cell3row3 = new PdfPCell(new Phrase("Arrival", defaultFont));
                    cell3row3.Border = 0;
                    PdfPCell cell4row3 = new PdfPCell(new Phrase(""));
                    cell4row3.Border = 0;
                    PdfPCell cell5row3 = new PdfPCell(new Phrase("Departure", defaultFont));
                    cell5row3.Border = 0;
                    tablecell2.AddCell(cell3row1);
                    tablecell2.AddCell(cell3row2);
                    tablecell2.AddCell(cell3row3);
                    tablecell2.AddCell(cell4row3);
                    tablecell2.AddCell(cell5row3);
                    PdfPTable tablecell3 = new PdfPTable(4);
                    PdfPCell cell6row1 = new PdfPCell(new Phrase("Pickup\nTime", defaultFont));
                    cell6row1.Border = 0;
                    PdfPCell cell7row1 = new PdfPCell(new Phrase(""));
                    cell7row1.Border = 0;
                    PdfPCell cell8row1 = new PdfPCell(new Phrase("Pickup\nODO", defaultFont));
                    cell8row1.Border = 0;
                    PdfPCell cell9row1 = new PdfPCell(new Phrase(""));
                    cell9row1.Border = 0;
                    PdfPCell cell6row2 = new PdfPCell(new Phrase("DropOff\nTime", defaultFont));
                    cell6row2.Border = 0;
                    PdfPCell cell7row2 = new PdfPCell(new Phrase(""));
                    cell7row2.Border = 0;
                    PdfPCell cell8row2 = new PdfPCell(new Phrase("DropOff\nODO", defaultFont));
                    cell8row2.Border = 0;
                    PdfPCell cell9row2 = new PdfPCell(new Phrase(""));
                    cell9row2.Border = 0;
                    PdfPCell cell6row3 = new PdfPCell(new Phrase("Dropped\nOff", defaultFont));
                    cell6row3.Border = 0;
                    PdfPCell cell7row3 = new PdfPCell(new Phrase(""));
                    cell7row3.Border = 0;
                    PdfPCell cell8row3 = new PdfPCell(new Phrase("Mileage", defaultFont));
                    cell8row3.Border = 0;   
                    PdfPCell cell9row3 = new PdfPCell(new Phrase(""));
                    cell9row3.Border = 0;
                    tablecell3.AddCell(cell6row1);
                    tablecell3.AddCell(cell7row1);
                    tablecell3.AddCell(cell8row1);
                    tablecell3.AddCell(cell9row1);
                    tablecell3.AddCell(cell6row2);
                    tablecell3.AddCell(cell7row2);
                    tablecell3.AddCell(cell8row2);
                    tablecell3.AddCell(cell9row2);
                    tablecell3.AddCell(cell6row3);
                    tablecell3.AddCell(cell7row3);
                    tablecell3.AddCell(cell8row3);
                    tablecell3.AddCell(cell9row3);
                    PdfPTable tablecell4 = new PdfPTable(3);
                    PdfPCell cell10row1 = new PdfPCell(new Phrase("WCT", defaultFont));
                    cell10row1.Border = 0;
                    PdfPCell cell11row1 = new PdfPCell(new Phrase(""));
                    cell11row1.Border = 0;
                    PdfPCell cell12row1 = new PdfPCell(new Phrase("Completed", defaultFont));
                    cell12row1.Border = 0;
                    PdfPCell cell10row2 = new PdfPCell(new Phrase("WCF", defaultFont));
                    cell10row2.Border = 0;
                    PdfPCell cell11row2 = new PdfPCell(new Phrase(""));
                    cell11row2.Border = 0;
                    PdfPCell cell12row2 = new PdfPCell(new Phrase("Cancelled\n\nTurnback", defaultFont));
                    cell12row2.Border = 0;
                    PdfPCell cell10row3 = new PdfPCell(new Phrase("$", defaultFont));
                    cell10row3.Border = 0;
                    PdfPCell cell11row3 = new PdfPCell(new Phrase(""));
                    cell11row3.Border = 0;
                    PdfPCell cell12row3 = new PdfPCell(new Phrase("Attendant", defaultFont));
                    cell12row3.Border = 0;
                    PdfPCell cell10row4 = new PdfPCell(new Phrase("Patient\nSignature", defaultFont));
                    cell10row4.Border = 0;
                    PdfPCell cell11row4 = new PdfPCell(new Phrase(""));
                    cell11row4.Border = 0;
                    PdfPCell cell12row4 = new PdfPCell(new Phrase(""));
                    cell12row4.Border = 0;
                    tablecell4.AddCell(cell10row1);
                    tablecell4.AddCell(cell11row1);
                    tablecell4.AddCell(cell12row1);
                    tablecell4.AddCell(cell10row2);
                    tablecell4.AddCell(cell11row2);
                    tablecell4.AddCell(cell12row2);
                    tablecell4.AddCell(cell10row3);
                    tablecell4.AddCell(cell11row3);
                    tablecell4.AddCell(cell12row3);
                    tablecell4.AddCell(cell10row4);
                    tablecell4.AddCell(cell11row4);
                    tablecell4.AddCell(cell12row4);

                    table.SpacingBefore = 15f;
                    table.AddCell(tablecell1);
                    table.AddCell(tablecell2);
                    table.AddCell(tablecell3);
                    table.AddCell(tablecell4);
                }
            }
        }


        private void printAccessDetail(PdfPTable table, iTextSharp.text.Font defaultFont, PdfWriter writer, ride record, DateTime rideDate)
        {
            /** Home Phone**/
            string strHomePhone = record.customer.person.homephone != null
                            && record.customer.person.homephone.ToString().Length > 0
                            ? record.customer.person.homephone.ToString() : "";
            /** Cell Phone **/
            string strCellPhone = record.customer.person.cellphone != null
                            && record.customer.person.cellphone.ToString().Length > 0
                            ? record.customer.person.cellphone.ToString() : "";
            /** Pickup Time **/
            string strPickupTime = "";
            if (record.pickuptime != null)
            { 
                DateTime pickuptime = new DateTime(record.pickuptime.Value.Ticks);
                strPickupTime = pickuptime.ToString("h:mm t").ToLower();
            }
            else if (record.address != null && record.address.address1 != "")
            {
                strPickupTime = "Call";
            }
            /** From Address **/
            string strFromAddress = record.address != null ? record.address.fulladdress : "";
            if (record.address != null)
            {
                if (!string.IsNullOrEmpty(record.address.phone))
                {
                    strFromAddress += " " + record.address.phone;
                }
            }
            /** To Address **/
            string strToAddress = record.address1 != null ? record.address1.fulladdress : "";
            if (record.address1 != null)
            {
                if (!string.IsNullOrEmpty(record.address1.phone))
                    strToAddress += " " + record.address1.phone;
            }
            /** Member Name **/
            string strMemberName = record.customer.person.fullname != null ? record.customer.person.fullname : "";
            /** Distance **/
            string distance = "";
            if (record.fundingsourcedistance > 0)
                distance = String.Format("{0:.0}", record.fundingsourcedistance.Value);
            else
                distance = record.distance != null ? string.Format("{0:.0}", record.distance.Value) : "-";
            /** disability **/
            string strDisability = "";
            strDisability += record.customer.walker ? "wkr " : "";
            strDisability += record.customer.wheelchair ? "w/c " : "";
            strDisability += record.customer.blind ? "bln " : "";
            /** Notes **/
            string noteString = record.note + "//" + record.customer.notes;
            noteString = noteString.Replace("\r\n", "//").Replace("\r", "//").Replace("\n", "//").Trim('/');            

            PdfPTable tablec1r1 = new PdfPTable(2);
            //cell 1 & 2 row 1
            Phrase c1word = new Phrase();
            c1word.Add(new Chunk(record.dispatchnumber ?? "", new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.BOLD)));
            c1word.Add(new Chunk(".Pickup: ", defaultFont));
            PdfPCell cell1table = new PdfPCell(c1word);
            cell1table.Border = 0;
            PdfPCell cell2table = new PdfPCell(new Phrase(strMemberName, defaultFont));
            cell2table.BorderWidthRight = 0;
            cell2table.Border = 0;
            //cell 1 & 2 row 2
            PdfPCell cell1r2table = new PdfPCell(new Phrase("Drop Off: \nTrip No: ", defaultFont));
            cell1r2table.Border = 0;
            PdfPCell cwll2r2table = new PdfPCell(new Phrase("" +"\n"+ "", defaultFont));
            cwll2r2table.Border = 0;
            //cell 1 & 2 row 3
            PdfPCell cell1r3table = new PdfPCell(new Phrase("Mobility: \nPolicy No:", defaultFont)); 
            cell1r3table.Border = 0;
            PdfPCell cell2r3table = new PdfPCell(new Phrase(strDisability + "\n" + "", defaultFont));
            cell2r3table.Border = 0;
            //cell 1 & 2 row 4
            PdfPCell cell1r4table = new PdfPCell(new Phrase("Notes: ", defaultFont));
            PdfPCell cell2r4table = new PdfPCell(new Phrase(noteString, defaultFont));
            cell2r4table.Border = 0;
            cell1r4table.Border = 0;
            tablec1r1.AddCell(cell1table);
            tablec1r1.AddCell(cell2table);
            tablec1r1.AddCell(cell1r2table);
            tablec1r1.AddCell(cwll2r2table);
            tablec1r1.AddCell(cell1r3table);
            tablec1r1.AddCell(cell2r3table);
            tablec1r1.AddCell(cell1r4table);
            tablec1r1.AddCell(cell2r4table);
            //cell 3
            PdfPTable tablec2r1 = new PdfPTable(3);
            PdfPCell cell3r1table = new PdfPCell(new Phrase("Pick-Up:\n" + strFromAddress + "\nHome # " + strHomePhone, defaultFont));
            cell3r1table.Colspan = 3;
            cell3r1table.Border = 0;
            //cell 3 row 2
            PdfPCell cell3r2table = new PdfPCell(new Phrase("Destination:\n" + strToAddress + "\nCell # " + strCellPhone, defaultFont));
            cell3r2table.Colspan = 3;
            cell3r2table.Border = 0;
            //cell 3 row 3
            PdfPCell cell3r3table = new PdfPCell(new Phrase("Arrival", defaultFont));
            cell3r3table.Border = 0;
            PdfPCell cell4r3table = new PdfPCell(new Phrase(""));
            cell4r3table.Border = 0;
            PdfPCell cell5r3table = new PdfPCell(new Phrase("Departure", defaultFont));
            cell5r3table.Border = 0;
            tablec2r1.AddCell(cell3r1table);
            tablec2r1.AddCell(cell3r2table);
            tablec2r1.AddCell(cell3r3table);
            tablec2r1.AddCell(cell4r3table);
            tablec2r1.AddCell(cell5r3table);
            //cell 6 row 1
            PdfPTable tablec3r1 = new PdfPTable(4);
            PdfPCell cell6r1table = new PdfPCell(new Phrase("Pickup\nTime", defaultFont));
            cell6r1table.Border = 0;
            PdfPCell cell7r1table = new PdfPCell(new Phrase(strPickupTime ,defaultFont));
            cell7r1table.Border = 0;
            PdfPCell cell8r1table = new PdfPCell(new Phrase("Pickup\nODO", defaultFont));
            cell8r1table.Border = 0;
            PdfPCell cell9r1table = new PdfPCell(new Phrase("", defaultFont));
            cell9r1table.Border = 0;
            //row 2
            PdfPCell cell6r2table = new PdfPCell(new Phrase("DropOff\nTime", defaultFont));
            cell6r2table.Border = 0;
            PdfPCell cell7r2table = new PdfPCell(new Phrase("", defaultFont));
            cell7r2table.Border = 0;
            PdfPCell cell8r2table = new PdfPCell(new Phrase("DropOff\nODO", defaultFont));
            cell8r2table.Border = 0;
            PdfPCell cell9r2table = new PdfPCell(new Phrase("", defaultFont));
            cell9r2table.Border = 0;
            //row 3
            PdfPCell cell6r3table = new PdfPCell(new Phrase("Dropped\nOff", defaultFont));
            cell6r3table.Border = 0;
            PdfPCell cell7r3table = new PdfPCell(new Phrase("", defaultFont));
            cell7r3table.Border = 0;
            PdfPCell cell8r3table = new PdfPCell(new Phrase("Mileage", defaultFont));
            cell8r3table.Border = 0;
            PdfPCell cell9r3table = new PdfPCell(new Phrase(distance, defaultFont));
            cell9r3table.Border = 0;
            tablec3r1.AddCell(cell6r1table);
            tablec3r1.AddCell(cell7r1table);
            tablec3r1.AddCell(cell8r1table);
            tablec3r1.AddCell(cell9r1table);
            tablec3r1.AddCell(cell6r2table);
            tablec3r1.AddCell(cell7r2table);
            tablec3r1.AddCell(cell8r2table);
            tablec3r1.AddCell(cell9r2table);
            tablec3r1.AddCell(cell6r3table);
            tablec3r1.AddCell(cell7r3table);
            tablec3r1.AddCell(cell8r3table);
            tablec3r1.AddCell(cell9r3table);
            //row 4
            PdfPTable tablec4r1 = new PdfPTable(3);
            PdfPCell cell10r1table = new PdfPCell(new Phrase("WCT", defaultFont));
            cell10r1table.Border = 0;
            PdfPCell cell11r1table = new PdfPCell(new Phrase(""));
            cell11r1table.Border = 0;
            PdfPCell cell12r1table = new PdfPCell(new Phrase("Completed", defaultFont));
            cell12r1table.Border = 0;
            PdfPCell cell10r2table = new PdfPCell(new Phrase("WCF", defaultFont));
            cell10r2table.Border = 0;
            PdfPCell cell11r2table = new PdfPCell(new Phrase(""));
            cell11r2table.Border = 0;
            PdfPCell cell12r2table = new PdfPCell(new Phrase("Cancelled\n\nTurnback", defaultFont));
            cell12r2table.Border = 0;
            PdfPCell cell10r3table = new PdfPCell(new Phrase("$", defaultFont));
            cell10r3table.Border = 0;
            PdfPCell cell11r3table = new PdfPCell(new Phrase(""));
            cell11r3table.Border = 0;
            PdfPCell cell12r3table = new PdfPCell(new Phrase("Attendant", defaultFont));
            cell12r3table.Border = 0;
            PdfPCell cell10r4table = new PdfPCell(new Phrase("Patient\nSignature", defaultFont));
            cell10r4table.Border = 0;
            PdfPCell cell11r4table = new PdfPCell(new Phrase(""));
            cell11r4table.Border = 0;
            PdfPCell cell12r4table = new PdfPCell(new Phrase(""));
            cell12r4table.Border = 0;
            tablec4r1.AddCell(cell10r1table);
            tablec4r1.AddCell(cell11r1table);
            tablec4r1.AddCell(cell12r1table);
            tablec4r1.AddCell(cell10r2table);
            tablec4r1.AddCell(cell11r2table);
            tablec4r1.AddCell(cell12r2table);
            tablec4r1.AddCell(cell10r3table);
            tablec4r1.AddCell(cell11r3table);
            tablec4r1.AddCell(cell12r3table);
            tablec4r1.AddCell(cell10r4table);
            tablec4r1.AddCell(cell11r4table);
            tablec4r1.AddCell(cell12r4table);

            table.SpacingBefore = 15f;

            table.AddCell(tablec1r1);
            table.AddCell(tablec2r1);
            table.AddCell(tablec3r1);
            table.AddCell(tablec4r1);

           // table.Rows.Last().MaxHeights = 14;
        }
    }

推荐答案



这篇关于ASP.Net C#PDFPTable打印头表上面的详细信息表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:34