List of usage examples for com.itextpdf.text FontFactory getFont
public static Font getFont(final String fontname, final float size, final int style)
Font
-object. From source file:PDF.Reportes.java
public static PdfPTable statusfichas(String usuario, String contra) throws DocumentException { // IngresoAbd bd = new IngresoAbd(usuario, contra); List<Beans.Reportes> reportes; reportes = ReportesDAO.statusFichas(usuario, contra); // reportes = bd.statusFichas(); PdfPTable table = new PdfPTable(4); if (reportes.isEmpty()) { PdfPCell cell;/*from w w w.j a va2 s. c o m*/ cell = new PdfPCell( new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte.")); cell.setColspan(5); table.addCell(cell); } else if (reportes.get(0).getCodError() != 0) { PdfPCell cell; if (reportes.get(0).getCodError() == -1) { cell = new PdfPCell(new Phrase(Constants.ERROR1)); cell.setColspan(5); table.addCell(cell); } if (reportes.get(0).getCodError() == -2) { cell = new PdfPCell(new Phrase(Constants.ERROR3)); cell.setColspan(5); table.addCell(cell); } if (reportes.get(0).getCodError() == -3) { cell = new PdfPCell(new Phrase(Constants.ERROR2)); cell.setColspan(5); table.addCell(cell); } // cell = new PdfPCell(new Phrase(reportes.get(0).getMsjError())); } else { BaseColor color = new BaseColor(69, 161, 240); BaseColor colorB = new BaseColor(255, 255, 255); PdfPCell cell; cell = new PdfPCell(new Phrase("Carrera", FontFactory.getFont("arial", 12, colorB))); cell.setBorderColor(colorB); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); table.addCell(cell); cell = new PdfPCell(new Phrase("Prefichas", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); cell = new PdfPCell(new Phrase("Prefichas pagadas", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); cell = new PdfPCell(new Phrase("Pre proceso concluido", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); int totalP = 0; int totalPp = 0; int totalPr = 0; for (Beans.Reportes reporte : reportes) { cell = new PdfPCell(new Phrase(reporte.getNombre(), FontFactory.getFont("arial", 8))); cell.setBorderColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(reporte.getPreficha())); cell.setBorderColor(color); totalP = Integer.parseInt(reporte.getPreficha()) + totalP; cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(reporte.getPrefpagadas())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderColor(color); totalPp = Integer.parseInt(reporte.getPrefpagadas()) + totalPp; table.addCell(cell); cell = new PdfPCell(new Phrase(reporte.getPreproc())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderColor(color); totalPr = Integer.parseInt(reporte.getPreproc()) + totalPr; table.addCell(cell); } cell = new PdfPCell(new Phrase("Totales", FontFactory.getFont("arial", 12, colorB))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(color); cell.setBorderColor(colorB); table.addCell(cell); cell = new PdfPCell(new Phrase(Integer.toString(totalP), FontFactory.getFont("arial", 12))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderColor(color); table.addCell(cell); cell = new PdfPCell(new Phrase(Integer.toString(totalPp), FontFactory.getFont("arial", 12))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderColor(color); table.addCell(cell); cell = new PdfPCell(new Phrase(Integer.toString(totalPr), FontFactory.getFont("arial", 12))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderColor(color); table.addCell(cell); table.setWidthPercentage(110); table.setWidths(new int[] { 50, 50, 100, 100 }); } return table; }
From source file:PdfCreation.PdfTableWriter.java
public Section addTable(JTable table) { DefaultTableModel model = (DefaultTableModel) table.getModel(); Section ourTableSection = new Chapter(0) .addSection(this.newParagraph("Information Table", true, false, false)); ourTableSection.add(new Paragraph(" ")); PdfPTable ourTable = new PdfPTable(model.getColumnCount() + 1); int count = 1; ourTable.addCell(new Phrase(" ", FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD))); for (int i = 0; i < model.getColumnCount(); i++) { Phrase phrase = new Phrase(model.getColumnName(i).toString(), FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD)); ourTable.addCell(new PdfPCell(phrase)); }//from w w w .j av a 2 s . c o m for (int i = 0; i < model.getRowCount(); i++) { ourTable.addCell(new Phrase("" + count++, FontFactory.getFont(FontFactory.HELVETICA, 8))); for (int j = 0; j < model.getColumnCount(); j++) { Phrase phrase = new Phrase(model.getValueAt(i, j).toString(), FontFactory.getFont(FontFactory.HELVETICA, 8)); ourTable.addCell(phrase); } } ourTableSection.add(ourTable); return ourTableSection; }
From source file:presentation.frmReportForm.java
private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed Date dateNow = new Date(); SimpleDateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss"); System.out.println(dtcMonthChooser.getMonth()); System.out.println(dtcYearChooser.getYear()); if (radInMonth.isSelected()) { List<Transfer> transferList = new ArrayList<>(); transferList = empObj.searchRecordByMonth(dtcMonthChooser.getMonth() + 1, dtcYearChooser.getYear()); Document document = new Document(); try {/*from w w w . j a va 2s . com*/ Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph( "Transfer records at " + (dtcMonthChooser.getMonth() + 1) + "/" + dtcYearChooser.getYear(), FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radInDateRange.isSelected()) { try { List<Transfer> transferList = new ArrayList<>(); java.sql.Date fromDateSql = formatDateForSearching(dtcFromDate.getDate()); java.sql.Date toDateSql = formatDateForSearching(dtcToDate.getDate()); transferList = empObj.searchRecordByDate(fromDateSql, toDateSql); Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy"); String fromDate = df2.format(dtcFromDate.getDate()); String toDate = df2.format(dtcToDate.getDate()); Paragraph slashPara = new Paragraph("Transfer records from " + fromDate + " to " + toDate, FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParseException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radInProject.isSelected()) { String fromProjectId = (String) cbxFromProject.getSelectedItem(); String toProjectId = (String) cbxToProject.getSelectedItem(); List<Transfer> transferList = new ArrayList<>(); String andOr = ""; if (cbxAndOr.getSelectedItem().equals("And")) { andOr = "and"; transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr); } else { andOr = "or"; transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr); } Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph( "Transfer records from Project ID " + fromProjectId + " " + andOr + " " + toProjectId, FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radAllRecord.isSelected()) { List<Transfer> transferList = new ArrayList<>(); transferList = empObj.searchAllRecord(); Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph("All transfer records", FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:py.com.palermo.imprimeetiquetas.web.ProductoController.java
public String createPdf() throws IOException, DocumentException { if (hayParaImprimir()) { HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance() .getExternalContext().getResponse(); response.setContentType("application/x-pdf"); response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\""); // step 1 Document document = new Document(new Rectangle(86, 35)); // step 2 document.setMargins(0f, 0f, 0f, 0f); PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // step 3 document.open();/*from w w w . j a v a 2s .c o m*/ // step 4 PdfContentByte cb = writer.getDirectContent(); for (ProductoCantidad p : productos) { if (p.getCantidad() > 0) { BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCode(p.getCodigo()); codeEAN.setCodeType(Barcode.EAN13); codeEAN.setBarHeight(10f); codeEAN.setX(0.7f); codeEAN.setSize(4f); NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("es", "py")); Font fontbold = FontFactory.getFont("Times-Roman", 5, Font.NORMAL); Chunk productTitle = new Chunk(p.getNombre() + "," + " " + nf.format(p.getPrecio()), fontbold); // EAN 13 Paragraph pTitile = new Paragraph(productTitle); pTitile.setAlignment(Element.ALIGN_CENTER); pTitile.setLeading(0, 1); PdfPTable table = new PdfPTable(1); table.setPaddingTop(0f); table.setWidthPercentage(96); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(Rectangle.NO_BORDER); cell.addElement(codeEAN.createImageWithBarcode(cb, null, BaseColor.BLACK)); table.addCell(cell); PdfPCell cell2 = new PdfPCell(); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBorder(Rectangle.NO_BORDER); cell2.addElement(pTitile); table.addCell(cell2); for (int i = 0; i < p.getCantidad(); i++) { document.add(table); document.newPage(); } } } // step 5 document.close(); response.getOutputStream().flush(); response.getOutputStream().close(); FacesContext.getCurrentInstance().responseComplete(); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "No hay nada que imprimir", "")); } return null; }
From source file:Screens.Print.java
public void ConvertPDF() throws DocumentException, FileNotFoundException, UnsupportedEncodingException, IOException, ParserConfigurationException, SAXException { FontFactory.register("tahoma.ttf", "MY_FONT"); Document document = new Document(PageSize.A5, 20, 20, 10, 10); Image image = Image.getInstance("123.jpg"); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setBorder(0); // table.setBorderColor(BaseColor.WHITE); PdfPTable tablefooter = new PdfPTable(3); tablefooter.getDefaultCell().setBorder(0); try {/*from www . j a va 2s . c o m*/ PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); image.setAbsolutePosition(350f, 520f); document.add(image); document.add(new Paragraph("\n\n Telefon: " + PrintTel + "\n\n\n", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell( new Paragraph("Ad, Soyad, ID kod", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell(new Paragraph(DataPrint.Ad + " " + DataPrint.Soyad + " (#" + DataPrint.idDaxilOlan + ")", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell(new Paragraph("Model, Marka", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell(new Paragraph(DataPrint.Model + " " + DataPrint.Marka, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell(new Paragraph("Aksesuar", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell( new Paragraph(DataPrint.Aksesuar, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell(new Paragraph("Problem", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell( new Paragraph(DataPrint.Problem, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell(new Paragraph("Tarix", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell( new Paragraph(DataPrint.DatePlan, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell(new Paragraph("Telefon", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); table.addCell( new Paragraph(DataPrint.Telefon, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); document.add(table); document.add( new Paragraph(jEditorPane1.getText(), FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); // document.add(new Paragraph(footer, FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); tablefooter.addCell( new Paragraph("Thvil Verdi:", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); tablefooter.addCell(new Paragraph("" + DataPrint.Ad + " " + DataPrint.Soyad + "", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); tablefooter.addCell( new Paragraph("_____________", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12))); tablefooter.addCell(new Paragraph(" ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12))); tablefooter.addCell(new Paragraph(" ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12))); tablefooter.addCell(new Paragraph(" ", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12))); tablefooter.addCell( new Paragraph("Thvil ald:", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); tablefooter.addCell( new Paragraph("Elxan ?sgrli", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 10))); tablefooter.addCell( new Paragraph("_____________", FontFactory.getFont("MY_FONT", BaseFont.IDENTITY_H, 12))); document.add(tablefooter); } catch (FileNotFoundException | DocumentException e) { } document.close(); }
From source file:servlet.AdministrarRestriccion.java
public void genDocTren(HttpServletRequest request, HttpServletResponse response) throws Exception { int linea = Integer.parseInt(request.getParameter("idLinea")); //PrintWriter salida = response.getWriter(); HttpSession session = request.getSession(); // PrintWriter out = response.getWriter(); Usuario usr = (Usuario) session.getAttribute("usuario"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {/* w ww .j a v a 2s . c o m*/ String nota = new String(request.getParameter("nota").getBytes(), "UTF-8"); String nota2 = new String(request.getParameter("nota2").getBytes(), "UTF-8"); MaterialRodanteJpaController mrjc = new MaterialRodanteJpaController(Conex.getEmf()); MaterialRodante mr = mrjc .findMaterialRodante(Integer.parseInt(request.getParameter("materialRodante"))); String comunicaciones = new String(request.getParameter("comunicaciones").getBytes(), "UTF-8"); String instrucciones = new String(request.getParameter("instrucciones").getBytes(), "UTF-8"); String precauciones = new String(request.getParameter("precauciones").getBytes(), "UTF-8"); String nombre = new String(request.getParameter("nombre").getBytes(), "UTF-8"); String vigencia = request.getParameter("vigencia"); String[] fecha = vigencia.split("-"); LineaJpaController ljc = new LineaJpaController(Conex.getEmf()); Linea l = ljc.findLinea(linea); Document documento = new Document(PageSize.A4); com.itextpdf.text.Font arialNegrita = FontFactory.getFont("arial", 9, Font.BOLD); com.itextpdf.text.Font arial = FontFactory.getFont("arial", 9, Font.PLAIN); com.itextpdf.text.Font saltoDeLinea = FontFactory.getFont("arial", 5, Font.BOLD); Paragraph parrafo = new Paragraph(); int numResAs = 0; int numResDes = 0; RestriccionJpaController rjc = new RestriccionJpaController(Conex.getEmf()); List<Restriccion> restDes = rjc.buscarIdLineaDescendenteDocTren(linea, l.getVelocidadLinea()); List<Restriccion> restAsc = rjc.buscarIdLineaAscendenteDocTren(linea, l.getVelocidadLinea()); int restAscTotal = restAsc.size() - 1; int restDescTotal = restDes.size() - 1; System.out.println(restAscTotal); System.out.println(restDescTotal); PdfWriter.getInstance(documento, baos); documento.open(); do { try { URL url = getClass().getResource("/img/cintillo_s1.png"); Image foto = Image.getInstance(url); foto.scaleToFit(500, 70); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita)); documento.add(new Paragraph( "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable tabla = new PdfPTable(1); tabla.setHorizontalAlignment(10); tabla.setWidthPercentage(100f); tabla.addCell(new Paragraph("Operaciones Del Tren: circular a una velocidad no mayor de " + l.getVelocidadLinea() + " Km/h", arial)); tabla.addCell(new Paragraph("Nota: " + nota, arial)); //tabla.getDefaultCell().setBorder(2); if (numResAs < restAscTotal) { tabla.getDefaultCell().setBorderWidthBottom(0); tabla.addCell(new Paragraph("Restricciones Ascendentes ", arialNegrita)); } tabla.getDefaultCell().setBorderColorBottom(BaseColor.WHITE); int c = 0; for (int i = numResAs; i <= restAscTotal; i++) { if (c > 30) { break; } // System.out.println("imrimiento asc: "+numResAs); int pkI = (int) (restAsc.get(numResAs).getProgInicio() / 1000); int pkI1 = (int) (((restAsc.get(numResAs).getProgInicio() / 1000) - pkI) * 1000); int pkF = (int) (restAsc.get(numResAs).getProgFinal() / 1000); int pkF1 = (int) (((restAsc.get(numResAs).getProgFinal() / 1000) - pkF) * 1000); tabla.getDefaultCell().setBorder(14); tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1 + " circular a una velocidad no mayor de " + restAsc.get(numResAs).getVelocidadMaxAscendente() + " " + restAsc.get(numResAs).getObservacion(), arial)); numResAs++; c++; } if (c < 30) { tabla.getDefaultCell().setBorderWidthBottom(1); tabla.getDefaultCell().setBorderWidthTop(1); tabla.getDefaultCell().setBorder(14); tabla.addCell(new Paragraph("Restricciones Descendentes ", arialNegrita)); } int d = c; if (c < 30) { for (int i = numResDes; i <= restDescTotal; i++) { if (d > 30) { break; } tabla.getDefaultCell().setBorder(14); tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); int pkI = (int) (restDes.get(numResDes).getProgFinal() / 1000); int pkI1 = (int) (((restDes.get(numResDes).getProgFinal() / 1000) - pkI) * 1000); int pkF = (int) (restDes.get(numResDes).getProgInicio() / 1000); int pkF1 = (int) (((restDes.get(numResDes).getProgInicio() / 1000) - pkF) * 1000); tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1 + " circular a una velocidad no mayor de " + restDes.get(numResDes).getVelocidadMaxDescendente() + " " + restDes.get(numResDes).getObservacion(), arial)); numResDes++; d++; } } int espacios = d; while (espacios < 30) { tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); tabla.addCell(new Paragraph(" ", arial)); espacios++; } tabla.getDefaultCell().setBorder(15); tabla.getDefaultCell().setBorderWidthBottom(1); tabla.getDefaultCell().setBorderWidthTop(1); tabla.getDefaultCell().setMinimumHeight(50f); tabla.addCell(new Paragraph("Instrucciones: " + instrucciones, arial)); tabla.addCell(new Paragraph("Comunicaciones: " + comunicaciones, arial)); tabla.addCell(new Paragraph("Precauciones: " + precauciones, arial)); tabla.getDefaultCell().setMinimumHeight(10f); tabla.addCell(new Paragraph("Vigencia A Partir De: " + fecha[0] + "/" + fecha[1] + "/" + fecha[2], arial)); tabla.getDefaultCell().setBorder(1); Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString() + " - Gerencia de Gestin de Trfico", arialNegrita); preface.setAlignment(Element.ALIGN_CENTER); tabla.addCell(preface); tabla.getDefaultCell().setBorder(0); tabla.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); preface = new Paragraph(Paragraph.ALIGN_CENTER, "EL NO CUMPLIR CON LAS LIMITACIONES PRESCRITAS EN ESTE" + " DOCUMENTO VA EN CONTRA DE LA SEGURIDAD EN LA CIRCULACIN, POR LO TANTO SER? MOTIVO DE SANCIN", FontFactory.getFont("arial", 8f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "Nota: Informacin sustentada con el informe tcnico " + "de limitaciones de velocidad, emitido por el CCF (Centro de Control de Fallas)", FontFactory.getFont("arial", 8f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "Sentido Ascendente: Sentido en el cual aumenta la progresiva ej: 0+0 -> 41+000 -- Sentido Descendente: Sentido en el cual disminuye la progresiva ej: 41+000 -> 0+0 ", FontFactory.getFont("arial", 6f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "En la lnea Caracas-Cua el sentido ASCENDENTE corresponde a la V?A PAR y el DESCENDENTE a la V?A IMPAR", FontFactory.getFont("arial", 6f)); tabla.addCell(preface); documento.add(tabla); if (numResAs < restAscTotal || numResDes < restDescTotal) { documento.newPage(); } } while (numResAs < restAscTotal || numResDes < restDescTotal); System.out.println("Termine"); //CARACTER?STICAS DE MATERIAL RODANTE documento.newPage(); try { URL url = getClass().getResource("/img/cintillo_s1.png"); Image foto = Image.getInstance(url); foto.scaleToFit(500, 70); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita)); documento.add(new Paragraph( "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add( new Paragraph("CARACTER?STICAS DE LA UNIDAD: " + mr.getNombreMaterialRodante(), arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable tablaMT = new PdfPTable(2); tablaMT.addCell(new Paragraph("ITEM", arialNegrita)); tablaMT.addCell(new Paragraph("DESCRIPCIN", arialNegrita)); tablaMT.addCell(new Paragraph("Nmero de Unidades Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getNumeroRemolque() + " Unidades", arial)); tablaMT.addCell(new Paragraph("Nmero de Unidades Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getNumeroMotriz() + " Unidades", arial)); tablaMT.addCell(new Paragraph("Longitud Total", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudTotal() + " m", arial)); tablaMT.addCell(new Paragraph("Longitud Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudRemolque() + " m", arial)); tablaMT.addCell(new Paragraph("Longitud Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudMotriz() + " m", arial)); tablaMT.addCell(new Paragraph("Alto x Ancho Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getAltoXAnchoMotriz() + " m", arial)); tablaMT.addCell(new Paragraph("Alto x Ancho Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getAltoXAnchoRemolque() + " m", arial)); tablaMT.addCell(new Paragraph("Masa o Tara Total", arial)); tablaMT.addCell(new Paragraph(mr.getMasa() + " t", arial)); tablaMT.addCell(new Paragraph("Masa Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getMasaRemolque() + " t", arial)); tablaMT.addCell(new Paragraph("Masa Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getMasaMotriz() + " t", arial)); tablaMT.addCell(new Paragraph("Frenado", arial)); tablaMT.addCell(new Paragraph(mr.getFrenadoDescripcion() + "", arial)); tablaMT.addCell(new Paragraph("Trocha", arial)); tablaMT.addCell(new Paragraph(l.getTrocha() + " m", arial)); tablaMT.addCell(new Paragraph("Velocidad Comercial", arial)); tablaMT.addCell(new Paragraph(mr.getVelocidadOperativa() + " Km/h", arial)); tablaMT.addCell(new Paragraph("Aceleracin Mx.", arial)); tablaMT.addCell(new Paragraph(mr.getAceleracionMax() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Desaceleracin de Servicio", arial)); tablaMT.addCell(new Paragraph(mr.getDesaceleracionMax() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Desaceleracion de Emergencia", arial)); tablaMT.addCell(new Paragraph(mr.getDesaceleracionEmergencia() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Voltaje", arial)); tablaMT.addCell(new Paragraph(mr.getVoltaje() + " V", arial)); tablaMT.addCell(new Paragraph("Voltaje de Bateras", arial)); tablaMT.addCell(new Paragraph(mr.getVoltajeBateria() + " V", arial)); tablaMT.addCell(new Paragraph("Presin de Trabajo", arial)); tablaMT.addCell(new Paragraph(mr.getPresionTrabajo() + "", arial)); if (mr.getSubTipo().equals("Tren de Viajeros")) { tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " pasajeros", arial)); tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " pasajeros", arial)); tablaMT.addCell(new Paragraph("Capacidad Total", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " pasajeros", arial)); } else { tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " t", arial)); tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " t", arial)); tablaMT.addCell(new Paragraph("Capacidad Total", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " t", arial)); } documento.add(tablaMT); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); try { URL url = getClass().getResource("/img/" + request.getParameter("materialRodante") + ".jpg"); Image foto = Image.getInstance(url); foto.scaleToFit(300, 300); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable t = new PdfPTable(1); t.setWidthPercentage(100f); t.addCell("Nota: " + nota2); documento.add(t); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString(), arialNegrita); documento.add(preface); documento.close(); response.addHeader("Content-Disposition", "attachment; filename=DocumentoDeTren.pdf"); response.addHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.addHeader("Pragma", "public"); response.setContentType("application/pdf"); DataOutput output = new DataOutputStream(response.getOutputStream()); byte[] bytes = baos.toByteArray(); response.setContentLength(bytes.length); for (int i = 0; i < bytes.length; i++) { output.writeByte(bytes[i]); } } catch (Exception e) { e.printStackTrace(); // salida.print("http://localhost:8084/MODULO2.3/img/error.png"); } }
From source file:src.GUI.FONTS.java
License:Open Source License
public static Font FontHeader() { Font font = FontFactory.getFont("Helvetica", 18, Font.BOLD); return font; }
From source file:storybook.export.ExportPDF.java
public void open() { SbApp.trace("ExportPDF.open()"); outDoc = new Document(); Rectangle rectangle = new Rectangle(PageSize.getRectangle(parent.parent.paramExport.pdfPageSize)); if (parent.parent.paramExport.pdfLandscape) { rectangle = new Rectangle(PageSize.getRectangle(parent.parent.paramExport.pdfPageSize).rotate()); }//from w w w. j a v a 2s . co m outDoc.setPageSize(rectangle); try { writer = PdfWriter.getInstance(outDoc, new FileOutputStream(fileName)); } catch (FileNotFoundException | DocumentException ex) { SbApp.error(ExportPDF.class.getName(), ex); } outDoc.open(); addMetaData(); try { outDoc.add(new Phrase(parent.bookTitle + " - " + parent.exportData.getKey() + "\n", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD))); } catch (DocumentException ex) { SbApp.error("ExportPDF.open()", ex); } if (headers == null) return; float hsize[] = new float[headers.size()]; int i = 0; for (ExportHeader header : headers) { hsize[i] = header.getSize(); i++; } table = new PdfPTable(hsize); for (ExportHeader header : headers) { table.addCell(new Phrase(header.getName(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD))); } }
From source file:support.plus.reportit.export.export_pdf_class.java
License:Open Source License
public PdfPTable createFirstTable(String filenumber, String filetag, String startdate, String enddate, String TextUserNameString, String TextUserNameBossString, String mondayText1, String mondayText2, String mondayText3, String mondayText4, String mondayText5, String mondayText6, String tuesdayText1, String tuesdayText2, String tuesdayText3, String tuesdayText4, String tuesdayText5, String tuesdayText6, String wednesdayText1, String wednesdayText2, String wednesdayText3, String wednesdayText4, String wednesdayText5, String wednesdayText6, String thursdayText1, String thursdayText2, String thursdayText3, String thursdayText4, String thursdayText5, String thursdayText6, String fridayText1, String fridayText2, String fridayText3, String fridayText4, String fridayText5, String fridayText6, String mondayTextTime1, String mondayTextTime2, String mondayTextTime3, String mondayTextTime4, String mondayTextTime5, String mondayTextTime6, String tuesdayTextTime1, String tuesdayTextTime2, String tuesdayTextTime3, String tuesdayTextTime4, String tuesdayTextTime5, String tuesdayTextTime6, String wednesdayTextTime1, String wednesdayTextTime2, String wednesdayTextTime3, String wednesdayTextTime4, String wednesdayTextTime5, String wednesdayTextTime6, String thursdayTextTime1, String thursdayTextTime2, String thursdayTextTime3, String thursdayTextTime4, String thursdayTextTime5, String thursdayTextTime6, String fridayTextTime1, String fridayTextTime2, String fridayTextTime3, String fridayTextTime4, String fridayTextTime5, String fridayTextTime6) { String mon = String.valueOf(context.getResources().getText(R.string.monday_short)); String tues = String.valueOf(context.getResources().getText(R.string.tuesday_short)); String wed = String.valueOf(context.getResources().getText(R.string.wednesday_short)); String thurs = String.valueOf(context.getResources().getText(R.string.thursday_short)); String fri = String.valueOf(context.getResources().getText(R.string.friday_short)); String hours = String.valueOf(context.getResources().getText(R.string.hours)); String day = String.valueOf(context.getResources().getText(R.string.day)); String reportNr = String.valueOf(context.getResources().getText(R.string.report_nr)); String weekFrom = String.valueOf(context.getResources().getText(R.string.weekFrom)); String weekTo = String.valueOf(context.getResources().getText(R.string.weekTo)); String firmName = String.valueOf(context.getResources().getText(R.string.firmName)); String instructorName = String.valueOf(context.getResources().getText(R.string.instructorName)); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(450 / 5.23f); try {/*from ww w. ja v a2 s. c o m*/ table.setWidths(new int[] { 1, 9, 1 }); } catch (DocumentException e) { e.printStackTrace(); } PdfPCell cell; Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD); cell = new PdfPCell( new Phrase(reportNr + " " + filenumber + " " + weekFrom + " " + startdate + " " + weekTo + " " + enddate, fontbold)); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase(firmName + " " + TextUserNameString + " " + instructorName + " " + TextUserNameBossString)); cell.setColspan(3); table.addCell(cell); table.addCell(day); cell = new PdfPCell(new Phrase(filetag)); cell.setColspan(1); table.addCell(cell); table.addCell(hours); table.addCell(mon); cell = new PdfPCell(new Phrase(mondayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(mondayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(mondayTextTime6); table.addCell(tues); cell = new PdfPCell(new Phrase(tuesdayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(tuesdayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(tuesdayTextTime6); table.addCell(wed); cell = new PdfPCell(new Phrase(wednesdayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(wednesdayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(wednesdayTextTime6); table.addCell(thurs); cell = new PdfPCell(new Phrase(thursdayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(thursdayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(thursdayTextTime6); table.addCell(fri); cell = new PdfPCell(new Phrase(fridayText1)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime1); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText2)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime2); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText3)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime3); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText4)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime4); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText5)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime5); table.addCell(" "); cell = new PdfPCell(new Phrase(fridayText6)); cell.setColspan(1); table.addCell(cell); table.addCell(fridayTextTime6); createSecondTable(); return table; }