C#向PDF指定区域添加文字或图片

2021-07-11 02:05

阅读:624

标签:reg   over   day   substring   tostring   color   ted   element   fread   

            string url = Server.MapPath("../../WebFiles/教师职业发展报告.pdf");
            PdfReader pdfReader = new PdfReader(Server.MapPath("../../WebFiles/教师职业发展报告.pdf"));//读pdf
            PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(Server.MapPath("../../WebFiles/FZBG/" + studyClassId + "/教师职业发展报告-" + dt.Rows[0]["Name"] + ".pdf"), FileMode.Create, FileAccess.Write, FileShare.None));
            BaseFont baseFont = BaseFont.CreateFont("C:\\Windows\\Fonts\\simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//获取系统的字体
            BaseFont baseFontk = BaseFont.CreateFont("C:\\Windows\\Fonts\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);            #region 第一页
            iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 12);//黑体12号字体
            Phrase Num = new Phrase("201808080808", font);//编号
            Phrase ActualName = new Phrase(dt.Rows[0]["ActualName"].ToString(), font);//姓名
            Phrase Unit = new Phrase(dt.Rows[0]["OtherC1"].ToString(), font);//单位
            PdfContentByte over = pdfStamper.GetOverContent(1);//PdfContentBye类,用来设置图像和文本的绝对位置
            ColumnText.ShowTextAligned(over, Element.ALIGN_LEFT, Num, 130, 800, 0);
            ColumnText.ShowTextAligned(over, Element.ALIGN_CENTER, ActualName, 210, 220, 0);
            ColumnText.ShowTextAligned(over, Element.ALIGN_CENTER, Unit, 210, 182, 0);
            #endregion
            #region 第二页
            iTextSharp.text.Font font2 = new iTextSharp.text.Font(baseFont, 11);
            Phrase ActualName2 = new Phrase(dt.Rows[0]["ActualName"].ToString(), font2);//姓名
            Phrase StudentId = new Phrase(dt.Rows[0]["Name"].ToString(), font2);//学号
            Phrase Sex = new Phrase(dt.Rows[0]["sexs"].ToString(), font2);//性别
            Phrase StudentType = new Phrase(dt.Rows[0]["OtherC2"].ToString(), font2);//学员类别
            Phrase Birthday = new Phrase(dt.Rows[0]["BirthdayS"].ToString(), font2);//出生年月
            string duty = @"select Name from StudentDutyInfo 
inner join DutyInfo on StudentDutyInfo.DutyId=DutyInfo.ID
where StudentDutyInfo.StudentId=‘" + dt.Rows[0]["Id"].ToString() + "";
            DataTable dtduty = SqlHelper.ExecuteDataTable(SqlHelper.ConnString, CommandType.Text, duty, null);
            string dutyname = "";
            foreach (DataRow item in dtduty.Rows)
            {
                if (dutyname.Length > 0) { dutyname += ","; }
                dutyname += item["Name"].ToString();
            }
            Phrase Duty = new Phrase(dutyname, font2);//岗位
            Phrase Unit2 = new Phrase(dt.Rows[0]["OtherC1"].ToString(), font2);
            string zzdss = "";
            foreach (DataRow item in dutyclass.Rows)
            {
                if (item["Grade"].ToString() == "高级")
                {
                    zzdss = "高级";
                    break;
                }
                else if (item["Grade"].ToString() == "中级" || item["Grade"].ToString() == "初级")
                {
                    zzdss = "中级";
                    break;
                }
                else
                {
                    zzdss = "初级";
                    break;
                }
            }
            Phrase zzdj = new Phrase(zzdss, font2);//资质等级
            Phrase xueli = new Phrase(dt.Rows[0]["OtherC4"].ToString(), font2);//学历
            Phrase jszw = new Phrase(dt.Rows[0]["Duty"].ToString(), font2);//专业技术职务
            Phrase lxsj = new Phrase(dt.Rows[0]["JoinTimeS"].ToString(), font2);//来校时间
            Phrase cszy = new Phrase(dt.Rows[0]["OtherC3"].ToString(), font2);//从事专业
            PdfContentByte over2 = pdfStamper.GetOverContent(2);
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, ActualName2, 265, 600, 0);//姓名
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, StudentId, 450, 600, 0);//学号
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, Sex, 265, 568, 0);//性别
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, StudentType, 450, 568, 0);//学员类别
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, Birthday, 265, 536, 0);//出生年月
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, Duty, 450, 536, 0);//岗位
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, Unit2, 265, 504, 0);
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, zzdj, 450, 504, 0);
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, xueli, 265, 472, 0);
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, jszw, 450, 472, 0);
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, lxsj, 265, 440, 0);
            ColumnText.ShowTextAligned(over2, Element.ALIGN_CENTER, cszy, 450, 440, 0);
            iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(Server.MapPath("../../WebFiles/Picture/" + dt.Rows[0]["Name"].ToString() + ".jpg"));
            img.ScaleAbsolute(72, 100);
            img.SetAbsolutePosition(76, 475);
            over2.AddImage(img);
            #endregion
            foreach (DataRow item in dutyclass.Rows)
            {
                
            }
            //-----------------------------初级-----------------------------
            #region 第三页
            iTextSharp.text.Font font3 = new iTextSharp.text.Font(baseFont, 10);
            iTextSharp.text.Font font4 = new iTextSharp.text.Font(baseFontk, 12);
            Phrase year = new Phrase("2018", font3);
            Phrase month = new Phrase("08", font3);
            Phrase day = new Phrase("09", font3);
            Phrase CJ = new Phrase("100", font3);//成绩
            Phrase year1 = new Phrase("2018", font3);
            Phrase month1 = new Phrase("08", font3);
            Phrase day1 = new Phrase("09", font3);
            Phrase ZKKCMC = new Phrase("助课课程称阿德", font3);//助课课程名称
            Phrase ZKKCLB = new Phrase("助课课程类别阿萨德", font3);//助课课程类别
            Phrase ZKKCXS = new Phrase("助课课程学时撒的", font3);//助课课程学时
            string ZJJYS = "助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,";
            Phrase ZJJY = new Phrase();
            PdfContentByte over3 = pdfStamper.GetOverContent(3);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, year, 380, 370, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, month, 425, 370, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, day, 470, 370, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, CJ, 425, 352, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, year1, 380, 297, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, month1, 425, 297, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, day1, 470, 297, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, ZKKCMC, 410, 278, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, ZKKCLB, 410, 260, 0);
            ColumnText.ShowTextAligned(over3, Element.ALIGN_CENTER, ZKKCXS, 410, 242, 0);

            int h = ZJJYS.Length > 0 ? ((ZJJYS.Length 35) ? 1 : ((ZJJYS.Length % 35 != 0) ? (ZJJYS.Length / 35 + 1) : (ZJJYS.Length / 35))) : 0;
            int height = 150;
            int width = 110;
            int le = 0;
            int index = 0;
            for (int i = 1; i )
            {
                le = 35;
                if (i == 1)
                {
                    le = 33;
                }
                else
                {
                    if (i == 2)
                    {
                        index = index + 33;
                    }
                    else
                    {
                        index = index + le;
                    }
                    width = 90;
                }
                if (ZJJYS.Length - index 35)
                {
                    le = ZJJYS.Length - index;
                }


                ZJJY = new Phrase(ZJJYS.Substring(index, le), font4);//助课课程学时
                ColumnText.ShowTextAligned(over3, Element.ALIGN_LEFT, ZJJY, width, height, 0);
                height = height - 13;
            }
            #endregion
            //-----------------------------中级-----------------------------
            #region 第四页
            iTextSharp.text.Font font5 = new iTextSharp.text.Font(baseFont, 10);
            iTextSharp.text.Font font6 = new iTextSharp.text.Font(baseFontk, 12);
            Phrase year2 = new Phrase("2018", font5);
            Phrase month2 = new Phrase("08", font5);
            Phrase day2 = new Phrase("09", font5);
            string xetus = "建设心得题目建建设心得题目建建设心得题目建建设心得题目建建设心得题目建建设心得题目建";
            Phrase xetu = new Phrase(xetus, font5);//建设心得题目
            string ZJJYS1 = "助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,";
            Phrase ZJJY1 = new Phrase();
            Phrase ccmc = new Phrase("某某课程", font5);//课程名称
            Phrase cclb = new Phrase("某某课程某某课程", font5);//课程类别
            Phrase year3 = new Phrase("2018", font5);
            Phrase month3 = new Phrase("08", font5);
            Phrase day3 = new Phrase("09", font5);
            Phrase xmmc = new Phrase("项目名称", font5);//项目名称
            Phrase cszys = new Phrase("从事专业", font5);//从事专业
            Phrase year4 = new Phrase("2018", font5);
            Phrase month4 = new Phrase("08", font5);
            Phrase day4 = new Phrase("09", font5);
            Phrase zjkc = new Phrase("主讲课程", font5);//主讲课程
            PdfContentByte over4 = pdfStamper.GetOverContent(4);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, year2, 360, 443, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, month2, 405, 443, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, day2, 445, 443, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, ccmc, 389, 394, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, cclb, 389, 378, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, year3, 360, 330, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, month3, 405, 330, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, day3, 445, 330, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, xmmc, 389, 314, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, cszys, 389, 298, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, year4, 363, 251, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, month4, 408, 251, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, day4, 448, 251, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, zjkc, 389, 234, 0);
            ColumnText.ShowTextAligned(over4, Element.ALIGN_CENTER, cszys, 389, 218, 0);
            int hx = xetus.Length > 0 ? ((xetus.Length 21) ? 1 : ((xetus.Length % 21 != 0) ? (xetus.Length / 21 + 1) : (xetus.Length / 21))) : 0;
            int heightx = 425;
            int widthx = 285;
            int lex = 0;
            int indexx = 0;
            for (int i = 1; i )
            {
                lex = 21;
                if (i != 1)
                {
                    indexx = indexx + lex;
                }

                if (xetus.Length - indexx 21)
                {
                    lex = xetus.Length - indexx;
                }
                xetu = new Phrase(xetus.Substring(indexx, lex), font5);//助课课程学时
                ColumnText.ShowTextAligned(over4, Element.ALIGN_LEFT, xetu, widthx, heightx, 0);
                heightx = heightx - 13;
            }

            int h1 = ZJJYS1.Length > 0 ? ((ZJJYS1.Length 35) ? 1 : ((ZJJYS1.Length % 35 != 0) ? (ZJJYS1.Length / 35 + 1) : (ZJJYS1.Length / 35))) : 0;
            int height1 = 140;
            int width1 = 110;
            int le1 = 0;
            int index1 = 0;
            for (int i = 1; i )
            {
                le1 = 35;
                if (i == 1)
                {
                    le1 = 33;
                }
                else
                {
                    if (i == 2)
                    {
                        index1 = index1 + 33;
                    }
                    else
                    {
                        index1 = index1 + le1;
                    }
                    width1 = 90;
                }
                if (ZJJYS1.Length - index1 35)
                {
                    le1 = ZJJYS1.Length - index1;
                }


                ZJJY1 = new Phrase(ZJJYS1.Substring(index1, le1), font6);//助课课程学时
                ColumnText.ShowTextAligned(over4, Element.ALIGN_LEFT, ZJJY1, width1, height1, 0);
                height1 = height1 - 13;

            }
            #endregion
            //-----------------------------高级-----------------------------
            #region 第五页
            iTextSharp.text.Font font7 = new iTextSharp.text.Font(baseFont, 10);
            iTextSharp.text.Font font8 = new iTextSharp.text.Font(baseFontk, 12);
            Phrase year5 = new Phrase("2018", font7);
            Phrase month5 = new Phrase("08", font7);
            Phrase day5 = new Phrase("09", font7);
            string tuxds = "建设心得题目建建设心得题目建建设心得题目建建设心得题目建建设心得题目建建";
            Phrase tuxd = new Phrase(xetus, font5);//建设心得题目
            string ZJJYS2 = "助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,";
            Phrase ZJJY2 = new Phrase();
            Phrase ssx = new Phrase("所属系", font7);//所属系
            PdfContentByte over5 = pdfStamper.GetOverContent(5);
            ColumnText.ShowTextAligned(over5, Element.ALIGN_CENTER, year, 340, 310, 0);
            ColumnText.ShowTextAligned(over5, Element.ALIGN_CENTER, month, 386, 310, 0);
            ColumnText.ShowTextAligned(over5, Element.ALIGN_CENTER, day, 430, 310, 0);
            ColumnText.ShowTextAligned(over5, Element.ALIGN_CENTER, ssx, 400, 257, 0);
            ColumnText.ShowTextAligned(over5, Element.ALIGN_CENTER, cszys, 400, 234, 0);
            int hd = tuxds.Length > 0 ? ((tuxds.Length 19) ? 1 : ((tuxds.Length % 19 != 0) ? (tuxds.Length / 19 + 1) : (tuxds.Length / 19))) : 0;
            int heightd = 290;
            int widthd = 310;
            int led = 0;
            int indexd = 0;
            for (int i = 1; i )
            {
                led = 19;
                if (i != 1)
                {
                    indexd = indexd + led;
                }

                if (tuxds.Length - indexd 19)
                {
                    led = tuxds.Length - indexd;
                }
                tuxd = new Phrase(tuxds.Substring(indexd, led), font7);//助课课程学时
                ColumnText.ShowTextAligned(over5, Element.ALIGN_LEFT, tuxd, widthd, heightd, 0);
                heightd = heightd - 13;
            }
            int h2 = ZJJYS2.Length > 0 ? ((ZJJYS2.Length 35) ? 1 : ((ZJJYS2.Length % 35 != 0) ? (ZJJYS2.Length / 35 + 1) : (ZJJYS2.Length / 35))) : 0;
            int height2 = 140;
            int width2 = 110;
            int le2 = 0;
            int index2 = 0;
            for (int i = 1; i )
            {
                le2 = 35;
                if (i == 1)
                {
                    le2 = 33;
                }
                else
                {
                    if (i == 2)
                    {
                        index2 = index2 + 33;
                    }
                    else
                    {
                        index2 = index2 + le2;
                    }
                    width2 = 90;
                }
                if (ZJJYS2.Length - index2 35)
                {
                    le2 = ZJJYS2.Length - index2;
                }


                ZJJY2 = new Phrase(ZJJYS2.Substring(index2, le2), font8);//助课课程学时
                ColumnText.ShowTextAligned(over5, Element.ALIGN_LEFT, ZJJY2, width2, height2, 0);
                height2 = height2 - 13;
            }
            #endregion
            #region 第六页
            iTextSharp.text.Font font9 = new iTextSharp.text.Font(baseFont, 10);
            PdfContentByte over6 = pdfStamper.GetOverContent(6);
            for (int i = 0; i 5; i++)
            {
                Phrase bxmc = new Phrase("培训名称" + i, font9);//培训名称
                Phrase bxsj = new Phrase("2018-08-09" + i, font9);//培训时间
                Phrase bxdd = new Phrase("培训地点" + i, font9);//培训地点
                Phrase bxfs = new Phrase("培训方式" + i, font9);//培训方式
                Phrase bxdw = new Phrase("培训单位" + i, font9);//培训单位
                Phrase jg = new Phrase("合格" + i, font9);//培训结果
                if (i == 2)
                {
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxmc, 320, 598 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxsj, 245, 571 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxdd, 435, 571 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxfs, 245, 544 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxdw, 435, 544 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, jg, 320, 517 - (27 * 4 * i), 0);
                }
                else if (i == 3)
                {
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxmc, 320, 598 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxsj, 245, 569 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxdd, 435, 569 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxfs, 245, 542 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxdw, 435, 542 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, jg, 320, 515 - (27 * 4 * i), 0);
                }
                else if (i == 4)
                {
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxmc, 320, 595 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxsj, 245, 568 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxdd, 435, 568 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxfs, 245, 541 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxdw, 435, 541 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, jg, 320, 514 - (27 * 4 * i), 0);
                }
                else
                {
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxmc, 320, 599 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxsj, 245, 572 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxdd, 435, 572 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxfs, 245, 545 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, bxdw, 435, 545 - (27 * 4 * i), 0);
                    ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, jg, 320, 518 - (27 * 4 * i), 0);
                }
            }
            Phrase count = new Phrase("5", font9);//培训总数
            ColumnText.ShowTextAligned(over6, Element.ALIGN_CENTER, count, 160, 53, 0);
            #endregion
            #region 第七页
            iTextSharp.text.Font font10 = new iTextSharp.text.Font(baseFont, 10);
            PdfContentByte over7 = pdfStamper.GetOverContent(7);
            for (int i = 0; i 5; i++)
            {
                Phrase pjkcmc = new Phrase("评价课程名称" + i, font9);//评价课程名称
                Phrase pjcj = new Phrase("100", font9);//评价成绩
                Phrase avgcj = new Phrase("100", font9);//评价成绩
                ColumnText.ShowTextAligned(over7, Element.ALIGN_CENTER, pjkcmc, 270, 594 - (i * 4 * 14), 0);
                ColumnText.ShowTextAligned(over7, Element.ALIGN_CENTER, pjcj, 450, 594 - (i * 4 * 14), 0);
                ColumnText.ShowTextAligned(over7, Element.ALIGN_CENTER, avgcj, 240, 576 - (i * 4 * 14), 0);
            }
            Phrase avg = new Phrase("98", font10);//平均得分
            ColumnText.ShowTextAligned(over7, Element.ALIGN_CENTER, avg, 360, 312, 0);


            string ZJJYS4 = "助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,";
            Phrase ZJJY4 = new Phrase();
            int h4 = ZJJYS4.Length > 0 ? ((ZJJYS4.Length 35) ? 1 : ((ZJJYS4.Length % 35 != 0) ? (ZJJYS4.Length / 35 + 1) : (ZJJYS2.Length / 35))) : 0;
            int height4 = 255;
            int width4 = 110;
            int le4 = 0;
            int index4 = 0;
            for (int i = 1; i )
            {
                le4 = 35;
                if (i == 1)
                {
                    le4 = 33;
                }
                else
                {
                    if (i == 2)
                    {
                        index4 = index4 + 33;
                    }
                    else
                    {
                        index4 = index4 + le4;
                    }
                    width4 = 90;
                }
                if (ZJJYS4.Length - index4 35)
                {
                    le4 = ZJJYS4.Length - index4;
                }


                ZJJY4 = new Phrase(ZJJYS4.Substring(index4, le4), font8);//助课课程学时
                ColumnText.ShowTextAligned(over7, Element.ALIGN_LEFT, ZJJY4, width4, height4, 0);
                height4 = height4 - 13;
            }



            string ZJJYS3 = "助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,助课课程学时撒的助课课,";//教学信息员
            Phrase ZJJY3 = new Phrase();
            int h3 = ZJJYS3.Length > 0 ? ((ZJJYS3.Length 35) ? 1 : ((ZJJYS3.Length % 35 != 0) ? (ZJJYS3.Length / 35 + 1) : (ZJJYS2.Length / 35))) : 0;
            int height3 = 140;
            int width3 = 110;
            int le3 = 0;
            int index3 = 0;
            for (int i = 1; i )
            {
                le3 = 35;
                if (i == 1)
                {
                    le3 = 33;
                }
                else
                {
                    if (i == 2)
                    {
                        index3 = index3 + 33;
                    }
                    else
                    {
                        index3 = index3 + le3;
                    }
                    width3 = 90;
                }
                if (ZJJYS3.Length - index3 35)
                {
                    le3 = ZJJYS3.Length - index3;
                }


                ZJJY3 = new Phrase(ZJJYS3.Substring(index3, le3), font8);//助课课程学时
                ColumnText.ShowTextAligned(over7, Element.ALIGN_LEFT, ZJJY3, width3, height3, 0);
                height3 = height3 - 13;
            }
            #endregion
            pdfStamper.Close();

 

C#向PDF指定区域添加文字或图片

标签:reg   over   day   substring   tostring   color   ted   element   fread   

原文地址:https://www.cnblogs.com/luozhongtao/p/9667190.html


评论


亲,登录后才可以留言!