List of usage examples for com.lowagie.text.pdf PdfPTable setFooterRows
public void setFooterRows(int footerRows)
From source file:classroom.filmfestival_b.Movies14.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/* w ww .j a v a 2 s .c o m*/ Document document = new Document(); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter.getInstance(document, os); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); PdfPTable table = new PdfPTable(2); table.setWidths(new float[] { 1, 5 }); File f; Paragraph p; Chunk c; PdfPCell cell = new PdfPCell(); Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); p = new Paragraph("FILMFESTIVAL", bold); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(); cell.setFixedHeight(20); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(new Movies14().new PageCell()); table.addCell(cell); table.setHeaderRows(2); table.setFooterRows(1); for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { cell = new PdfPCell(Image.getInstance(f.getPath()), true); cell.setPadding(2); } else { cell = new PdfPCell(); } table.addCell(cell); p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); cell = new PdfPCell(); cell.setUseAscender(true); cell.setUseDescender(true); cell.addElement(p); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } cell.addElement(list); table.addCell(cell); } document.add(table); // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_b.Movies15.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1// www . j a v a 2 s .c om Document document = new Document(); try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); // step 3 document.open(); // step 4 Session session = (Session) MySessionFactory.currentSession(); Query q = session.createQuery("from FilmTitle order by title"); java.util.List<FilmTitle> results = q.list(); PdfPTable table = new PdfPTable(2); table.setComplete(false); table.setWidths(new float[] { 1, 5 }); File f; Paragraph p; Chunk c; PdfPCell cell = new PdfPCell(); Font bold = new Font(Font.HELVETICA, 12, Font.BOLD); Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC); p = new Paragraph("FILMFESTIVAL", bold); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); table.addCell(cell); cell = new PdfPCell(); cell.setFixedHeight(20); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(new Movies14().new PageCell()); table.addCell(cell); table.setHeaderRows(2); table.setFooterRows(1); int counter = 10; for (FilmTitle movie : results) { f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg"); if (f.exists()) { cell = new PdfPCell(Image.getInstance(f.getPath()), true); cell.setPadding(2); } else { cell = new PdfPCell(); } table.addCell(cell); p = new Paragraph(20); c = new Chunk(movie.getTitle(), bold); c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId()); p.add(c); c = new Chunk(" (" + movie.getYear() + ") ", italic); p.add(c); c = new Chunk("IMDB"); c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb()); p.add(c); cell = new PdfPCell(); cell.setUseAscender(true); cell.setUseDescender(true); cell.addElement(p); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } cell.addElement(list); table.addCell(cell); if (counter % 10 == 0) { document.add(table); } System.out.println(writer.getPageNumber()); counter++; } table.setComplete(true); document.add(table); // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java
License:Apache License
/** * Creates the pdf footer.//ww w .j a v a 2 s . c om * * @param pdfPTable * the pdf P table * @param font * the font * @throws DocumentException * the document exception * @throws IOException * Signals that an I/O exception has occurred. */ public void createPdfFooter(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException { final float width = pdfPTable.getWidthPercentage(); final int headerWidth = (int) width; font = getFont(); final PdfPCell footerCell = new PdfPCell(new Phrase(getFooter(), font)); footerCell.setHorizontalAlignment(Element.ALIGN_CENTER); footerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); footerCell.setColspan(headerWidth); footerCell.setBorder(0); footerCell.setUseDescender(true); pdfPTable.addCell(footerCell); pdfPTable.setFooterRows(1); }
From source file:com.prime.location.billing.InvoicedBillingManager.java
/** * Print invoice/*from ww w .ja va 2 s. c o m*/ */ public void printInvoice() { try { //catch better your exceptions, this is just an example FacesContext context = FacesContext.getCurrentInstance(); Document pdf = new Document(PageSize.A4, 5f, 5f, 75f, 45f); String fileName = "PDFFile"; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(pdf, baos); TableHeader event = new TableHeader(); event.setHeader("Header Here"); writer.setPageEvent(event); if (!pdf.isOpen()) { pdf.open(); } PdfPCell cell; PdfPTable header = new PdfPTable(new float[] { 1, 2, 1 }); cell = new PdfPCell(new Paragraph("INVOICE", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC, Color.BLACK))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); header.setTotalWidth(527); header.setLockedWidth(true); cell = new PdfPCell(new Phrase("Agency: " + selectedAgency.getDescription())); cell.setColspan(2); cell.setBorder(Rectangle.NO_BORDER); header.addCell(cell); cell = new PdfPCell(new Phrase("Invoice#: " + selectedInvoice.getId())); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); cell = new PdfPCell( new Phrase("Date: " + DateUtility.dateTimeFormat(selectedInvoice.getInvoiceDate()))); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); header.addCell(cell); pdf.add(header); PdfPTable table = new PdfPTable(new float[] { 1, 3, 2, 1 }); table.setSpacingBefore(15f); table.setTotalWidth(527); table.setLockedWidth(true); //table.setWidths(new int[]{3, 1, 1}); table.getDefaultCell().setBackgroundColor(Color.LIGHT_GRAY); table.addCell("Date"); table.addCell("Name"); table.addCell("Service"); table.addCell("Rate"); table.getDefaultCell().setBackgroundColor(null); cell = new PdfPCell(new Phrase("Total(US$): ")); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setColspan(3); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(selectedInvoice.getAmount()))); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBackgroundColor(Color.LIGHT_GRAY); table.addCell(cell); // There are three special rows table.setHeaderRows(2); // One of them is a footer table.setFooterRows(1); Font f = FontFactory.getFont(FontFactory.HELVETICA, 10); //add remaining for (AgencyBilling billing : selectedInvoice.getBillings()) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setIndent(2); table.getDefaultCell().setFixedHeight(20); table.addCell(new Phrase(DateUtility.dateFormat(billing.getBillingDate()), f)); table.addCell(new Phrase(billing.getPerson().getName(), f)); table.addCell(new Phrase(billing.getTariff().getTariffType().getDescription(), f)); cell = new PdfPCell(new Phrase(new DecimalFormat("###,###.###").format(billing.getRate()), f)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); } pdf.add(table); writer.getAcroForm().setNeedAppearances(true); //document.add(new Phrase(TEXT)); //Keep modifying your pdf file (add pages and more) pdf.close(); writePDFToResponse(context.getExternalContext(), baos, fileName); context.responseComplete(); } catch (Exception e) { //e.printStackTrace(); } }