String path=GlobalParameter.absoluteProPath;
String ls_outPath = path+ "pdf\\" + wordExportUrl_pdf;
System.out.println(ls_outPath);
//建立Document对象的实例
Document document = new Document();
//建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中
PdfWriter.getInstance(document, new FileOutputStream(ls_outPath));
//打开文档
document.open();
// 中文字体
BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);//宋体
BaseFont msyh = BaseFont.createFont(path+"/fonts/msyh.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//微软雅黑
//中文标题
com.itextpdf.text.Font title1font = new com.itextpdf.text.Font(bfChinese, 14, com.itextpdf.text.Font.BOLD);
Paragraph title1=new Paragraph("孔子学院总部/国家汉办国家公派出国教师需求汇总表",title1font);
title1.setAlignment(Element.ALIGN_CENTER);
document.add(title1);
//英文标题
Paragraph title2=new Paragraph("Summary Sheet for Confucius Institute Headquarters/HanbanSponsored Chinese Teachers");
title2.setAlignment(Element.ALIGN_CENTER);
document.add(title2);
//文字块
TeacherPost2016 post=list.get(0);
List getzb = commonDao.findBySql("select name from pm_code_nation where level =1 and code="+post.getZb());//查询洲名称
com.itextpdf.text.Font ketangfont = new com.itextpdf.text.Font(msyh, 10, com.itextpdf.text.Font.NORMAL);
String zhou=getzb.get(0).toString();//(洲)
String guo=post.getNationName();//(国)
String ketang=post.getJobName();// 课堂
Chunk str1 = new Chunk("孔子学院(课堂)名称:",ketangfont);
document.add(str1);
Chunk zhoustr = new Chunk(zhou,ketangfont);
zhoustr.setUnderline(1f, -1f);//设置下划线 1f厚度(值越大下划线越粗)
document.add(zhoustr);
Chunk str2 = new Chunk("(洲)",ketangfont);
document.add(str2);
Chunk guostr = new Chunk(guo,ketangfont);
guostr.setUnderline(1f, -1f);//设置下划线 1f厚度(值越大下划线越粗)
document.add(guostr);
Chunk str3 = new Chunk("(国)",ketangfont);
document.add(str3);
Chunk ketangstr = new Chunk(ketang,ketangfont);
ketangstr.setUnderline(1f, -1f);//设置下划线 1f厚度(值越大下划线越粗)
document.add(ketangstr);
Chunk str4 = new Chunk("(孔子学院/课堂)",ketangfont);
document.add(str4);
// 表头
String[] tableHeader = { "序号", "岗位名称", "回国人数","需求人数", "教师类型"};
// 数据表字段数
int colNumber = 5;
// 表格的设置
int spacing = 1;
// 表格的设置
int padding = 1;
//边框颜色
BaseColor lightGrey = new BaseColor(0xCC,0xCC,0xCC,0xCC);
// 创建有5列的表格
PdfPTable datatable = new PdfPTable(colNumber);
//定义表格的宽度
int[] cellsWidth = { 2, 8, 3, 3, 8};
datatable.setWidths(cellsWidth);
// 表格的宽度百分比
datatable.setWidthPercentage(100);
datatable.getDefaultCell().setPadding(padding);
datatable.getDefaultCell().setBorderWidth(spacing);
datatable.getDefaultCell().setBorderColor(lightGrey);
datatable.setHorizontalAlignment(1);
// 添加表头
com.itextpdf.text.Font biaotou = new com.itextpdf.text.Font(msyh, 10, com.itextpdf.text.Font.NORMAL);
for (int i = 0; i < colNumber; i++) {
datatable.addCell(new Paragraph(tableHeader[i],biaotou));
}
// 添加数据
com.itextpdf.text.Font fontChinese = new com.itextpdf.text.Font(msyh, 8, com.itextpdf.text.Font.NORMAL);
int index=1;
for (TeacherPost2016 teac : list) {
datatable.addCell(new Paragraph(String.valueOf(index),fontChinese));//序号
datatable.addCell(new Paragraph(teac.getJobName(),fontChinese));//岗位名称
datatable.addCell(new Paragraph(String.valueOf(teac.getBackpeo()),fontChinese));//回国人数
datatable.addCell(new Paragraph(String.valueOf(teac.getPeople()),fontChinese));//需求人数
datatable.addCell(new Paragraph(teac.getType(),fontChinese));//教师类型
index++;
}
// //加入空行
com.itextpdf.text.Font fontkong = new com.itextpdf.text.Font(bfChinese, 4, com.itextpdf.text.Font.NORMAL);
Paragraph blankRow2 = new Paragraph(6f, " ", fontkong);
document.add(blankRow2);
//向文档中添加表格
document.add(datatable);
//加入空行
Paragraph blankRow3 = new Paragraph(16f, " ", fontChinese);
document.add(blankRow3);
//加入空行
Paragraph blankRow4 = new Paragraph(16f, " ", fontChinese);
document.add(blankRow4);
Paragraph sign=new Paragraph("孔子学院(课堂)负责人:(签名)(盖章)",ketangfont);
sign.setAlignment(Element.ALIGN_RIGHT);
document.add(sign);
//关闭文档
document.close();
String ls_outPath = path+ "pdf\\" + wordExportUrl_pdf;
System.out.println(ls_outPath);
//建立Document对象的实例
Document document = new Document();
//建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中
PdfWriter.getInstance(document, new FileOutputStream(ls_outPath));
//打开文档
document.open();
// 中文字体
BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);//宋体
BaseFont msyh = BaseFont.createFont(path+"/fonts/msyh.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//微软雅黑
//中文标题
com.itextpdf.text.Font title1font = new com.itextpdf.text.Font(bfChinese, 14, com.itextpdf.text.Font.BOLD);
Paragraph title1=new Paragraph("孔子学院总部/国家汉办国家公派出国教师需求汇总表",title1font);
title1.setAlignment(Element.ALIGN_CENTER);
document.add(title1);
//英文标题
Paragraph title2=new Paragraph("Summary Sheet for Confucius Institute Headquarters/HanbanSponsored Chinese Teachers");
title2.setAlignment(Element.ALIGN_CENTER);
document.add(title2);
//文字块
TeacherPost2016 post=list.get(0);
List getzb = commonDao.findBySql("select name from pm_code_nation where level =1 and code="+post.getZb());//查询洲名称
com.itextpdf.text.Font ketangfont = new com.itextpdf.text.Font(msyh, 10, com.itextpdf.text.Font.NORMAL);
String zhou=getzb.get(0).toString();//(洲)
String guo=post.getNationName();//(国)
String ketang=post.getJobName();// 课堂
Chunk str1 = new Chunk("孔子学院(课堂)名称:",ketangfont);
document.add(str1);
Chunk zhoustr = new Chunk(zhou,ketangfont);
zhoustr.setUnderline(1f, -1f);//设置下划线 1f厚度(值越大下划线越粗)
document.add(zhoustr);
Chunk str2 = new Chunk("(洲)",ketangfont);
document.add(str2);
Chunk guostr = new Chunk(guo,ketangfont);
guostr.setUnderline(1f, -1f);//设置下划线 1f厚度(值越大下划线越粗)
document.add(guostr);
Chunk str3 = new Chunk("(国)",ketangfont);
document.add(str3);
Chunk ketangstr = new Chunk(ketang,ketangfont);
ketangstr.setUnderline(1f, -1f);//设置下划线 1f厚度(值越大下划线越粗)
document.add(ketangstr);
Chunk str4 = new Chunk("(孔子学院/课堂)",ketangfont);
document.add(str4);
// 表头
String[] tableHeader = { "序号", "岗位名称", "回国人数","需求人数", "教师类型"};
// 数据表字段数
int colNumber = 5;
// 表格的设置
int spacing = 1;
// 表格的设置
int padding = 1;
//边框颜色
BaseColor lightGrey = new BaseColor(0xCC,0xCC,0xCC,0xCC);
// 创建有5列的表格
PdfPTable datatable = new PdfPTable(colNumber);
//定义表格的宽度
int[] cellsWidth = { 2, 8, 3, 3, 8};
datatable.setWidths(cellsWidth);
// 表格的宽度百分比
datatable.setWidthPercentage(100);
datatable.getDefaultCell().setPadding(padding);
datatable.getDefaultCell().setBorderWidth(spacing);
datatable.getDefaultCell().setBorderColor(lightGrey);
datatable.setHorizontalAlignment(1);
// 添加表头
com.itextpdf.text.Font biaotou = new com.itextpdf.text.Font(msyh, 10, com.itextpdf.text.Font.NORMAL);
for (int i = 0; i < colNumber; i++) {
datatable.addCell(new Paragraph(tableHeader[i],biaotou));
}
// 添加数据
com.itextpdf.text.Font fontChinese = new com.itextpdf.text.Font(msyh, 8, com.itextpdf.text.Font.NORMAL);
int index=1;
for (TeacherPost2016 teac : list) {
datatable.addCell(new Paragraph(String.valueOf(index),fontChinese));//序号
datatable.addCell(new Paragraph(teac.getJobName(),fontChinese));//岗位名称
datatable.addCell(new Paragraph(String.valueOf(teac.getBackpeo()),fontChinese));//回国人数
datatable.addCell(new Paragraph(String.valueOf(teac.getPeople()),fontChinese));//需求人数
datatable.addCell(new Paragraph(teac.getType(),fontChinese));//教师类型
index++;
}
// //加入空行
com.itextpdf.text.Font fontkong = new com.itextpdf.text.Font(bfChinese, 4, com.itextpdf.text.Font.NORMAL);
Paragraph blankRow2 = new Paragraph(6f, " ", fontkong);
document.add(blankRow2);
//向文档中添加表格
document.add(datatable);
//加入空行
Paragraph blankRow3 = new Paragraph(16f, " ", fontChinese);
document.add(blankRow3);
//加入空行
Paragraph blankRow4 = new Paragraph(16f, " ", fontChinese);
document.add(blankRow4);
Paragraph sign=new Paragraph("孔子学院(课堂)负责人:(签名)(盖章)",ketangfont);
sign.setAlignment(Element.ALIGN_RIGHT);
document.add(sign);
//关闭文档
document.close();
FileUtil.downAttach(ls_outPath,wordExportUrl_pdf,response, false);