Java 如何对齐打印在PDF文档上的表格中的列?
这是我生成pdf格式记录的代码。我需要逐个显示记录,但这段代码无法控制pdfptable的列宽。如何设置 我使用Java 如何对齐打印在PDF文档上的表格中的列?,java,pdf,pdf-generation,itext,Java,Pdf,Pdf Generation,Itext,这是我生成pdf格式记录的代码。我需要逐个显示记录,但这段代码无法控制pdfptable的列宽。如何设置 我使用Itext生成PDF pdfDocument=new Document(); PdfWriter.getInstance(pdfDocument, new FileOutputStream(sOutputDirectory + "/" + sOutputFileName, false)); pdfDocument.open(); if(valuelist!=null &
Itext
生成PDF
pdfDocument=new Document();
PdfWriter.getInstance(pdfDocument, new FileOutputStream(sOutputDirectory + "/" + sOutputFileName, false));
pdfDocument.open();
if(valuelist!=null && !valuelist.isEmpty() && valuelist!=null && !valuelist.isEmpty() && pdfDocument.isOpen() ){
System.out.println("CP 1");
PdfPTable pdfPTable=new PdfPTable(valuelist.size());
pdfPTable.setWidthPercentage(100);
float[] columnWidths = new float[] {15f, 15f, 15f, 35f,15f,15f};
pdfPTable.setWidths(columnWidths);
PdfPCell pdfPCell;
for(int i=0;i<valuelist.size();i++){
System.out.println("CP :"+i);
Bean bean = (Bean) valuelist.get(i);
pdfPCell=new PdfPCell(new Phrase(bean.getsName()));
pdfPCell.setBorder(Rectangle.NO_BORDER);
pdfPTable.addCell(pdfPCell);
pdfPCell=new PdfPCell(new Phrase(bean.getsNumber()));
pdfPCell.setBorder(Rectangle.NO_BORDER);
pdfPTable.addCell(pdfPCell);
pdfPCell=new PdfPCell(new Phrase(bean.getsTransactionDate()));
pdfPCell.setBorder(Rectangle.NO_BORDER);
pdfPTable.addCell(pdfPCell);
pdfPCell=new PdfPCell(new Phrase(bean.getsItemNo()));
pdfPCell.setBorder(Rectangle.NO_BORDER);
pdfPTable.addCell(pdfPCell);
pdfPCell=new PdfPCell(new Phrase(bean.getsPoints()));
pdfPCell.setBorder(Rectangle.NO_BORDER);
pdfPTable.addCell(pdfPCell);
pdfPCell=new PdfPCell(new Phrase(bean.getsQuantity()));
pdfPCell.setBorder(Rectangle.NO_BORDER);
pdfPTable.addCell(pdfPCell);
}
pdfDocument.add(pdfPTable);
}
pdfDocument.close();
pdfDocument=新文档();
getInstance(pdfDocument,新文件输出流(sOutputDirectory+“/”+sOutputFileName,false));
pdfDocument.open();
if(valuelist!=null&&!valuelist.isEmpty()&&valuelist!=null&&!valuelist.isEmpty()&&pdfDocument.isOpen()){
系统输出打印项次(“CP 1”);
PdfPTable PdfPTable=新的PdfPTable(valuelist.size());
pdfPTable.setWidthPercentage(100);
float[]columnWidths=新的float[]{15f,15f,15f,35f,15f,15f};
pdfPTable.setWidths(列宽);
PdfPCell-PdfPCell;
对于(int i=0;i)您希望结果是什么?代码的结果以何种方式不满足此要求?很抱歉延迟回复mkl。实际上,我需要每行显示六列。问题是我已将数组列表大小设置为PDFP表值。现在它可以正常工作