List of usage examples for com.itextpdf.text Document add
public boolean add(Element element) throws DocumentException
Element
to the Document
. From source file:com.archsystemsinc.ipms.sec.webapp.controller.IssueController.java
License:Apache License
@RequestMapping(value = "/issues/pdf", method = RequestMethod.GET) public void getPDF1(final HttpServletResponse response, final Model model, final java.security.Principal principal) throws DocumentException, IOException, ClassNotFoundException { logger.debug("Received request to download issues report as an PDF"); try {/*from ww w.j a v a 2s . c o m*/ Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:\\Test.pdf")); document.open(); final String sheetName = GenericConstants.ISSUES; final String[] coloumnNames = { "1", "2", "3", "4", "5", "6" }; final Principal currentUser = principalService.findByName(principal.getName()); final List issues = service.findCurrentUserIssues(currentUser); document.add(new Paragraph(GenericConstants.ISSUES)); PdfPTable t = new PdfPTable(3); t.setSpacingBefore(25); t.setSpacingAfter(25); for (int i = 0; i < issues.size(); i++) { Object isu = issues.get(i); } t.addCell("1.1"); t.addCell("1.2"); t.addCell("1.3"); document.add(t); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.asae.controllers.BeanGestionRutinas.java
public void generarPdf() { Document document = new Document(); try {//www. j ava2 s. com File file = File.createTempFile("rutina-", ".pdf", new File("/var/webapp/pdf")); pdfFileName = file.getName(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Font bold = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD); URL url = FacesContext.getCurrentInstance().getExternalContext() .getResource("/resources/img/logo-unicauca-negro.png"); Image imgLogoUnicauca = Image.getInstance(url); imgLogoUnicauca.scaleAbsolute(118f, 131f); PdfPTable tableEncabezado = new PdfPTable(2); tableEncabezado.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEncabezado.setWidthPercentage(100); tableEncabezado.setSpacingAfter(5); PdfPCell cell1 = new PdfPCell(imgLogoUnicauca); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(new Paragraph("Vicerrectoria Administrativa")); cell2.setBorder(Rectangle.NO_BORDER); cell2.setVerticalAlignment(Element.ALIGN_BOTTOM); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); PdfPCell cell3 = new PdfPCell(new Paragraph("Universidad del Cauca", bold)); cell3.setBorder(Rectangle.NO_BORDER); PdfPCell cell4 = new PdfPCell(new Paragraph("Gimnasio y Actividad Fsica", bold)); cell4.setBorder(Rectangle.NO_BORDER); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); tableEncabezado.addCell(cell1); tableEncabezado.addCell(cell2); tableEncabezado.addCell(cell3); tableEncabezado.addCell(cell4); PdfPTable tableDatosUsuario = new PdfPTable(3); tableDatosUsuario.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDatosUsuario.setWidthPercentage(100); tableDatosUsuario.setSpacingBefore(20); PdfPCell cell5 = new PdfPCell(new Paragraph("Nombre: " + rutinaVisualizar.getIdusuario().getFisrtname() + " " + rutinaVisualizar.getIdusuario().getSecondname() + " " + rutinaVisualizar.getIdusuario().getFirstlastname() + " " + rutinaVisualizar.getIdusuario().getSecondlastname())); cell5.setBorder(Rectangle.NO_BORDER); PdfPCell cell6 = new PdfPCell(); cell6.setBorder(Rectangle.NO_BORDER); PdfPCell cell7 = new PdfPCell(); cell7.setBorder(Rectangle.NO_BORDER); tableDatosUsuario.addCell(cell5); tableDatosUsuario.addCell(cell6); tableDatosUsuario.addCell(cell7); PdfPTable tableFechas = new PdfPTable(3); tableFechas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableFechas.setWidthPercentage(100); tableFechas.setSpacingBefore(10); PdfPCell cell8 = new PdfPCell( new Paragraph("Fecha de inicio: " + getMyFormattedDate(rutinaVisualizar.getFechaInicio()))); cell8.setBorder(Rectangle.NO_BORDER); PdfPCell cell9 = new PdfPCell( new Paragraph("Fecha de fin: " + getMyFormattedDate(rutinaVisualizar.getFechaFin()))); cell9.setBorder(Rectangle.NO_BORDER); PdfPCell cell10 = new PdfPCell(); cell10.setBorder(Rectangle.NO_BORDER); tableFechas.addCell(cell8); tableFechas.addCell(cell9); tableFechas.addCell(cell10); PdfPTable tableMedidas = new PdfPTable(4); tableMedidas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableMedidas.setWidthPercentage(100); tableMedidas.setSpacingBefore(10); Usuario usuAux = rutinaVisualizar.getIdusuario(); List<Evaluacion> lstEvalAux = usuAux.getEvaluacionList(); Evaluacion evalAux; double peso = 0; if (lstEvalAux.size() > 0) { evalAux = lstEvalAux.get(lstEvalAux.size() - 1); peso = evalAux.getPeso().doubleValue(); } double estatura = 0; MedidasGenerales medGenAux = usuAux.getMedidasGenerales(); if (medGenAux != null) { estatura = medGenAux.getEstatura().doubleValue(); } PdfPCell cell11 = new PdfPCell(new Paragraph("Peso: " + peso)); cell11.setBorder(Rectangle.NO_BORDER); PdfPCell cell12 = new PdfPCell(new Paragraph("Talla: " + estatura)); cell12.setBorder(Rectangle.NO_BORDER); double imc = 0; if (peso != 0 && estatura != 0) { imc = peso / Math.pow(estatura, 2); } PdfPCell cell13 = new PdfPCell(new Paragraph("I.M.C: " + imc)); cell13.setBorder(Rectangle.NO_BORDER); PdfPCell cell14 = new PdfPCell(new Paragraph("Rutina: " + rutinaVisualizar.getCodigoRutina())); cell14.setBorder(Rectangle.NO_BORDER); tableMedidas.addCell(cell11); tableMedidas.addCell(cell12); tableMedidas.addCell(cell13); tableMedidas.addCell(cell14); PdfPTable tableDias = new PdfPTable(2); tableDias.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDias.setWidthPercentage(100); tableDias.setSpacingBefore(20); tableDias.setHorizontalAlignment(Element.ALIGN_LEFT); tableDias.setWidths(new int[] { 1, 9 }); List<Dia> lstDiasPDF = rutinaVisualizar.getDiaList(); PdfPCell cellCabezeraDia = new PdfPCell(new Paragraph("Da", bold)); PdfPCell cellCabezeraDia2 = new PdfPCell(); cellCabezeraDia2.setBorder(Rectangle.NO_BORDER); tableDias.addCell(cellCabezeraDia); tableDias.addCell(cellCabezeraDia2); for (Dia dia : lstDiasPDF) { PdfPCell cellDia = new PdfPCell(new Paragraph(dia.getNumDia().toString())); PdfPCell cellDia2 = new PdfPCell(); cellDia2.setBorder(Rectangle.NO_BORDER); List<GrupoMuscular> lstGMuscularPDF = dia.getGrupoMuscularList(); if (lstGMuscularPDF.size() > 0) { PdfPTable tableGMuscular = new PdfPTable(2); tableGMuscular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableGMuscular.setWidthPercentage(100); tableGMuscular.setHorizontalAlignment(Element.ALIGN_LEFT); tableGMuscular.setWidths(new int[] { 1, 6 }); PdfPCell cellCabezeraGMuscular = new PdfPCell(new Paragraph("Grupo Muscular", bold)); cellCabezeraGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); PdfPCell cellCabezeraGMuscular2 = new PdfPCell(); cellCabezeraGMuscular2.setBorder(Rectangle.NO_BORDER); tableGMuscular.addCell(cellCabezeraGMuscular); tableGMuscular.addCell(cellCabezeraGMuscular2); int aux = 1; for (GrupoMuscular gMuscularFor : lstGMuscularPDF) { PdfPCell cellGMuscular = new PdfPCell( new Paragraph(gMuscularFor.getIdgrupoMuscularGeneral().getNombre())); cellGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); PdfPCell cellGMuscular2 = new PdfPCell(); cellGMuscular2.setBorder(Rectangle.NO_BORDER); List<EjercicioGm> lstEjerciciosGMuscularPDF = gMuscularFor.getEjercicioGmList(); BaseColor myColor = WebColors.getRGBColor("#CCEEFF"); if (lstEjerciciosGMuscularPDF.size() > 0) { PdfPTable tableEjercicioGMsucular = new PdfPTable(5); tableEjercicioGMsucular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEjercicioGMsucular.setWidthPercentage(100); tableEjercicioGMsucular.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cellCabezeraEjercicioGM = new PdfPCell(new Paragraph("Ejercicio", bold)); cellCabezeraEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM.setLeading(20f, 0f); cellCabezeraEjercicioGM.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM); PdfPCell cellCabezeraEjercicioGM2 = new PdfPCell(new Paragraph("Series", bold)); cellCabezeraEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM2.setLeading(20f, 0f); cellCabezeraEjercicioGM2.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM2); PdfPCell cellCabezeraEjercicioGM3 = new PdfPCell(new Paragraph("Repeticiones", bold)); cellCabezeraEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM3.setLeading(20f, 0f); cellCabezeraEjercicioGM3.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM3); PdfPCell cellCabezeraEjercicioGM4 = new PdfPCell(new Paragraph("Receso", bold)); cellCabezeraEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM4.setLeading(20f, 0f); cellCabezeraEjercicioGM4.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM4); PdfPCell cellCabezeraEjercicioGM5 = new PdfPCell(new Paragraph("Peso", bold)); cellCabezeraEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM5.setLeading(20f, 0f); cellCabezeraEjercicioGM5.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM5); int aux2 = 1; for (EjercicioGm ejercicioGm : lstEjerciciosGMuscularPDF) { PdfPCell cellEjercicioGM = new PdfPCell( new Paragraph(ejercicioGm.getEjercicio().getNombre())); cellEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM.setLeading(20f, 0f); PdfPCell cellEjercicioGM2 = new PdfPCell( new Paragraph(ejercicioGm.getNumeroSeries().toString())); cellEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM2.setLeading(20f, 0f); PdfPCell cellEjercicioGM3 = new PdfPCell( new Paragraph(ejercicioGm.getRepeticiones().toString())); cellEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM3.setLeading(20f, 0f); PdfPCell cellEjercicioGM4 = new PdfPCell( new Paragraph(ejercicioGm.getReceso().toString())); cellEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM4.setLeading(20f, 0f); PdfPCell cellEjercicioGM5 = new PdfPCell( new Paragraph(ejercicioGm.getPeso().toString())); cellEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM5.setLeading(20f, 0f); if (aux2 % 2 == 0) { cellEjercicioGM.setBackgroundColor(myColor); cellEjercicioGM2.setBackgroundColor(myColor); cellEjercicioGM3.setBackgroundColor(myColor); cellEjercicioGM4.setBackgroundColor(myColor); cellEjercicioGM5.setBackgroundColor(myColor); } tableEjercicioGMsucular.addCell(cellEjercicioGM); tableEjercicioGMsucular.addCell(cellEjercicioGM2); tableEjercicioGMsucular.addCell(cellEjercicioGM3); tableEjercicioGMsucular.addCell(cellEjercicioGM4); tableEjercicioGMsucular.addCell(cellEjercicioGM5); aux2++; } cellGMuscular2.addElement(tableEjercicioGMsucular); } tableGMuscular.addCell(cellGMuscular); tableGMuscular.addCell(cellGMuscular2); aux++; } cellDia2.addElement(tableGMuscular); } tableDias.addCell(cellDia); tableDias.addCell(cellDia2); } LineSeparator ls = new LineSeparator(); document.add(tableEncabezado); document.add(ls); document.add(tableDatosUsuario); document.add(tableFechas); document.add(tableMedidas); document.add(tableDias); document.close(); } catch (DocumentException | FileNotFoundException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(BeanGestionRutinas.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
private void addSignature(Document document) throws DocumentException, MalformedURLException, IOException { Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12f, Font.BOLD); Phrase p = new Phrase("" + getSpace(120) + "Signature", headerFont); document.add(p); }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
private void addCustomerDetails(Document document) throws DocumentException, MalformedURLException, IOException { Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD); Font shopNameFont = new Font(Font.FontFamily.TIMES_ROMAN, 18f, Font.BOLD); Font normalTextFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.NORMAL); Phrase p = null;/*from ww w. j a v a2 s . c o m*/ String customerName = ""; String doctorName = ""; String doctorAddr = ""; String customerAddr = ""; String billNo = ""; String billDate = ""; if (totalRecords != null && totalRecords.size() > 0) { for (InvoiceBean iBean : totalRecords) { if (iBean.getDoctorName() != null) doctorName = iBean.getDoctorName(); if (iBean.getDoctorAddr1() != null) doctorAddr = iBean.getDoctorAddr1(); customerName = iBean.getCustomerName(); customerAddr = iBean.getCustomerAddr1(); billNo = String.valueOf(iBean.getBillNo()); billDate = iBean.getBillDate(); } p = new Phrase("Bill No:" + billNo + getSpace(120), headerFont); document.add(p); p = new Phrase("Date:" + billDate + "\n", headerFont); document.add(p); addBlankLine(document); addImage(document); addBlankLine(document); String shopName = myaccountBean.getShopName(); p = new Phrase(shopName, shopNameFont); document.add(p); addBlankLine(document); // Add store details String address = myaccountBean.getOwnerAddr1() + "," + myaccountBean.getOwnerAddr2() + "," + myaccountBean.getState() + ",PIN-" + myaccountBean.getPin(); p = new Phrase("Shop No - " + myaccountBean.getShopNo() + "," + address, normalTextFont); document.add(p); String contactNo = myaccountBean.getMob1() + "/" + myaccountBean.getPhone1(); p = new Phrase(",Contact:" + contactNo, normalTextFont); document.add(p); addBlankLine(document); p = new Phrase("Licence No:" + myaccountBean.getLicenceNo() + getSpace(20), normalTextFont); document.add(p); p = new Phrase("Baby Food Licence No:" + myaccountBean.getBabyFoodLcNo(), normalTextFont); document.add(p); addBlankLine(document); addEmptyLine(document, 25); p = new Phrase("Name:", headerFont); document.add(p); p = new Phrase(customerName + getSpace(5), normalTextFont); document.add(p); p = new Phrase("Address:", headerFont); document.add(p); p = new Phrase(customerAddr + "\n", normalTextFont); document.add(p); p = new Phrase("Doctor's Name:", headerFont); document.add(p); p = new Phrase(doctorName + getSpace(5), normalTextFont); document.add(p); p = new Phrase("Doctor's Address:", headerFont); document.add(p); p = new Phrase(doctorAddr, normalTextFont); document.add(p); } }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
private void createTable(Document document) throws DocumentException, MalformedURLException, IOException { PdfPTable table = new PdfPTable(8); table.setWidths(new int[] { 5, 10, 30, 15, 15, 15, 25, 20 }); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); // addLogo(table); String[] headerTitle = { "Sl", "Qty", "Medicine Name", "Mfg Date", "Batch", "Exp Date", "Schedule", "Price" }; Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 10f, Font.BOLD); for (String header : headerTitle) { Phrase p = new Phrase(header, headerFont); PdfPCell c1 = new PdfPCell(p); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setLeading(0f, 1.5f);/*from w w w. j av a 2 s . co m*/ c1.setBackgroundColor(BaseColor.GRAY); table.addCell(c1); } Font contentFont = new Font(Font.FontFamily.TIMES_ROMAN, 9f); MedicineUtility mUtil = new MedicineUtility(); // table.setSpacingAfter(20); double vat = 0.0; double discount = 0.0; int count = 1; double totalAmt = 0.0; if (totalRecords != null && totalRecords.size() > 0) { for (InvoiceBean iBean : totalRecords) { // replaceDoctor = iBean.getDoctorName(); // replaceCustomer = iBean.getCustomerName(); // replaceCustAddr1 = iBean.getCustomerAddr1(); // replaceBillNo = iBean.getBillNo(); // replaceBillDate = iBean.getPurchaseDate(); vat = iBean.getVat(); discount = iBean.getDiscount(); PdfPCell c = new PdfPCell(new Phrase(count++ + "", contentFont)); table.addCell(c); c = new PdfPCell(new Phrase(iBean.getSoldoutStock() + "", contentFont)); table.addCell(c); table.addCell(new PdfPCell(new Phrase(iBean.getMedicineName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getMfgDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getBatchName(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getExpDate(), contentFont))); table.addCell(new PdfPCell(new Phrase(iBean.getSchedule(), contentFont))); totalAmt = totalAmt + (iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice()); table.addCell(new PdfPCell(new Phrase( mUtil.getFormattedAmount((iBean.getSoldoutStock() * iBean.getSoldoutUnitPrice())), contentFont))); } } double grandTotal = 0.0; // Total PdfPCell c1 = new PdfPCell(new Phrase("Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(totalAmt))); c1.setColspan(1); table.addCell(c1); // Vat c1 = new PdfPCell(new Phrase("Vat(" + vat + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double vatAmt = totalAmt * vat / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(vatAmt))); c1.setColspan(1); table.addCell(c1); // Discount c1 = new PdfPCell(new Phrase("Discount(" + discount + "%)")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); double discountAmt = totalAmt * discount / 100; c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(discountAmt))); c1.setColspan(1); table.addCell(c1); // Grand Total c1 = new PdfPCell(new Phrase("Grand Total")); c1.setColspan(7); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); grandTotal = (totalAmt + vatAmt - discountAmt); c1 = new PdfPCell(new Phrase(mUtil.getFormattedAmount(grandTotal))); c1.setColspan(1); table.addCell(c1); document.add(table); }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
private void addEmptyLine(Document document, int noOfLines) throws DocumentException { document.add(new Paragraph(noOfLines, " ")); }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
public void addImage(Document document) throws DocumentException, MalformedURLException, IOException { Image logo = Image.getInstance(invoiceBean.getLogoPath()); document.add(new Chunk(logo, 0, 5)); }
From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java
public void addBlankLine(Document document) throws DocumentException, MalformedURLException, IOException { Phrase p = new Phrase("\n"); document.add(p); }
From source file:com.atacadao.almoxarifado.model.GerandoPDF.java
public void pdfDeSaida(ArrayList<Equipamento> equipamentos, String solicitante, String autorizante, String responsavel, String numeroSaida) { Document documento = new Document(); try {/*from ww w. ja v a2 s .c o m*/ Path path = Paths.get("\\files\\saidas.pdf"); if (!Files.isDirectory(path.getParent())) { Files.createDirectory(path.getParent()); Files.createFile(path); } PdfWriter pdf; pdf = PdfWriter.getInstance(documento, new FileOutputStream("\\files\\saidas.pdf")); documento.open(); documento.addTitle("SOLICITAO DE EQUIPAMENTOS E PRODUTOS"); /** * Responsavel pelo cabealho do documento */ Image imagem = Image.getInstance("atacadao.jpg"); imagem.setAlignment(Element.ALIGN_CENTER); documento.add(imagem); Paragraph titulo = new Paragraph("SOLICITAO DE EQUIPAMENTOS E PRODUTOS", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 16, 0, BaseColor.BLACK)); titulo.setAlignment(Element.ALIGN_CENTER); documento.add(titulo); documento.setMargins(0, 0, 18, 0); Date datas = new Date(); Locale local = new Locale("pt", "BR"); SimpleDateFormat sdf = new SimpleDateFormat("E dd/MM/yyyy", local); Paragraph espaco = new Paragraph( "\n\nDeclaro para os devidos fins que eu " + solicitante + " recebi na " + sdf.format(datas) + " os equipamentos abaixo relacionados da empresa " + "Atacado dos Pisos por " + autorizante + " e autorizado por " + responsavel + ".\n", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.BLACK)); documento.add(espaco); documento.add(new Paragraph("\n Numero de registro : " + numeroSaida + "\n\n")); /** * Responsavel por cria a tabela da sada dos equipamentos */ PdfPTable pdfT = new PdfPTable(4); PdfPCell celulas = new PdfPCell(new Paragraph( "Relao de equipamentos solicitados para seus devidos fins." + " Favor caso haja devoluo manter o maximo possvel do estado atual dos mesmos. Grato !!!", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 11, 0, BaseColor.GRAY))); celulas.setColspan(4); PdfPCell patrimonio = new PdfPCell(new Paragraph("PATRIMONIO", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE))); patrimonio.setBackgroundColor(BaseColor.GRAY); patrimonio.setPadding((float) 1); PdfPCell Nome = new PdfPCell(new Paragraph("NOME", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE))); Nome.setBackgroundColor(BaseColor.GRAY); Nome.setPadding((float) 1); PdfPCell Situacao = new PdfPCell(new Paragraph("SITUAO", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE))); Situacao.setBackgroundColor(BaseColor.GRAY); Situacao.setPadding((float) 1); PdfPCell valor = new PdfPCell(new Paragraph("DESTINO", new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE))); valor.setBackgroundColor(BaseColor.GRAY); valor.setPadding((float) 1); pdfT.addCell(celulas); pdfT.addCell(patrimonio); pdfT.addCell(Nome); pdfT.addCell(Situacao); pdfT.addCell(valor); for (Equipamento equipamento : equipamentos) { PdfPCell patrimonios = new PdfPCell( new Paragraph(equipamento.getPatrimonio(), new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK))); patrimonios.setBackgroundColor(BaseColor.WHITE); Situacao.setPadding((float) 0.8); pdfT.addCell(patrimonios); PdfPCell nomes = new PdfPCell(new Paragraph(equipamento.getNome(), new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK))); nomes.setBackgroundColor(BaseColor.WHITE); nomes.setPadding((float) 0.8); pdfT.addCell(nomes); PdfPCell situacoes = new PdfPCell( new Paragraph(equipamento.getSituacao(), new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK))); situacoes.setBackgroundColor(BaseColor.WHITE); situacoes.setPadding((float) 0.8); pdfT.addCell(situacoes); PdfPCell valores = new PdfPCell(new Paragraph(equipamento.getCodigo(), new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK))); valores.setBackgroundColor(BaseColor.WHITE); valores.setPadding((float) 0.8); pdfT.addCell(valores); } documento.add(pdfT); /** * Cria tabela para assinatura do solicitante e autorizado */ PdfPTable pdfTs = new PdfPTable(5); Paragraph sol = new Paragraph("\n\n" + solicitante, new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, Font.ITALIC)); sol.setAlignment(Element.ALIGN_CENTER); PdfPCell ass = new PdfPCell(sol); ass.setBorder(0); ass.setBorderWidthTop(1); ass.setColspan(2); PdfPCell espacos = new PdfPCell(); espacos.setBorder(0); Paragraph auth = new Paragraph("\n\n" + autorizante, new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, Font.ITALIC)); auth.setAlignment(Element.ALIGN_CENTER); PdfPCell ass2 = new PdfPCell(auth); ass2.setBorder(0); ass2.setBorderWidthTop(1); ass2.setColspan(2); pdfTs.addCell(ass); pdfTs.addCell(espacos); pdfTs.addCell(ass2); documento.add(new Paragraph("\n\n\n")); documento.add(pdfTs); documento.close(); ImpressaoDeDocumentos imprimir = new ImpressaoDeDocumentos("\\files\\saidas.pdf"); // Desktop.getDesktop().open(new File("\\files\\saidas.pdf")); } catch (DocumentException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.atacadao.almoxarifado.model.GerandoPDF.java
public void pdfRelatorioSaida(ArrayList<Saida> saidas) { Document documento = new Document(PageSize.A4.rotate()); try {/*from w w w. j a v a2s . co m*/ PdfWriter pdf = PdfWriter.getInstance(documento, new FileOutputStream("relatorios.pdf")); Paragraph titulo = new Paragraph("Relatrio de Sada\n\n", new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 20, Font.BOLD)); titulo.setAlignment(Element.ALIGN_CENTER); documento.open(); documento.add(titulo); PdfPTable table = new PdfPTable(8); PdfPCell cSaida = new PdfPCell(new Phrase("N Sada")); cSaida.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cNome = new PdfPCell(new Phrase("Nome")); cNome.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cPatrimonio = new PdfPCell(new Phrase("Patrimonio")); cPatrimonio.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cValor = new PdfPCell(new Phrase("Valor")); cValor.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cSolic = new PdfPCell(new Phrase("Solicitante")); cSolic.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cAtut = new PdfPCell(new Phrase("Autorizado")); cAtut.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cCodigo = new PdfPCell(new Phrase("Codigo")); cCodigo.setBackgroundColor(BaseColor.DARK_GRAY); PdfPCell cDtSaida = new PdfPCell(new Phrase("Dt Sada")); cDtSaida.setBackgroundColor(BaseColor.DARK_GRAY); table.addCell(cSaida); table.addCell(cNome); table.addCell(cPatrimonio); table.addCell(cValor); table.addCell(cSolic); table.addCell(cAtut); table.addCell(cCodigo); table.addCell(cDtSaida); for (Saida saida : saidas) { PdfPCell sai = new PdfPCell(new Phrase(saida.getRegistro())); PdfPCell nomes = new PdfPCell(new Phrase(saida.getNome())); PdfPCell patrimonios = new PdfPCell(new Phrase(saida.getPatrimonio())); PdfPCell valores = new PdfPCell(new Phrase(String.valueOf(saida.getValor()))); PdfPCell solicitantes = new PdfPCell(new Phrase(saida.getSolicitador())); PdfPCell autorizados = new PdfPCell(new Phrase(saida.getAutorizador())); PdfPCell codigos = new PdfPCell(new Phrase(saida.getCodigo())); PdfPCell datas = new PdfPCell( new Phrase(FormatosDeData.formatarLongParaDatas(saida.getDatasaida().getTime()))); table.addCell(sai); table.addCell(nomes); table.addCell(patrimonios); table.addCell(valores); table.addCell(solicitantes); table.addCell(autorizados); table.addCell(codigos); table.addCell(datas); } documento.add(table); documento.close(); Desktop.getDesktop().open(new File("relatorios.pdf")); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex); } }