List of usage examples for com.itextpdf.text.pdf PdfPTable setWidths
public void setWidths(final int relativeWidths[]) throws DocumentException
From source file:Funciones.PedidoPDF.java
public PedidoPDF(String id, java.awt.Image imagen, String directorio) throws FileNotFoundException, DocumentException, IOException { this.idpedido = id; this.directorio = directorio; this.archivo = new File(directorio); Document documento = new Document(PageSize.A6); FileOutputStream ficheroPdf = new FileOutputStream(archivo); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); documento.setMargins(0, 0, 1, 0);/*from ww w . jav a 2 s . c om*/ documento.open(); int width = imagen.getWidth(null); int height = imagen.getHeight(null); int type = BufferedImage.TYPE_3BYTE_BGR; BufferedImage bi = new BufferedImage(width, height, type); Graphics2D g2d = bi.createGraphics(); g2d.drawImage(imagen, 0, 0, null); g2d.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bi, "png", baos); baos.flush(); byte[] imageInByte = baos.toByteArray(); baos.close(); Image image = Image.getInstance(imageInByte); PdfPTable tablaimagen = new PdfPTable(1); tablaimagen.setWidths(new int[] { 350 }); tablaimagen.addCell(image); documento.add(tablaimagen); documento.close(); ejecutarPDF(); }
From source file:gestionsessions.FenSession.java
private void jTableGestionSessionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableGestionSessionMouseClicked Document document = new Document(); String req;//from w w w .j a va2 s . co m int nbLignes = 0; // Creation d'une PdfPTable avec 5 colonnes final PdfPTable table = new PdfPTable(5); try { PdfWriter.getInstance(document, new FileOutputStream(System.getProperty("user.dir") + "//listeEmargementSession.pdf")); document.open(); //en tte du pdf Image logo = Image.getInstance("logo.png"); logo.scaleAbsolute(120f, 67f); document.add(logo); //on indique la marge document.add(new Phrase("\n\n\nMarge dgage par la session: " + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 9).toString() + "")); document.add(new Phrase("\n\nListe d'margement de la session ")); document.add(new Phrase( jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 0).toString())); document.add(new Phrase( " / " + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 1).toString())); document.add(new Phrase( " / " + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 2).toString())); document.add(new Phrase(" / " + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 3).toString() + ":")); // Ajout d'un espace entre la PdfPTable et l'lment prcdent. table.setSpacingBefore(15f); //requte pour les personnes inscrites stmt1 = GestionBdd.connexionBdd(GestionBdd.TYPE_MYSQL, "formarmor", "localhost", "root", ""); req = "Select c.* from client c, inscription i where c.id = i.client_id and i.session_formation_id = " + jTableGestionSession.getValueAt(jTableGestionSession.getSelectedRow(), 0).toString(); ResultSet rs1 = GestionBdd.envoiRequeteLMD(stmt1, req); // Ajout d'une entte pour PdfPTable table.addCell("Matricule"); table.addCell("Nom"); table.addCell("Rue"); table.addCell("Code Postal"); table.addCell("Ville"); // Ajout d'un espace entre la PdfPTable et l'lment prcdent. table.setSpacingBefore(15f); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); //change taille colonnes table.setWidths(new int[] { 5, 10, 14, 6, 8 }); while (rs1.next()) { // Ajout d'objets String la PdfPTable table.addCell(rs1.getString(1)); table.addCell(rs1.getString(3)); table.addCell(rs1.getString(5)); table.addCell(rs1.getString(6)); table.addCell(rs1.getString(7)); // Ajout d'un espace entre la PdfPTable et l'lment prcdent. table.setSpacingBefore(15f); nbLignes++; } //cas ou il n'y a personne d'inscrit if (nbLignes == 0) { JOptionPane.showMessageDialog(null, "Il n'y a personne d'inscrits"); document.add(new Phrase("\n\nIl n'y a personne d'inscrits")); } else { document.add(table); //ouvre le fichier listeEmargementSession.pdf avec le logiciel de lecture pdf par dfaut Runtime r = Runtime.getRuntime(); r.exec(new String[] { "cmd.exe", "/C", System.getProperty("user.dir") + "//listeEmargementSession.pdf" }); } document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (SQLException ex) { Logger.getLogger(FenSession.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FenSession.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.ExpiredLicensesReport.java
private static PdfPTable getDocumentTable(Person specialist) throws DocumentException { PdfPTable table = new PdfPTable(1); // format the tables int headerwidths[] = { 100 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);/* w w w .j a v a 2s.c o m*/ table.getDefaultCell().setLeading(0, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorderWidthLeft(0); table.getDefaultCell().setBorderWidthRight(0); table.getDefaultCell().setBorderWidthTop(0); table.getDefaultCell().setPaddingBottom(4); table.getDefaultCell().setBorderWidthBottom(1.0f); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(getHeaderTable(specialist)); table.setHeaderRows(1); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.ExpiredLicensesReport.java
private static PdfPTable getDetailTable() throws DocumentException { PdfPTable table = new PdfPTable(5); // format the table int headerwidths[] = { 41, 17, 8, 24, 10 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);//from w w w. j a v a2 s .c o m table.getDefaultCell().setLeading(fixedLeading, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_BOTTOM); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.ExpiredLicensesReport.java
private static PdfPTable getFacilityDetailsTable() throws DocumentException { PdfPTable table = new PdfPTable(3); // format the table int headerwidths[] = { 33, 33, 33 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);/*from ww w . j a v a 2s.co m*/ table.getDefaultCell().setLeading(fixedLeading, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_BOTTOM); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java
private static PdfPTable getDocumentTable(Person specialist, Date endDate) throws DocumentException { PdfPTable table = new PdfPTable(1); // format the tables int headerwidths[] = { 100 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);//from w w w .ja v a 2 s . c om table.getDefaultCell().setLeading(0, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorderWidthLeft(0); table.getDefaultCell().setBorderWidthRight(0); table.getDefaultCell().setBorderWidthTop(0); table.getDefaultCell().setPaddingBottom(4); table.getDefaultCell().setBorderWidthBottom(1.0f); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(getHeaderTable(specialist, endDate)); table.setHeaderRows(1); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java
private static PdfPTable getHeaderTable(Person specialist, Date endDate) throws DocumentException { Date today = new Date(); PdfPTable table = new PdfPTable(2); // format the table int headerwidths[] = { 80, 20 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);/* w w w. j a v a 2 s.co m*/ table.getDefaultCell().setLeading(largeFixedLeading, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setPaddingLeft(4); table.getDefaultCell().setPaddingRight(2); if (endDate == null) { table.getDefaultCell().setPaddingBottom(17); } table.getDefaultCell().setBorderWidthLeft(0); table.getDefaultCell().setBorderWidthRight(0); table.getDefaultCell().setBorderWidthTop(1.0f); table.getDefaultCell().setBorderWidthBottom(0); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); // Add Page header information sb = new StringBuilder(); sb.append("Facility Licenses for "); if (StringUtils.isNotBlank(specialist.getFirstAndLastName())) { sb.append(specialist.getFirstAndLastName()); } table.addCell(new Phrase(sb.toString(), largefontB)); // Add report date table.getDefaultCell().setPaddingLeft(2); table.getDefaultCell().setPaddingRight(4); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT); table.addCell(new Phrase(df.format(today), mediumfontB)); if (endDate != null) { // Add expiration end date date table.getDefaultCell().setPaddingLeft(8); table.getDefaultCell().setPaddingRight(4); table.getDefaultCell().setPaddingBottom(0); table.getDefaultCell().setBorderWidthTop(0); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); table.getDefaultCell().setColspan(2); table.addCell(new Phrase("With Licenses Expiring " + df.format(endDate), mediumfontB)); } return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java
private static PdfPTable getFacilityDetailTable() throws DocumentException { PdfPTable table = new PdfPTable(4); // format the table int headerwidths[] = { 11, 18, 29, 42 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);/*from w ww . j a va 2 s .c o m*/ table.getDefaultCell().setLeading(fixedLeading, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java
private static PdfPTable getLicenseDetailTable() throws DocumentException { PdfPTable table = new PdfPTable(7); // format the table int headerwidths[] = { 11, 18, 15, 8, 17, 12, 19 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);// w w w .j a v a 2 s . c om table.getDefaultCell().setLeading(fixedLeading, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseSummaryReport.java
private static PdfPTable getDocumentTable(Person specialist, Date endDate, FacilityLicenseSummarySortBy sortBy) throws DocumentException { PdfPTable table = new PdfPTable(1); // format the tables int headerwidths[] = { 100 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);//w w w .j av a 2 s . co m table.getDefaultCell().setLeading(0, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorderWidthLeft(0); table.getDefaultCell().setBorderWidthRight(0); table.getDefaultCell().setBorderWidthTop(0); table.getDefaultCell().setPaddingBottom(4); table.getDefaultCell().setBorderWidthBottom(1.0f); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(getHeaderTable(specialist, endDate, sortBy)); table.setHeaderRows(1); return table; }