/*** 新建报告(报告名字。图片。新闻id)
*
*@throwsJSONException*/@OverridepublicString addReport(String[] img, String[] newsId, String reportName, String loginId, String path,
String imgPath) {
Long name=System.currentTimeMillis();
String filePath= path + File.separator + name + ".doc";
File file= newFile(filePath);
Report report= newReport();
report.setLoginId(loginId);
report.setReportName(reportName);
report.setDownUrl(filePath);
fileDao.addReport(report);
System.out.println("插入报告成功" +report.getReportNo());
Document document= newDocument(PageSize.A4);try{
RtfWriter2.getInstance(document,newFileOutputStream(file));
}catch(FileNotFoundException e2) {//TODO Auto-generated catch block
e2.printStackTrace();
}
document.open();
BaseFont bfChinese= null;try{
bfChinese=BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
}catch (DocumentException |IOException e1) {
e1.printStackTrace();
}
Font titleFont= new Font(bfChinese, 22, Font.BOLD);
Font contextFont= new Font(bfChinese, 10, Font.NORMAL);
Paragraph title= new Paragraph("统计报告", titleFont);
title.setAlignment(Element.ALIGN_CENTER);//红色的线
RtfShapePosition position;
position= new RtfShapePosition(150, 0, 10400, 170);
position.setXRelativePos(RtfShapePosition.POSITION_X_RELATIVE_MARGIN);
position.setYRelativePos(RtfShapePosition.POSITION_Y_RELATIVE_PARAGRAPH);
RtfShape shape= newRtfShape(RtfShape.SHAPE_RECTANGLE, position);
RtfShapeProperty property= newRtfShapeProperty(RtfShapeProperty.PROPERTY_LINE_COLOR, Color.RED);
shape.setProperty(property);
Paragraph p1= newParagraph(shape);try{//logo
Image imglogo = Image.getInstance(imgPath + File.separator + "dfgx.jpg");
imglogo.setAlignment(Image.LEFT);//设置图片显示位置
imglogo.scaleAbsolute(80, 50);//直接设定显示尺寸
document.add(imglogo);
document.add(title);
document.add(p1);
}catch(Exception e) {
e.printStackTrace();
}
Table table= null;try{
table= new Table(4);int width[] = { 40, 30, 15, 15 };//设置每列宽度比例
table.setWidths(width);
}catch(Exception e1) {
e1.printStackTrace();
}
table.setBorderWidth(1);
table.setBorderColor(Color.BLACK);
table.setPadding(0);
table.setSpacing(0);try{
table.addCell("标题");
table.addCell("链接");
table.addCell("渠道");
table.addCell("时间");
}catch(BadElementException e1) {
e1.printStackTrace();
}
List list =estoWeb.SelectId(newsId);
String time= "";
String titleinfo= "";
String url= "";
String channel= "";try{for(Object string : list) {
JSONObject json= null;
json= newJSONObject(String.valueOf(string));
channel= (String) json.get("webCell");
titleinfo= (String) json.get("titleCell");
url= (String) json.get("linkCell");
time= (String) json.get("dateCell");
table.addCell(newParagraph(titleinfo));
table.addCell(newParagraph(url));
table.addCell(newParagraph(channel));
table.addCell(newParagraph(time));
}
}catch(Exception e) {
e.printStackTrace();
}try{
document.add(table);
}catch(DocumentException e1) {
e1.printStackTrace();
}for(String string : img) {
Map map =fileDao.findReportPath(string);
System.out.println(map.get("PIC_PATH"));
Image img1= null;try{
img1= Image.getInstance(imgPath + File.separator + String.valueOf(map.get("PIC_PATH")));
}catch(BadElementException e) {
e.printStackTrace();
}catch(MalformedURLException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}
img1.setAbsolutePosition(0, 0);
img1.setAlignment(Image.ALIGN_CENTER);//设置图片显示位置
img1.scaleAbsolute(360, 180);//直接设定显示尺寸
try{
document.add(img1);
}catch(DocumentException e) {
e.printStackTrace();
}
}
document.close();return "ok";
}