-1
嗨! 下面是我的代碼導出數據庫到excel文件。現在根據我的要求,我想在頁面頂部添加公司的頁眉圖像.plz傢伙幫助我,並指導我完成task.thanks提前。下面是我的代碼...如何在使用itext從數據庫生成的pdf報告中添加標題圖像
Document document = new Document(PageSize.A2);
PdfWriter.getInstance(document, new FileOutputStream("d:/".concat(datum1).concat(" ").concat("To").concat(" ").concat(datum2).concat(".pdf")));
document.open();
Image logo = Image.getInstance("d:/header.png");
logo.setAlignment(Image.MIDDLE);
logo.scaleAbsoluteHeight(20);
logo.scaleAbsoluteWidth(20);
logo.scalePercent(100);
Chunk chunk = new Chunk(logo, 0, -45);
HeaderFooter header = new HeaderFooter(new Phrase(chunk), false);
header.setAlignment(Element.ALIGN_CENTER);
header.setBorder(Rectangle.NO_BORDER);
document.setHeader(header);
PdfPTable table = new PdfPTable(9);
table.setWidthPercentage(110);
table.addCell("calldate");
table.addCell("src");
table.addCell("dst");
table.addCell("dstchannel");
table.addCell("lastapp");
table.addCell("duration");
table.addCell("disposition");
table.addCell("amaflags");
table.addCell("cdrcost");
String strQuery = "";
ResultSet rs = null;
conexion conexiondb = new conexion();
conexiondb.Conectar();
strQuery = "SELECT * FROM cdrcost where date(calldate) between '" + datum1 + "' and '" + datum2 + "'";
// strQuery = "SELECT * FROM cdrcost where date(calldate) between '2011-09-01' and '2012-01-01'";
rs = conexiondb.Consulta(strQuery);
while (rs.next()) {
table.addCell(rs.getString("calldate"));
table.addCell(rs.getString("src"));
table.addCell(rs.getString("dst"));
table.addCell(rs.getString("dstchannel"));
table.addCell(rs.getString("lastapp"));
table.addCell(rs.getString("duration"));
table.addCell(rs.getString("disposition"));
table.addCell(rs.getString("amaflags"));
table.addCell(rs.getString("cdrcost"));
}
document.add(table);
document.close();
重複的問題,昨天回答:http://stackoverflow.com/questions/13465657/itext-add-content-to-the-bottom-of-an-existing-page –
@BrunoLowagie先生我經歷了鏈接,但沒有解決我的問題PLZ先生幫我 – Adarsh
我會編輯我的答案。 –