Fuentes en las celdas
Last updated
Was this helpful?
Last updated
Was this helpful?
PdfPCell cellMision = new PdfPCell(new Paragraph(pv.getMision(), FontFactory.getFont("arial", 9, Font.NORMAL)));
Definimos el tamaño de fuente mas pequeño para mision.
public void imprimir() {
// com.lowagie.text.Document document = new com.lowagie.text.Document(PageSize.LETTER);
com.lowagie.text.Document document = new com.lowagie.text.Document(PageSize.A4.rotate());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
PdfWriter.getInstance(document, baos);
//METADATA
document.open();
document.add(new Paragraph(" PROGRAMACION DE FLOTA VEHICULAR \n"));
DateFormat formatter = new SimpleDateFormat("dd/MM/yy '-' hh:mm:ss:");
Date currentDate = new Date();
String date = formatter.format(currentDate);
document.add(new Paragraph("Fecha Generado: " + date));
document.add(new Paragraph("\n"));
PdfPTable table = new PdfPTable(7);
// table.setTotalWidth(new float[]{ 20,72, 110, 95, 170, 72 });
table.setTotalWidth(new float[]{20, 100,85,85,225, 72, 110});
table.setLockedWidth(true);
PdfPCell cell = new PdfPCell(new Paragraph("id",
FontFactory.getFont("arial", // fuente
12, // tamaño
Font.BOLD)));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setColspan(1);
table.addCell(cell);
// cell = new PdfPCell(new Paragraph("ID", FontFactory.getFont("arial", 8, Font.BOLD)));
table.addCell("fechapartida");
table.addCell("dia");
table.addCell("unidad");
table.addCell("mision");
table.addCell("conductor");
table.addCell("placa");
for (ProgramacionVehicular pv : programacionVehicular) {
String date1 = formatter.format(pv.getFechahorasalida());
table.addCell(pv.getIdviaje().toString());
table.addCell(date1);
table.addCell(pv.getNombredia());
table.addCell(pv.getUnidad());
PdfPCell cellMision = new PdfPCell(new Paragraph(pv.getMision(), FontFactory.getFont("arial", 9, Font.NORMAL)));
table.addCell(cellMision );
// table.addCell(pv.getMision());
table.addCell(pv.getConductor());
table.addCell(pv.getPlaca());
}
document.add(table);
} catch (Exception ex) {
System.out.println("Error " + ex.getMessage());
}
document.close();
FacesContext context = FacesContext.getCurrentInstance();
Object response = context.getExternalContext().getResponse();
if (response instanceof HttpServletResponse) {
HttpServletResponse hsr = (HttpServletResponse) response;
hsr.setContentType("application/pdf");
hsr.setHeader("Contentdisposition", "attachment;filename=report.pdf");
// hsr.setHeader("Content-disposition", "attachment");
hsr.setContentLength(baos.size());
try {
ServletOutputStream out = hsr.getOutputStream();
baos.writeTo(out);
out.flush();
} catch (IOException ex) {
System.out.println("Error: " + ex.getMessage());
}
context.responseComplete();
}
}