iText 生成 PDF(java)

更新时间:2023-11-23 17:22:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

iText 生成 PDF (java)

标签: itextpdfit 分类: java技术文档

public class BL { ***

// private String rgtno = \

private SSRS ssrsRgtno = new SSRS();// rgtno 赔案号,grpcontno 团体保单号,grpname // 投保单位,endcasedate 结案日期

private SSRS ssrsCustomerno = new SSRS();// customerno客户号

private SSRS ssrsIdno = new SSRS();// idno 证件号,bankcode 银行编码,bankaccno // 账号,accname 户名

private SSRS ssrsOpt = new SSRS();// 门诊医疗费用理算信息: private SSRS ssrsHos = new SSRS();// 住院医疗费用理算信息: private SSRS ssrsBirth = new SSRS();// 生育医疗费用理算信息:

private SSRS sumSsrsOpt = new SSRS();// 门诊医疗费用理算信息:总计 private SSRS sumSsrsHos = new SSRS();// 住院医疗费用理算信息:总计 private SSRS sumSsrsBirth = new SSRS();// 生育医疗费用理算信息:总计

public boolean batchPrint() throws DocumentException, IOException {

String rgtno = \String rgtno2 = \String rgtno3 = \

ArrayList rgtnoList = new ArrayList(); rgtnoList.add(rgtno); rgtnoList.add(rgtno2); rgtnoList.add(rgtno3);

Document document = new Document(PageSize.A4, 10, 10, 60, 20);// 参数:第一个是页面大小;接下来是左右上下边距; try {

// // 生成名为xxx的文档

PdfWriter.getInstance(document, new FileOutputStream( \

BaseFont bfChinese = BaseFont.createFont(\

\

Color colorGray = new Color(217, 217, 217); Color colorBlack = new Color(0, 0, 0);

Font titleFont = new Font(bfChinese, 21, Font.BOLD, colorBlack); Font infoFont = new Font(bfChinese, 11, Font.NORMAL, colorBlack); Font infoLittleNormal = new Font(bfChinese, 10, Font.NORMAL, colorBlack);

Font infoLittleBold = new Font(bfChinese, 10, Font.BOLD, colorBlack);

document.open();

for (int i = 0; i < rgtnoList.size(); i++) {

String rgtn22o =rgtnoList.get(i).toString(); // 查询数据

selectData(rgtn22o);

// 打开文档,将要写入内容 document.newPage();

// 插入图片:可以是绝对路径,也可以是URL // String path = \

String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();

if (path.indexOf( \

path = path.substring(0, path.indexOf( \}

path = path + \

// String path = \printImage(document, path);

// 打印PDF头部信息

printHead(document, titleFont, infoFont);

// 打印空白表格

printBlank(document, titleFont);

printInfoTable(document, infoFont);

// 门诊医疗费用理算信息

String strOpt = \门诊医疗费用理算信息\门诊医疗费用理算信息,表头

printInfoTable(document, strOpt, infoLittleBold, infoLittleNormal, colorGray, ssrsOpt, sumSsrsOpt);

// 住院医疗费用理算信息

String strHos = \住院医疗费用理算信息\门诊医疗费用理算信息,表头 printInfoTable(document, strHos, infoLittleBold, infoLittleNormal, colorGray, ssrsHos, sumSsrsHos);

// 生育医疗费用理算信息

String strBirth = \生育医疗费用理算信息\门诊医疗费用理算信息,表头 printInfoTable(document, strBirth, infoLittleBold, infoLittleNormal, colorGray, ssrsBirth, sumSsrsBirth);

// 打印PDF结尾部分

printEndInfoTable(document, infoFont, colorGray); }

} catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) {

System.err.println(ioe.getMessage()); }

document.close(); return true; }

public void setAlignment(PdfPCell pdfPCell, int verticalAlign, int horizontalAlign) {

if (verticalAlign == Element.ALIGN_MIDDLE) {

pdfPCell.setVerticalAlignment(Element.ALIGN_MIDDLE);// 垂直居中 } else if (verticalAlign == Element.ALIGN_TOP) {

pdfPCell.setVerticalAlignment(Element.ALIGN_TOP);// 垂直上居中 } else if (verticalAlign == Element.ALIGN_BOTTOM) {

pdfPCell.setVerticalAlignment(Element.ALIGN_BOTTOM);// 垂直下居中 }

if (horizontalAlign == Element.ALIGN_CENTER) {

pdfPCell.setHorizontalAlignment(Element.ALIGN_CENTER);// 水平居中 } else if (horizontalAlign == Element.ALIGN_LEFT) {

pdfPCell.setHorizontalAlignment(Element.ALIGN_LEFT);// 水平左居中 } else if (horizontalAlign == Element.ALIGN_RIGHT) {

pdfPCell.setHorizontalAlignment(Element.ALIGN_RIGHT);// 水平右居中

} }

public void setOptInfoStyle(PdfPCell pdfPCell) {

setDisableBorder(pdfPCell, 0, 0, 4, 8);// 上下边框显示,左右边框不显示。 setCellPadding(pdfPCell, 3, 4, 4, 4);// 设置单元格距离 }

public void setCellPadding(PdfPCell pdfPCell, int top, int bottom, int left, int right) {

pdfPCell.setPaddingTop(top);

pdfPCell.setPaddingBottom(bottom); pdfPCell.setPaddingLeft(left); pdfPCell.setPaddingRight(right); }

public void setDisableBorder(PdfPCell pdfPCell, int top, int bottom, int left, int right) {

// 参数只能为1248,分别代表上下左右 if (top != 0) {

pdfPCell.disableBorderSide(top);// 不显示上边框 }

if (bottom != 0) {

pdfPCell.disableBorderSide(bottom);// 不显示下边框 }

if (left != 0) {

pdfPCell.disableBorderSide(left);// 不显示左边框 }

if (right != 0) {

pdfPCell.disableBorderSide(right);// 不显示右边框 } }

public void printBasicInfo(PdfPTable pdfPTable, Font infoFont, String strCellBI11, String strCellBI12, String strCellBI21, String strCellBI22, String strCellBI31, String strCellBI32, String strCellBI41, String strCellBI42) {

PdfPCell cellBasicInfo11 = new PdfPCell(new Phrase(strCellBI11, infoFont));

cellBasicInfo11.setVerticalAlignment(Element.ALIGN_LEFT);

cellBasicInfo11.setBorder(Rectangle.NO_BORDER); cellBasicInfo11.setPaddingTop(6); pdfPTable.addCell(cellBasicInfo11);

PdfPCell cellBasicInfo12 = new PdfPCell(new Phrase(strCellBI12, infoFont));

cellBasicInfo12.setVerticalAlignment(Element.ALIGN_LEFT); cellBasicInfo12.setBorder(Rectangle.NO_BORDER); cellBasicInfo12.setPaddingTop(6); pdfPTable.addCell(cellBasicInfo12);

PdfPCell cellBasicInfo21 = new PdfPCell(new Phrase(strCellBI21, infoFont));

cellBasicInfo21.setVerticalAlignment(Element.ALIGN_LEFT); cellBasicInfo21.setBorder(Rectangle.NO_BORDER); cellBasicInfo21.setPaddingTop(3); pdfPTable.addCell(cellBasicInfo21);

PdfPCell cellBasicInfo22 = new PdfPCell(new Phrase(strCellBI22, infoFont));

cellBasicInfo22.setVerticalAlignment(Element.ALIGN_LEFT); cellBasicInfo22.setBorder(Rectangle.NO_BORDER); cellBasicInfo22.setPaddingTop(3); pdfPTable.addCell(cellBasicInfo22);

PdfPCell cellBasicInfo31 = new PdfPCell(new Phrase(strCellBI31, infoFont));

cellBasicInfo31.setVerticalAlignment(Element.ALIGN_LEFT); cellBasicInfo31.setBorder(Rectangle.NO_BORDER); cellBasicInfo31.setPaddingTop(3); pdfPTable.addCell(cellBasicInfo31);

PdfPCell cellBasicInfo32 = new PdfPCell(new Phrase(strCellBI32, infoFont));

cellBasicInfo32.setVerticalAlignment(Element.ALIGN_LEFT); cellBasicInfo32.setBorder(Rectangle.NO_BORDER); cellBasicInfo32.setPaddingTop(3); pdfPTable.addCell(cellBasicInfo32);

PdfPCell cellBasicInfo41 = new PdfPCell(new Phrase(strCellBI41, infoFont));

cellBasicInfo41.setVerticalAlignment(Element.ALIGN_LEFT); cellBasicInfo41.setBorder(Rectangle.NO_BORDER); cellBasicInfo41.setPaddingTop(3);

本文来源:https://www.bwwdw.com/article/uxct.html

Top