List of usage examples for com.itextpdf.text.pdf PdfPCell setBorder
public void setBorder(final int border)
From source file:com.solidmaps.webapp.report.EnableCompanyRequerimentFederalPDF.java
private void insertCellAlteracaoOption(PdfPTable table, String number, String text, Boolean selected) { String fullText = ""; if (selected) { fullText += number + " |X|" + " " + text; } else {/*ww w.jav a 2 s .co m*/ fullText += number + " | |" + " " + text; } if (StringUtils.isBlank(number) && StringUtils.isBlank(text)) { fullText = ""; } // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(fullText.trim(), FONT_PARAGRAPH)); // set the cell alignment // in case there is no text and you wan to create an empty row if (fullText.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setBorder(Rectangle.RIGHT); cell.setPaddingTop(10f); cell.setPaddingBottom(10f); cell.setPaddingLeft(10f); cell.setPaddingRight(10f); // add the call to the table table.addCell(cell); }
From source file:com.solidmaps.webapp.report.LicenseCivilIncludeProductPDF.java
License:Open Source License
private void insertCell(PdfPTable table, String text, int align, Font font, boolean border) { if (text == null) { text = ""; }/*from ww w .j a v a 2s . c o m*/ // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font)); // set the cell alignment cell.setHorizontalAlignment(align); // in case there is no text and you wan to create an empty row if (text.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } if (!border) { cell.setBorder(Rectangle.NO_BORDER); } // add the call to the table table.addCell(cell); }
From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java
private void insertCellAlteracaoOption(PdfPTable table, String number, String text, Boolean selected) { String fullText = ""; if (selected) { fullText += number + " |X|" + " " + text; } else {/*from www . ja v a 2s.c o m*/ fullText += number + " | |" + " " + text; } if (StringUtils.isBlank(number) && StringUtils.isBlank(text)) { fullText = ""; } // create a new cell with the specified Text and Font PdfPCell cell = new PdfPCell(new Phrase(fullText.trim(), FONT_PARAGRAPH)); // set the cell alignment // in case there is no text and you wan to create an empty row if (fullText.trim().equalsIgnoreCase("")) { cell.setMinimumHeight(10f); } cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setColspan(2); cell.setBorder(Rectangle.RIGHT); cell.setPaddingTop(10f); cell.setPaddingBottom(10f); cell.setPaddingLeft(25f); cell.setPaddingRight(25f); // add the call to the table table.addCell(cell); }
From source file:com.systemevent.jsfclass.util.FormatoPDF.java
/** * Constructor de la clase, inicializa la imagen que se utilizara en el membrete *///w w w . j a v a 2s . c o m public FormatoPDF(String nombre) { try { PdfPCell celda1 = new PdfPCell(new Phrase("Nombre Cliente")); PdfPCell celda2 = new PdfPCell(new Phrase(nombre)); imagen = Image.getInstance( "C:\\Users\\Jose_Gascon\\Documents\\ProyectoSystemEvent\\sysevent\\src\\main\\webapp\\resources\\imagenes\\logoconstruccion.jpg"); imagen.setAbsolutePosition(30, 720f); imagen.scaleAbsolute(100, 100); celda1.setBorder(Rectangle.BOTTOM); celda2.setBorder(Rectangle.BOTTOM); celda2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); table.addCell(celda1); table.addCell(celda2); table.setTotalWidth(350f); } catch (Exception r) { System.err.println("Error al leer la imagen"); } }
From source file:com.thelinh.gui.PreviewExam.java
private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed if (this.txtExamCode.getText().equals("")) { JOptionPane.showMessageDialog(this, "Hy nhp m ?"); } else {/*from w w w . j a v a 2 s. c o m*/ JFileChooser fc = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF files (*.pdf)", "pdf"); fc.setFileFilter(filter); int rt = fc.showSaveDialog(this); if (rt == JFileChooser.APPROVE_OPTION) { String filepath = fc.getSelectedFile().getPath(); if (filepath.indexOf(".") == -1) { filepath = filepath + ".pdf"; } String dafilepath = (new StringBuffer(filepath)).insert(filepath.length() - 4, ".da").toString(); try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(filepath)); document.open(); // Add title Paragraph p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(5); document.add(p); p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(25); document.add(p); p = new Paragraph( "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName() + ", Ngy ra ?: " + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())), times_15); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(5); document.add(p); p = new Paragraph("M ?: " + this.txtExamCode.getText() + " Th?i gian lm bi: " + spTime.getValue().toString() + " pht", timesBold_15); p.setSpacingAfter(25); document.add(p); for (int i = 0; i < this.questionList.size(); i++) { Question question = this.questionList.get(i); ArrayList<Answer> answerList = AnswerSql .getAnswersByQuestionId(question.getQuestionId().trim()); Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15); Phrase questionContent = new Phrase(question.getQuestion(), times_15); Paragraph questionTitle = new Paragraph(); questionTitle.add(questionNumber); questionTitle.add(questionContent); document.add(questionTitle); PdfPTable table = new PdfPTable(2); for (int j = 0; j < answerList.size(); j++) { Answer ans = answerList.get(j); Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15); Phrase answerContent = new Phrase(ans.getAnswer(), times_15); Phrase elem = new Phrase(); elem.add(cap); elem.add(answerContent); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setPhrase(elem); cell.setFixedHeight(25); table.addCell(cell); } document.add(table); } document.close(); // if (Desktop.isDesktopSupported()) { // try { // File myFile = new File(filepath); // Desktop.getDesktop().open(myFile); // } catch (IOException ex) { // // no application registered for PDFs // System.out.println(ex.toString()); // } // } document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dafilepath)); document.open(); // Add title p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(5); document.add(p); p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(25); document.add(p); p = new Paragraph( "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName() + ", Ngy ra ?: " + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())), times_15); p.setAlignment(Element.ALIGN_LEFT); p.setSpacingAfter(5); document.add(p); p = new Paragraph("M ?: " + this.txtExamCode.getText() + " Th?i gian lm bi: " + spTime.getValue().toString() + " pht", timesBold_15); p.setSpacingAfter(25); document.add(p); for (int i = 0; i < this.questionList.size(); i++) { Question question = this.questionList.get(i); ArrayList<Answer> answerList = AnswerSql .getAnswersByQuestionId(question.getQuestionId().trim()); Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15); Phrase questionContent = new Phrase(question.getQuestion(), times_15); Paragraph questionTitle = new Paragraph(); questionTitle.add(questionNumber); questionTitle.add(questionContent); document.add(questionTitle); PdfPTable table = new PdfPTable(2); for (int j = 0; j < answerList.size(); j++) { Answer ans = answerList.get(j); Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15); Phrase answerContent = null; if (ans.getYesNo()) { answerContent = new Phrase(ans.getAnswer(), timesBold_15); } else { answerContent = new Phrase(ans.getAnswer(), times_15); } Phrase elem = new Phrase(); elem.add(cap); elem.add(answerContent); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.NO_BORDER); cell.setPhrase(elem); cell.setFixedHeight(25); table.addCell(cell); } document.add(table); } document.close(); } catch (FileNotFoundException | DocumentException ex) { Logger.getLogger(PreviewExam.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:com.timesheet.export.PdfGenerator.java
@Override protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer, HttpServletRequest request, HttpServletResponse response) throws Exception { /* Add header*/ Font fontHeader = FontFactory.getFont(FontFactory.TIMES_ROMAN, 22, Font.BOLD); Paragraph headerPara = new Paragraph("Time sheet report", fontHeader); headerPara.setSpacingAfter(20f);// w ww. jav a2s. com document.add(headerPara); /*Add user info*/ User userProfile = (User) model.get("userprofile"); Font fontUserInfo = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD); document.add(new Paragraph("Name : " + userProfile.getName(), fontUserInfo)); document.add(new Paragraph("User no. : " + userProfile.getUserIdentifier(), fontUserInfo)); document.add(new Paragraph("Department : " + userProfile.getDepartment(), fontUserInfo)); document.add(new Paragraph("Email : " + userProfile.getEmail(), fontUserInfo)); Paragraph spacing = new Paragraph(""); spacing.setSpacingAfter(20f); document.add(spacing); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 5.0f, 3.0f, 3.0f, 3.0f, 10.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD); //font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); //cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPadding(5); cell.setBorderWidth(2.0f); cell.setBorder(Rectangle.BOTTOM); // get data model which is passed by the Spring container List<Booking> bookings = (List<Booking>) model.get("bookings"); // write table header cell.setPhrase(new Phrase("Project", font)); table.addCell(cell); // write table header cell.setPhrase(new Phrase("Option", font)); table.addCell(cell); // write table header cell.setPhrase(new Phrase("Date", font)); table.addCell(cell); // write table header cell.setPhrase(new Phrase("Duration", font)); table.addCell(cell); // write table header cell.setPhrase(new Phrase("Description", font)); table.addCell(cell); int sum = 0; Font fontData = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11); for (Booking booking : bookings) { PdfPCell cell1 = new PdfPCell(new Phrase( booking.getProject().getProjectId() + "-" + booking.getProject().getName(), fontData)); cell1.setBorder(Rectangle.BOTTOM); cell1.setPadding(5); table.addCell(cell1); PdfPCell cell2 = new PdfPCell(new Phrase(booking.getBookingOption().getOptionLabel(), fontData)); cell2.setBorder(Rectangle.BOTTOM); cell2.setPadding(5); table.addCell(cell2); PdfPCell cell3 = new PdfPCell(new Phrase(formatDate(booking.getBookingDate()), fontData)); cell3.setBorder(Rectangle.BOTTOM); cell3.setPadding(5); table.addCell(cell3); int hh = booking.getDuration() / 60; int mm = booking.getDuration() % 60; PdfPCell cell4 = new PdfPCell(new Phrase(hh + ":" + mm, fontData)); cell4.setBorder(Rectangle.BOTTOM); cell4.setPadding(5); table.addCell(cell4); PdfPCell cell5 = new PdfPCell( new Phrase(StringEscapeUtils.escapeHtml(booking.getDescription()), fontData)); cell5.setBorder(Rectangle.BOTTOM); cell5.setPadding(5); table.addCell(cell5); sum += booking.getDuration(); } document.add(table); int sumHH = sum / 60; int sumMM = sum % 60; document.add(new Paragraph("Sum : " + sumHH + ":" + sumMM, fontUserInfo)); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. }
From source file:com.tomasz.drag.triballocommanderro.controller.MakerPDF.java
public static PdfPTable createTable(Person person, EventGig event) throws DocumentException, IOException { int a = 0;/*www . j av a 2 s . c o m*/ if (person.getZaladunekScenaDachWyplata() > 0) { a++; } if (person.getZaladunekTechnikiWyplata() > 0) { a++; } if (person.getMontazDachuWyplata() > 0) { a++; } if (person.getMontazDzwiekuWyplata() > 0) { a++; } if (person.getMontazScenyWyplata() > 0) { a++; } if (person.getMontazSwiatlaWyplata() > 0) { a++; } if (person.getMontazTechnikiWyplata() > 0) { a++; } if (person.getDemontazDachuWyplata() > 0) { a++; } if (person.getDemontazDzwiekuWyplata() > 0) { a++; } if (person.getDemontazScenyWyplata() > 0) { a++; } if (person.getDemontazSwiatlaWyplata() > 0) { a++; } if (person.getDemontazTechnikiWyplata() > 0) { a++; } if (person.getRozladunekScenaDachWyplata() > 0) { a++; } if (person.getRozladunekTechnikiWyplata() > 0) { a++; } if (person.getDyzurWyplata() > 0) { a++; } if (person.getTechnikScenyWyplata() > 0) { a++; } if (person.getRealizacjaFOHWyplata() > 0) { a++; } if (person.getRealizacjaMONWyplata() > 0) { a++; } if (person.getRealizacjaSwiatlaWyplata() > 0) { a++; } if (person.getPremia() > 0) { a++; } System.out.println(a); BaseFont bf; bf = BaseFont.createFont("src\\main\\resources\\font\\arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // bf = BaseFont.createFont("arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); com.itextpdf.text.Font ft = new com.itextpdf.text.Font(bf); PdfPTable table = new PdfPTable(2); table.setTotalWidth(new float[] { 90, 190 }); table.setLockedWidth(true); PdfPCell cell; cell = new PdfPCell(new Phrase(person.getName() + " " + person.getSurName(), ft)); cell.setColspan(1); table.addCell(cell); cell = new PdfPCell(new Phrase(event.getName() + " " + event.getData(), ft)); cell.setColspan(2); table.addCell(cell); cell = new PdfPCell(new Phrase("")); cell.setRowspan(a); table.addCell(cell); if (person.getZaladunekScenaDachWyplata() > 0) { table.addCell(new Phrase("Zaadunek Scena/Dach", ft)); } if (person.getZaladunekTechnikiWyplata() > 0) { table.addCell(new Phrase("Zaadunek Techniki", ft)); } if (person.getMontazDachuWyplata() > 0) { table.addCell(new Phrase("Monta Dachu", ft)); } if (person.getMontazDzwiekuWyplata() > 0) { table.addCell(new Phrase("Monta Dwieku", ft)); } if (person.getMontazScenyWyplata() > 0) { table.addCell(new Phrase("Monta Sceny", ft)); } if (person.getMontazSwiatlaWyplata() > 0) { table.addCell(new Phrase("Monta wiata", ft)); } if (person.getMontazTechnikiWyplata() > 0) { table.addCell(new Phrase("Monta Techniki", ft)); } if (person.getDemontazDachuWyplata() > 0) { table.addCell(new Phrase("Demonta Dachu", ft)); } if (person.getDemontazDzwiekuWyplata() > 0) { table.addCell(new Phrase("Demonta Dwieku", ft)); } if (person.getDemontazScenyWyplata() > 0) { table.addCell(new Phrase("Demonta Sceny", ft)); } if (person.getDemontazSwiatlaWyplata() > 0) { table.addCell(new Phrase("Demonta wiata", ft)); } if (person.getDemontazTechnikiWyplata() > 0) { table.addCell(new Phrase("Demonta Techniki", ft)); } if (person.getRozladunekScenaDachWyplata() > 0) { table.addCell(new Phrase("Rozadunek Scena/Dach", ft)); } if (person.getRozladunekTechnikiWyplata() > 0) { table.addCell(new Phrase("Rozadunek Techniki", ft)); } if (person.getDyzurWyplata() > 0) { table.addCell(new Phrase("Dyur", ft)); } if (person.getTechnikScenyWyplata() > 0) { table.addCell(new Phrase("Technik Sceny", ft)); } if (person.getRealizacjaFOHWyplata() > 0) { table.addCell(new Phrase("Realizacja FOH", ft)); } if (person.getRealizacjaMONWyplata() > 0) { table.addCell(new Phrase("Realizacja MON", ft)); } if (person.getRealizacjaSwiatlaWyplata() > 0) { table.addCell(new Phrase("Realizacja wiata", ft)); } if (person.getPremia() > 0) { table.addCell(new Phrase("Premia", ft)); } cell = new PdfPCell(new Phrase("Suma: ")); cell.setColspan(1); table.addCell(cell); //cell = new PdfPCell(new Phrase(Double.toString(person.getSumaWyplata())));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()) cell = new PdfPCell(new Phrase(String.format("%.2f", person.getSumaWyplata()) + " z", ft));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()) table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); //cell = new PdfPCell(new Phrase(Double.toString(person.getSumaWyplata())));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()) cell = new PdfPCell(new Phrase(" "));//String.format("%.2f", tempPerson.getRealizacjaSwiatlaWyplata()) cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); table.setBreakPoints(2 + a); return table; }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable firma() throws DocumentException { PdfPTable tabla = new PdfPTable(3); tabla.setWidthPercentage(100);//from ww w. ja v a2 s . co m tabla.setWidths(new float[] { 2, 1, 2 }); //Declaramos un objeto para manejar las celdas PdfPCell celda; celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.BOTTOM); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.BOTTOM); tabla.addCell(celda); celda = new PdfPCell(new Phrase("JEFE ADMINISTRATIVO")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("EMPLEADO")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); return tabla; }
From source file:com.udec.utilidades.PdfTable.java
public PdfPTable tabla3(List<Nomina> no) throws DocumentException { //Instanciamos una tabla de 3 columnas PdfPTable tabla = new PdfPTable(4); tabla.setWidthPercentage(100);//from w w w . jav a 2 s . com tabla.setWidths(new float[] { 1, 3, 1, 1 }); //Declaramos un objeto para manejar las celdas PdfPCell celda; celda = new PdfPCell(new Phrase("CODIGO")); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); tabla.addCell(celda); celda = new PdfPCell(new Phrase("DESCRIPCION")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); celda = new PdfPCell(new Phrase("VLR.DEVEN")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); celda.setBorderWidth(1); celda.setVerticalAlignment(Element.ALIGN_TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase("VLR.DEDUC")); celda.setBorder(Rectangle.BOTTOM); celda.setVerticalAlignment(Element.ALIGN_TOP); celda.setBorderWidth(1); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); double totalDev = 0, totalDed = 0; for (Nomina nomina : no) { celda = new PdfPCell(new Phrase("" + nomina.getConceptoIdconcepto().getCodigo())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); celda = new PdfPCell(new Phrase("" + nomina.getConceptoIdconcepto().getConcepto())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); tabla.addCell(celda); if (nomina.getConceptoIdconcepto().getTipo().equals("DEVENGADO")) { totalDev += nomina.getValor(); celda = new PdfPCell(new Phrase("" + nomina.getValor())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); } else { celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } if (nomina.getConceptoIdconcepto().getTipo().equals("DEDUCIDO")) { totalDed += nomina.getValor(); celda = new PdfPCell(new Phrase("" + nomina.getValor())); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); } else { celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); } } celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("TOTALES")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("" + totalDev)); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); celda.setBorder(Rectangle.TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" " + totalDed)); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); celda.setBorder(Rectangle.TOP); tabla.addCell(celda); celda = new PdfPCell(new Phrase("")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase("NETO A PAGAR")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" " + (totalDev - totalDed))); celda.setBorder(Rectangle.NO_BORDER); celda.setHorizontalAlignment(Element.ALIGN_RIGHT); tabla.addCell(celda); celda = new PdfPCell(new Phrase(" ")); celda.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda); return tabla; }
From source file:com.vimbox.hr.LicensePDFGenerator.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j a v a 2 s. co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); String fileName = request.getParameter("license_name"); String ext = fileName.substring(fileName.lastIndexOf(".") + 1); String path = System.getProperty("user.dir") + "/documents/licenses/" + fileName; path = path.replaceAll("%20", " "); if (ext.equalsIgnoreCase("pdf")) { FileInputStream baos = new FileInputStream(path); OutputStream os = response.getOutputStream(); byte buffer[] = new byte[8192]; int bytesRead; while ((bytesRead = baos.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } os.flush(); os.close(); } else { try { // Document Settings // Document document = new Document(); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); // Loading MC // PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); // the cell object PdfPCell cell; Image img = Image.getInstance(path); int indentation = 0; float scaler = ((document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin() - indentation) / img.getWidth()) * 100; img.scalePercent(scaler); //img.scaleAbsolute(80f, 80f); cell = new PdfPCell(img); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); document.add(table); //-----------------------------------// document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } } }