Estou implementando uma impressão no meu programa e estou querendo imprimir uma jTable que meu programa possui com todos os dados.
Usando o Itext eu conseguir fazer uma coisa bacana de impressão, mais a PdfPTable sai com fonte muito grande. Não estou conseguindo mudar…
Código:
public void SistemaImpressao(){
Document document = new Document(PageSize.A4);
try {
PdfWriter.getInstance(document, new FileOutputStream("C:/Users/Kelvin/Desktop//PDF_LinhaCodigo.pdf"));
document.open();
//Image figura = Image.getInstance("C:/Arquivos de Programas/Sip\\Modelo pagina.bmp");
//figura.scaleAbsolute(280, 84);
//document.add(figura);
document.add(new Paragraph("Teste",FontFactory.getFont(FontFactory.COURIER, 5)));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
int linhas = jTable1.getRowCount()-1;
//CRIANDO UMA FONTE
Font f = new Font(FontFamily.COURIER, 20, Font.BOLD);
//----------------------
PdfPTable tabela = new PdfPTable(new float[]{0.3f,1.5f,0.2f,0.2f,0.2f,0.3f});
//tabela.setWidthPercentage(10.0f);
tabela.setHorizontalAlignment(Element.ALIGN_LEFT);
PdfPCell cabeca = new PdfPCell(new Paragraph("Testando Sistema de Impressão"));
cabeca.setColspan(6);
tabela.addCell(cabeca);
tabela.addCell("Referência");
tabela.addCell("Descrição");
tabela.addCell("À Vista");
tabela.addCell("30 Dias");
tabela.addCell("30/60");
tabela.addCell("30/60/90");
for(int i=0;i<=linhas;i++){
String codigo = String.valueOf(jTable1.getValueAt(i, 0));
String descricao = String.valueOf(jTable1.getValueAt(i, 1));
String avista = String.valueOf(jTable1.getValueAt(i, 2));
String trinta = String.valueOf(jTable1.getValueAt(i, 3));
String trintasessenta = String.valueOf(jTable1.getValueAt(i, 4));
String trintasessentanoventa = String.valueOf(jTable1.getValueAt(i, 5));
tabela.addCell(codigo);
tabela.addCell(descricao);
tabela.addCell(avista);
tabela.addCell(trinta);
tabela.addCell(trintasessenta);
tabela.addCell(trintasessentanoventa);
}
document.add(tabela);
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
catch(IOException ioe) {
System.err.println(ioe.getMessage());
}
document.close();
}
A tabela esta sendo impressa com texto com +/- o tamanho 30. Muito grande, e a folha A4 não está sendo utilizada ate o final direito, isso não sei se é coisa do Adobe Pdf…
O grande problema é esta fonte gigantesca que esta imprimindo…
Possivelmente deve dar para modificar a fonte facilmente, mais eu não estou acertando onde modificar…
Obrigado a quem dar uma mãozinha