package com.bonus.doc.docutil; import java.awt.Color; import java.io.File; import java.io.FileOutputStream; import java.util.List; import org.apache.log4j.Logger; import com.lowagie.text.BadElementException; import com.lowagie.text.Cell; import com.lowagie.text.Chunk; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Font; import com.lowagie.text.Image; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.Table; import com.lowagie.text.rtf.RtfWriter2; public class DocHelper { private static final Logger logger = Logger.getLogger(DocHelper.class); public static Document createDocument(String filePath) { File file = new File(filePath); Document document = new Document(PageSize.A4, 90, 90, 70, 70); try { RtfWriter2.getInstance(document, new FileOutputStream(file)); document.open(); } catch (Exception e) { logger.error("create doc fail,reason:",e); return null; } return document; } public static void insertImg(Document document, String imgUrl, int alignment, float widthScale, float heightScale) throws Exception { // 添加图片 Image img = Image.getInstance(imgUrl); if (img == null) return; img.setAlignment(alignment); img.scalePercent(widthScale, heightScale); document.add(img); } public static void insertChunks(Document document, int alignment, Chunk[] chunk) { Paragraph p = new Paragraph(); p.setAlignment(alignment); for(int i=0;i beans,String tableHead,String tableBody) throws BadElementException { Table table = new Table(beans.size() + 1); table.setBorderWidthRight(25); table.setWidth(99); table.setBorderWidth(1); table.setBorderColor(Color.BLACK); table.setBackgroundColor(Color.RED); table.setAutoFillEmptyCells(true); table.setPadding(0); table.setSpacing(0); table.addCell(createHeaderCell(tableHead)); for (int i = 0; i < beans.size(); i++) { table.addCell(createHeaderCell(beans.get(i).getUnit())); } table.addCell(tableBody); for (int i = 0; i < beans.size(); i++) { table.addCell(new Paragraph(beans.get(i).getProject_num())); } return table; } public static Table getTableDoc(List beans,String tableHead,String tableBody) throws BadElementException { Table table = new Table(beans.size() + 1); table.setBorderWidthRight(25); table.setWidth(99); table.setBorderWidth(1); table.setBorderColor(Color.BLACK); table.setBackgroundColor(Color.RED); table.setAutoFillEmptyCells(true); table.setPadding(0); table.setSpacing(0); table.addCell(createHeaderCell(tableHead)); for (int i = 0; i < beans.size(); i++) { table.addCell(createHeaderCell(beans.get(i).getUnit())); } table.addCell(tableBody); for (int i = 0; i < beans.size(); i++) { table.addCell(new Paragraph(beans.get(i).getAvg_time())); } return table; } public static String imagePathDoc(List beans,String imagehead,String describe){ if(beans==null){ return ""; } String imagehea1="\""+imagehead+"\""; String describe1="\""+describe+"\""; String untiData="\""+beans.get(0).getUnit()+"\""; String numData=beans.get(0).getProject_num(); for(int i=1;i beans,String imagehead,String describe){ if(beans==null){ return ""; } //String imagehea1="\""+imagehead+"\""; //String describe1="\""+describe+"\""; //String untiData="\""+beans.get(0).getUnit()+"\""; //String numData=beans.get(0).getProject_num(); //for(int i=1;i beans,String imagehead,String describe){ if(beans==null){ return ""; } String imagehea1="\""+imagehead+"\""; String describe1="\""+describe+"\""; String untiData="\""+beans.get(0).getUnit()+"\""; String numData=beans.get(0).getProject_num(); for(int i=1;i