如果循环次数太多不能显示.
如果内容太多也不能显示.
如果内容太多也不能显示.
解决方案 »
- jquery调用ajax验证名字是否存在,在ie9中无效!!!
- 新人spring mvc整合mybatis运行报错,下面贴错误代码,在线等回!
- 关于强制输出
- 提交表单后打开的窗口全屏怎么实现
- 请教--关于Struts防止重复提交问题
- oracle数据库中记录是乱码,怎么把他们还原出来????
- 怎么清除工程的一些琐碎
- The Custom Tag Library Extesion For UltraDev
- 关于JAVA ,JSP, 和Oracle 之间的问题
- 一JSP页面中由一Servlet处理,将取得的JSP页面中的文本框中的文字赋给String a,再插入数据库,如果在文本框中有"'"(单引号,半角)的话,就不
- 文件下载直接打开后,另存问题!!!!
- 数据库链接问题?急呀!!!
但是利用循环产生表的行时如果循环次数多的话输出的pdf文档就没有内容.
如果只是做一二十次循环就没有问题.
还有个问题是这样的:如果一行的文字很多的话也是这样.
而且在这种情况下它会自动换页。
PdfPTable t1 = new PdfPTable(1);
t1.addCell("title");
PdfPTable t2 = new PdfPTable(2);
t2.addCell("a");
t2.addCell("b");
t1.addCell(t2);
document.add(t1);
这时title会在第一页,而t2会在第二页。
private static void parseBody(Element root, Document document) {
NodeList body = root.getElementsByTagName("body");
System.out.print("----------BODY----------");
for (int z = 0; z < body.getLength(); z++) {
Element bodyNode = (Element) body.item(z);
Node bodyChildNode = bodyNode.getFirstChild();
// String bodyString = "";
while (bodyChildNode != null) {
String bodyChildName = bodyChildNode.getNodeName();
if ("BLOCK".equals(bodyChildName)) {
ArrayList blockValList = new ArrayList();
Node blockChildNode = bodyChildNode.getFirstChild();
//NodeList blockChildNode = bodyNode.getChildNodes();
String blockString = "";
while (blockChildNode != null) {
String blockChildName = blockChildNode.getNodeName();
System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"+blockChildName);
if("#text".equals(blockChildName)){
System.out.println(blockChildNode.getNodeValue());
blockString += blockChildNode.getNodeValue();
}
else if ("BR".equals(blockChildName)) {
blockString += "\n";
} else if ("VAR".equals(blockChildName)) {
if (blockChildNode.getFirstChild() != null) {
System.out.println(blockChildNode.getFirstChild().getNodeValue());
blockString += blockChildNode.getFirstChild().getNodeValue();
}
}
else if ("I".equals(blockChildName)){
if(blockChildNode.getFirstChild() != null){
System.out.println(blockChildNode.getFirstChild().getNodeValue());
blockString += blockChildNode.getFirstChild().getNodeName();
}
}
blockChildNode = blockChildNode.getNextSibling();
}
blockValList.add(blockString);
// iText画PDF
try {
BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
Font fontText = new Font(bfChinese, 8, Font.NORMAL);
Table iTextTable = new Table(blockValList.size());
iTextTable
.setDefaultVerticalAlignment(Element.ATTRIBUTE_NODE);
iTextTable.setBorder(Rectangle.NO_BORDER);
iTextTable.setWidth(100);
iTextTable.setAutoFillEmptyCells(false);
iTextTable.setDefaultColspan(1);
Iterator it = blockValList.iterator();
while (it.hasNext()) {
iTextTable.addCell(new Phrase ((String) it.next(),fontText)); }
document.add(iTextTable);
} catch (Exception e) {
e.printStackTrace();
}
}
else if ("TABLE".equals(bodyChildName)) {
Node tableChildNode = bodyChildNode.getFirstChild();
ArrayList tableValList = new ArrayList();
while(tableChildNode != null){
String tableChildName = tableChildNode.getNodeName();
System.out.println("########################################"+tableChildName);
if("CELL".equals(tableChildName)){
Node cellChildNode = tableChildNode.getFirstChild();
String cellString = "";
while(cellChildNode != null){
String cellChildName = cellChildNode.getNodeName();
if ("BR".equals(cellChildName)) {
cellString += "\n";
}
else if("B".equals(cellChildName)) {
Node bChildNode = cellChildNode.getFirstChild();
while(bChildNode != null){
String bChildNane = bChildNode.getNodeName();
if("VAR".equals(bChildNane)){
if(bChildNode.getFirstChild() != null){
System.out.println(bChildNode.getFirstChild().getNodeValue());
cellString += bChildNode.getFirstChild().getNodeValue();
}
}
bChildNode = bChildNode.getNextSibling();
}
}
else if ("VAR".equals(cellChildName)) {
if (cellChildNode.getFirstChild() != null) {
System.out.println(cellChildNode.getFirstChild().getNodeValue());
cellString += cellChildNode.getFirstChild().getNodeValue();
}
}
cellChildNode = cellChildNode.getNextSibling();
}
tableValList.add(cellString); }
tableChildNode = tableChildNode.getNextSibling();
}
//iText画PDF
try{
BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
if (tableValList.size() > 0 ){
Table iTextTable = new Table(tableValList.size());
iTextTable.setDefaultVerticalAlignment(Element.ENTITY_NODE);
iTextTable.setBorder(Rectangle.NO_BORDER);
iTextTable.setWidth(100);
iTextTable.setAutoFillEmptyCells(false);
iTextTable.setDefaultColspan(1);
Iterator it = tableValList.iterator();
//for (int m = 0 ; m < cellValList.size() ; m ++)
while(it.hasNext())
{
//表头信息
Cell cell = new Cell(new Phrase((String)it.next(), new Font(bfChinese, 10, Font.BOLD, new Color(0, 0, 255))));
cell.setHorizontalAlignment(Element.ENTITY_NODE);
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
iTextTable.addCell(cell);
}
document.add(iTextTable);
}
}catch(Exception e){
e.printStackTrace();
}
}
bodyChildNode = bodyChildNode.getNextSibling();
}
}
}