List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(final float widthPercentage)
From source file:IPDGES.ConcentForm.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/* w ww . j a v a 2 s . com*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); try { //style Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1); Font type = new Font(Font.FontFamily.TIMES_ROMAN, 10); Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1); Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1); Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1); float space = (float) 20; Document document = new Document(); document.setPageSize(PageSize.LETTER); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); //General PdfPTable table; Paragraph p1; Paragraph p2; PdfPCell cellRow1; PdfPCell cellRow2; //row: 1 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "FORMULARIO DE CONSTANCIA DE INFORMACION AL PACIENTE GES", title); p1.setAlignment(Element.ALIGN_CENTER); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); table.addCell(cellRow1); p1 = new Paragraph(space, "(Artculo 24, Ley 19.966)", subTitle2); p1.setAlignment(Element.ALIGN_CENTER); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); table.addCell(cellRow1); document.add(table); document.add(new Paragraph("\n")); //row: 2 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "DATOS DEL PRESTADOR", subTitle); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthTop(1); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); p1 = new Paragraph(space, "INSTITUCIN (Hospital, Clnica, Consultorio,etc): " + institution, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "DIRECCION: " + address, type); p2 = new Paragraph(space, "CIUDAD: " + city, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "NOMBRE PERSONA QUE NOTIFICA: " + personName, type); p2 = new Paragraph(space, "RUT: " + rut, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); cellRow2.setBorderWidthBottom(1); table.addCell(cellRow1); table.addCell(cellRow2); document.add(table); document.add(new Paragraph("\n")); //row 3 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "ANTECEDENTES DEL PACIENTE", subTitle); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthTop(1); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); p1 = new Paragraph(space, "NOMBRE: " + patientName, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "RUT: " + patientRut, type); p2 = new Paragraph(space, "FONASA: " + patientFonasa, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "ISAPRE: " + patientIsapre, type); p2 = new Paragraph(space, "DOMICILIO: " + home, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "COMUNA: " + commune, type); p2 = new Paragraph(space, "REGION: " + region, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "N TELFONO FIJO: " + phoneNumber, type); p2 = new Paragraph(space, "N TELFONO CELULAR: " + celularNumber, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "DIRECCIN CORREO ELECTRNICO (E-MAIL): " + mail, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); document.add(table); document.add(new Paragraph("\n")); //row 4 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "INFORMACIN MDICA", subTitle); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthTop(1); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); p1 = new Paragraph(space, "CONFIRMACIN DIAGNSTICA GES:", type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, ges, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "( ) Confirmacin Diagnstica", type); p2 = new Paragraph(space, "( ) Paciente en Tratamiento", type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); cellRow2.setBorderWidthBottom(1); table.addCell(cellRow1); table.addCell(cellRow2); document.add(table); //row 5 document.add(new Paragraph(space, "CONSTANCIA", subTitle)); Paragraph text1 = new Paragraph(space, "Declaro que, con esta fecha y hora, he tomado conocimiento que tengo derecho a acceder a las Garantas Explcitas en Salud, siempre que la atencin sea otorgada en la red de Prestadores que me corresponde segn Fonasa o Isapre, a la que me encuentro adscrito", type); text1.setAlignment(Element.ALIGN_JUSTIFIED); document.add(text1); document.add(new Paragraph(space, "IMPORTANTE", subTitle)); Paragraph text2 = new Paragraph(space, "Tenga presente que s no se cumplen las garantas usted puede reclamar ante Fonasa o la Isapre, segn corresponda. Si la respuesta no es satisfactoria, usted puede recurrir en segunda instancia a la Superintendencia de Salud.", type); text2.setAlignment(Element.ALIGN_JUSTIFIED); document.add(text2); document.add(new Paragraph(space, "FECHA Y HORA DE NOTIFICACIN: " + "-", subTitle)); document.add(new Paragraph(space, "\n", type)); document.add(new Paragraph(space, "\n", type)); document.add(new Paragraph(space, "\n", type)); //row 6 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "INFORM DIAGNSTICO GES", subTitle); p2 = new Paragraph(space, "TOM CONOCIMIENTO", subTitle); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "(Firma de persona que notifica)", subTitle2); p2 = new Paragraph(space, "(Firma o huella digital representante)", subTitle2); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); table.addCell(cellRow1); table.addCell(cellRow2); document.add(table); //row 7 document.add(new Paragraph(space, "En caso que la persona que tom conocimiento no sea el paciente, identificar.", type)); //row 8 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "Nombre:", type); p2 = new Paragraph(space, "R.U.T:", type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "N Telfono Celular:", type); p2 = new Paragraph(space, "Direccin correo electrnico (e-mail):", type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); table.addCell(cellRow1); table.addCell(cellRow2); document.add(table); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } }
From source file:IPDGES.IPD.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from www . j a v a2 s . c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); try { //style Font typeBold = new Font(Font.FontFamily.TIMES_ROMAN, 12, 1); Font type = new Font(Font.FontFamily.TIMES_ROMAN, 12); Font title = new Font(Font.FontFamily.TIMES_ROMAN, 15, 1); Font subTitle = new Font(Font.FontFamily.TIMES_ROMAN, 13, 1); Font subTitle2 = new Font(Font.FontFamily.TIMES_ROMAN, 10, 1); float space = (float) 20; Document document = new Document(); document.setPageSize(PageSize.LETTER); PdfWriter.getInstance(document, response.getOutputStream()); document.open(); //General PdfPTable table; Paragraph p1; Paragraph p2; PdfPCell cellRow1; PdfPCell cellRow2; //row: 1 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "Informe de Proceso Diagnstico", title); p1.setAlignment(Element.ALIGN_CENTER); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 40); table.addCell(cellRow1); document.add(table); //row: 2 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "Fecha: " + dfDateInstance.format(date), type); p2 = new Paragraph(space, "Folio: " + numberFolio, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); table.addCell(cellRow1); table.addCell(cellRow2); document.add(table); document.add(new Paragraph("\n")); //row: 3 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "Servicio de Salud: " + healthService, type); p2 = new Paragraph(space, "Establecimiento: " + establishment, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthTop(1); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthTop(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "Especialidad: " + speciality, type); p2 = new Paragraph(space, "Unidad: " + unit, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthBottom(1); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthBottom(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); document.add(table); document.add(new Paragraph("\n")); //row: 4 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "Datos del Paciente", subTitle); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthTop(1); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Historia clnica: " + clinicalHistory, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Nombre: " + patientName, type); p2 = new Paragraph(space, "Rut: " + Rut, type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "Sexo: " + sexo, type); p2 = new Paragraph(space, "Fecha de nacimiento: " + dfDateInstance.format(bornDate), type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); table.addCell(cellRow1); table.addCell(cellRow2); p1 = new Paragraph(space, "Edad: " + age, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); document.add(table); document.add(new Paragraph("\n")); //row 5 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "Datos Clnicos", subTitle); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthTop(1); cellRow1.setBorderWidthBottom(1); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "* Slo para caso AUGE", subTitle2); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Problema de salud AUGE:", typeBold); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, augeProblem, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Confirma que el diagnstico pertenece al sistema AUGE? " + "()SI ()NO", type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "SubProblema Auge:", typeBold); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, augeSubProblem, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Diagnstico:", typeBold); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, diagnosis, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Fundamentos de diagnstico:", typeBold); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, diagnosticBasics, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Tratamiento e Indicaciones:", typeBold); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, treatment, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "El tratamiento deber iniciarce a ms tardar el: " + dfDateInstance.format(treatmentInit), type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); document.add(table); document.add(new Paragraph("\n")); //row: 6 table = new PdfPTable(2); table.setWidthPercentage(100); p1 = new Paragraph(space, "Datos del Profesional", subTitle); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthTop(1); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Nombre: " + professionalName, type); cellRow1 = new PdfPCell(p1); cellRow1.setColspan(2); formatCellBorder(cellRow1, 20); cellRow1.setBorderWidthLeft(1); cellRow1.setBorderWidthRight(1); table.addCell(cellRow1); p1 = new Paragraph(space, "Rut: " + professionalRut, type); p2 = new Paragraph(space, "Firma del mdico", type); cellRow1 = new PdfPCell(p1); cellRow2 = new PdfPCell(p2); formatCellBorder(cellRow1, 20); formatCellBorder(cellRow2, 20); cellRow1.setBorderWidthLeft(1); cellRow2.setBorderWidthRight(1); cellRow1.setBorderWidthBottom(1); cellRow2.setBorderWidthBottom(1); table.addCell(cellRow1); table.addCell(cellRow2); table.addCell(cellRow1); document.add(table); document.add(new Paragraph("\n")); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } }
From source file:it.vige.magazzino.pdf.Format1DocumentReceipt.java
License:Apache License
@Model public void build(Receipt receipt) throws Exception { ResourceBundle bundle = ResourceBundle.getBundle("messages"); Document document = new Document(); ByteArrayOutputStream bytesOS = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, bytesOS); document.open();/*w w w.java2 s . c om*/ Font normalFont = new Font(); Font headerFont = FontFactory.getFont(FontFactory.TIMES, 9); PdfContentByte canvas = writer.getDirectContentUnder(); List<Data> imagesJar = receipt.getJar().getFiles(); if (imagesJar != null && imagesJar.size() > 0) { Image image1 = Image.getInstance(imagesJar.get(0).getData()); image1.setAbsolutePosition(166, 738); image1.scalePercent(60); document.add(image1); if (imagesJar.size() > 1) { Image image2 = Image.getInstance(imagesJar.get(1).getData()); image2.setAbsolutePosition(326, 748); image2.scalePercent(40); document.add(image2); } } Phrase phrase1 = new Phrase(receipt.getJar().getRagSoc1(), normalFont); Phrase phrase2 = new Phrase( receipt.getJar().getAddress().getAddress() + " " + receipt.getJar().getAddress().getCivicNumber(), normalFont); Phrase phrase3 = new Phrase("Loc. " + receipt.getJar().getAddress().getTown() + " - " + receipt.getJar().getAddress().getCap() + " " + receipt.getJar().getAddress().getCity() + " (" + receipt.getJar().getAddress().getProvince() + ")", normalFont); Phrase phrase4 = new Phrase("Tel. " + receipt.getJar().getAddress().getPhone() + " r.a.Fax " + receipt.getJar().getAddress().getFax(), normalFont); Phrase phrase5 = new Phrase( receipt.getJar().getAddress().getSite() + " E-mail: " + receipt.getJar().getAddress().getEmail(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 36, 784, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 36, 774, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 36, 764, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 36, 754, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 36, 744, 0); Phrase phrase6 = new Phrase(bundle.getString("magazzino_iva") + " " + receipt.getJar().getIva(), normalFont); Phrase phrase7 = new Phrase(bundle.getString("magazzino_capsoc") + " " + receipt.getJar().getCapSoc() + " - " + bundle.getString("magazzino_reapi") + " n. " + receipt.getJar().getReaPI(), normalFont); Phrase phrase8 = new Phrase("Reg. Impr. PI n. " + receipt.getJar().getIva(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 36, 724, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 36, 714, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 36, 704, 0); Phrase phrase9 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase10 = new Phrase("prova 3: prova 3", normalFont); Phrase phrase11 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase12 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase13 = new Phrase("prova 3: prova 3", normalFont); Phrase phrase14 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase15 = new Phrase("prova 4: prova 4", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 664, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 36, 654, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 644, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 36, 634, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 624, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 36, 614, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 604, 0); List<Data> imagesCustomer = receipt.getCustomer().getFiles(); if (imagesCustomer != null && imagesCustomer.size() > 0) { Image image3 = Image.getInstance(imagesCustomer.get(0).getData()); image3.setAbsolutePosition(212, 664); image3.scalePercent(40); document.add(image3); } Phrase phrase16 = new Phrase(receipt.getCustomer().getName(), normalFont); Phrase phrase17 = new Phrase(receipt.getCustomer().getAddress().getAddress() + ", " + receipt.getCustomer().getAddress().getCivicNumber(), normalFont); Phrase phrase18 = new Phrase( receipt.getCustomer().getAddress().getCap() + " " + receipt.getCustomer().getAddress().getCity() + " " + receipt.getCustomer().getAddress().getProvince(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 206, 644, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 206, 624, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 206, 604, 0); Phrase phrase19 = new Phrase("prova", normalFont); Phrase phrase20 = new Phrase("prova", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 316, 694, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 356, 694, 0); Phrase phrase21 = new Phrase( bundle.getString("customer_code").toUpperCase() + " " + bundle.getString("customer").toUpperCase(), headerFont); Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva").toUpperCase(), headerFont); Phrase phrase23 = new Phrase(bundle.getString("pdf_agent").toUpperCase(), headerFont); Phrase phrase24 = new Phrase(bundle.getString("pdf_number_receipt").toUpperCase(), headerFont); Phrase phrase25 = new Phrase( bundle.getString("receipt_date").toUpperCase() + " " + bundle.getString("receipt").toUpperCase(), headerFont); Phrase phrase26 = new Phrase(bundle.getString("pdf_number_page").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 24, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 100, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 176, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 390, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 466, 540, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase26, 542, 540, 0); Phrase phrase27 = new Phrase("aaqaqaq", normalFont); Phrase phrase28 = new Phrase("cddcddcd", normalFont); Phrase phrase29 = new Phrase("cnjcndkd", normalFont); Phrase phrase30 = new Phrase(receipt.getCodeReceipt() + "", normalFont); Phrase phrase31 = new Phrase(receipt.getDate(), normalFont); Phrase phrase32 = new Phrase("tgsb", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase27, 36, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase28, 106, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase29, 176, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase30, 396, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase31, 470, 530, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase32, 546, 530, 0); Phrase phrase33 = new Phrase("aaqaqaq", headerFont); Phrase phrase34 = new Phrase("cddcddcd", headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 24, 513, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 264, 513, 0); Phrase phrase35 = new Phrase("cnjcndkd", normalFont); Phrase phrase36 = new Phrase("dddedreqq", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 36, 503, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 276, 503, 0); Phrase phrase37 = new Phrase(bundle.getString("article_code").toUpperCase(), headerFont); Phrase phrase38 = new Phrase(bundle.getString("article_description").toUpperCase(), headerFont); Phrase phrase39 = new Phrase(bundle.getString("article_um").toUpperCase(), headerFont); Phrase phrase40 = new Phrase(bundle.getString("pdf_number_articles").toUpperCase(), headerFont); Phrase phrase41 = new Phrase(bundle.getString("article_prize").toUpperCase(), headerFont); Phrase phrase42 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont); Phrase phrase43 = new Phrase(bundle.getString("pdf_amount").toUpperCase(), headerFont); Phrase phrase44 = new Phrase(bundle.getString("pdf_iva").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase37, 47, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase38, 126, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase39, 286, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase40, 324, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase41, 373, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase42, 440, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 488, 480, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 552, 480, 0); Phrase phrase45 = null; Phrase phrase46 = null; Phrase phrase47 = null; Phrase phrase48 = null; Phrase phrase49 = null; Phrase phrase50 = null; Phrase phrase51 = null; Phrase phrase52 = null; int i = 0; for (i = 0; i < 70; i = i + 15) { phrase45 = new Phrase("dgbsbb", normalFont); phrase46 = new Phrase("323232", normalFont); phrase47 = new Phrase("bbg", normalFont); phrase48 = new Phrase("wefwe", normalFont); phrase49 = new Phrase("ewrew", normalFont); phrase50 = new Phrase("ewr5", normalFont); phrase51 = new Phrase("dsadasd", normalFont); phrase52 = new Phrase("ds", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase45, 59, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase46, 126, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase47, 280, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 306, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase49, 368, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 436, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase51, 480, 460 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 556, 460 - i, 0); } int j = 298; if (i - 298 < 0) i = 298; else { j = i; i = 460 - i; } Phrase phrase81 = new Phrase(receipt.getCause(), normalFont); Phrase phrase82 = new Phrase(receipt.getDescription(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase81, 59, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase82, 326, i, 0); Phrase phrase53 = new Phrase(bundle.getString("pdf_total_goods").toUpperCase(), headerFont); Phrase phrase54 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont); Phrase phrase55 = new Phrase(bundle.getString("pdf_total_net").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase53, 26, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase54, 104, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase55, 182, i - 30, 0); Phrase phrase56 = new Phrase("opoppp", normalFont); Phrase phrase57 = new Phrase("2ws", normalFont); Phrase phrase58 = new Phrase("78900", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase56, 96, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase57, 176, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase58, 252, i - 50, 0); Phrase phrase59 = new Phrase(bundle.getString("pdf_expiries").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase59, 36, i - 70, 0); Phrase phrase60 = new Phrase("78900", normalFont); Phrase phrase61 = new Phrase("opoppp", normalFont); Phrase phrase62 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase60, 166, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase61, 166, i - 110, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase62, 166, i - 130, 0); Phrase phrase63 = new Phrase("78900", normalFont); Phrase phrase64 = new Phrase("opoppp", normalFont); Phrase phrase65 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase63, 256, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase64, 256, i - 110, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase65, 256, i - 130, 0); Phrase phrase66 = new Phrase(bundle.getString("pdf_transport").toUpperCase(), headerFont); Phrase phrase67 = new Phrase(bundle.getString("pdf_caching").toUpperCase(), headerFont); Phrase phrase68 = new Phrase(bundle.getString("pdf_various_costs").toUpperCase(), headerFont); Phrase phrase69 = new Phrase(bundle.getString("pdf_stamps").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase66, 260, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase67, 340, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase68, 418, i - 30, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase69, 496, i - 30, 0); Phrase phrase70 = new Phrase("2ws", normalFont); Phrase phrase71 = new Phrase("78900", normalFont); Phrase phrase72 = new Phrase("opoppp", normalFont); Phrase phrase73 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase70, 300, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase71, 390, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase72, 468, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase73, 546, i - 50, 0); Phrase phrase74 = new Phrase(bundle.getString("article_imponible").toUpperCase(), headerFont); Phrase phrase75 = new Phrase(bundle.getString("pdf_tax").toUpperCase(), headerFont); Phrase phrase76 = new Phrase(bundle.getString("pdf_total_receipt").toUpperCase(), headerFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase74, 260, i - 70, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase75, 352, i - 70, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase76, 484, i - 70, 0); Phrase phrase77 = new Phrase("2ws", normalFont); Phrase phrase78 = new Phrase("78900", normalFont); Phrase phrase79 = new Phrase("opoppp", normalFont); Phrase phrase80 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase77, 310, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase78, 352, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase79, 450, i - 90, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase80, 536, i - 110, 0); PdfPTable table = new PdfPTable(1); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); PdfPCell cell = new PdfPCell(); cell.setPadding(127); table.addCell(cell); document.add(table); table = new PdfPTable(6); table.getDefaultCell().setPadding(5); table.setWidthPercentage(105); table.setWidths(new float[] { 7, 7, 20, 7, 7, 3 }); cell = new PdfPCell(); cell.setPadding(14); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(2); table.getDefaultCell().setPadding(5); table.setWidthPercentage(105); table.setWidths(new float[] { 15.5f, 20 }); cell = new PdfPCell(); cell.setPadding(14); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(1); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); cell = new PdfPCell(); cell.setPadding(3); table.addCell(cell); document.add(table); table = new PdfPTable(7); table.getDefaultCell().setPadding(100); table.setWidths(new float[] { 23.5f, 2, 5, 6, 4, 7, 3 }); table.setWidthPercentage(105); cell = new PdfPCell(); cell.setPadding(j * 8 - 2279); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(7); table.getDefaultCell().setPadding(5); table.setWidthPercentage(105); cell = new PdfPCell(); cell.setPadding(17); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(5); table.setWidths(new float[] { 10.5f, 4, 6, 4 }); table.setWidthPercentage(105); cell = new PdfPCell(); cell.setPadding(48); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); document.close(); HttpServletResponse response = (HttpServletResponse) extCtx.getResponse(); response.setContentType("application/pdf"); response.addHeader("Content-disposition", "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\""); ServletOutputStream os = response.getOutputStream(); os.write(bytesOS.toByteArray()); os.flush(); os.close(); facesContext.responseComplete(); }
From source file:it.vige.magazzino.pdf.Format2DocumentReceipt.java
License:Apache License
@Model public void build(Receipt receipt) throws Exception { ResourceBundle bundle = ResourceBundle.getBundle("messages"); Document document = new Document(); ByteArrayOutputStream bytesOS = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, bytesOS); document.open();/*from w w w . j a va 2 s. c o m*/ Font normalFont = new Font(); PdfContentByte canvas = writer.getDirectContentUnder(); List<Data> imagesJar = receipt.getJar().getFiles(); if (imagesJar != null && imagesJar.size() > 0) { Image image1 = Image.getInstance(imagesJar.get(0).getData()); image1.setAbsolutePosition(36, 742); image1.scalePercent(60); document.add(image1); } Phrase phrase1 = new Phrase(bundle.getString("pdf_number_receipt"), normalFont); Phrase phrase2 = new Phrase(receipt.getCodeReceipt() + "", normalFont); Phrase phrase3 = new Phrase(bundle.getString("receipt_date"), normalFont); Phrase phrase4 = new Phrase(receipt.getDate(), normalFont); Phrase phrase5 = new Phrase(receipt.getCause(), normalFont); Phrase phrase6 = new Phrase(receipt.getDescription(), normalFont); Phrase phrase7 = new Phrase(bundle.getString("customer_code") + " " + bundle.getString("customer"), normalFont); Phrase phrase8 = new Phrase("prova 4: prova 4", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 286, 797, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 386, 797, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 286, 777, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 386, 777, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 286, 757, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 386, 757, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 286, 737, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 386, 737, 0); Phrase phrase9 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase10 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase11 = new Phrase("prova 3: prova 3", normalFont); Phrase phrase12 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase13 = new Phrase(bundle.getString("pdf_tel"), normalFont); Phrase phrase14 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase15 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont); Phrase phrase16 = new Phrase("prova 4: prova 4", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 718, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 136, 718, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 698, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 136, 698, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 678, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 136, 678, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 658, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 136, 658, 0); Phrase phrase17 = new Phrase("Ditta", normalFont); Phrase phrase18 = new Phrase("prova 2: prova 2", normalFont); Phrase phrase19 = new Phrase("prova 3: prova 3", normalFont); Phrase phrase20 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase21 = new Phrase("prova 4: prova 4", normalFont); Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont); Phrase phrase23 = new Phrase("prova 2: ", normalFont); Phrase phrase24 = new Phrase(bundle.getString("pdf_cod_fisc"), normalFont); Phrase phrase25 = new Phrase("prova 2: ", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 236, 736, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 236, 708, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 236, 688, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 236, 668, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 386, 668, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 236, 648, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 286, 648, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 356, 648, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 416, 648, 0); Phrase phrase26 = new Phrase(bundle.getString("article_code"), normalFont); Phrase phrase27 = new Phrase(bundle.getString("article_description"), normalFont); Phrase phrase28 = new Phrase(bundle.getString("pdf_number_articles"), normalFont); Phrase phrase29 = new Phrase(bundle.getString("article_prize"), normalFont); Phrase phrase30 = new Phrase(bundle.getString("pdf_reduction"), normalFont); Phrase phrase31 = new Phrase(bundle.getString("pdf_amount"), normalFont); Phrase phrase32 = new Phrase(bundle.getString("pdf_iva"), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase26, 59, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase27, 146, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase28, 208, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase29, 280, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase30, 353, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase31, 422, 618, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase32, 498, 618, 0); Phrase phrase33 = null; Phrase phrase34 = null; Phrase phrase35 = null; Phrase phrase36 = null; Phrase phrase37 = null; Phrase phrase38 = null; Phrase phrase39 = null; int i = 0; for (i = 0; i < 70; i = i + 15) { phrase33 = new Phrase("dsadasd", normalFont); phrase34 = new Phrase("dgbsbb", normalFont); phrase35 = new Phrase("323232", normalFont); phrase36 = new Phrase("bbgdbdfbdb", normalFont); phrase37 = new Phrase("wefwew", normalFont); phrase38 = new Phrase("ewrew", normalFont); phrase39 = new Phrase("ewr5", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 59, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 136, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 196, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 266, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase37, 351, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase38, 416, 598 - i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase39, 496, 598 - i, 0); } int j = 298; if (i - 298 < 0) i = 298; else { j = i; i = 588 - i; } Phrase phrase40 = new Phrase(bundle.getString("pdf_references").toUpperCase(), normalFont); Phrase phrase41 = new Phrase(bundle.getString("pdf_delivery").toUpperCase(), normalFont); Phrase phrase42 = new Phrase(bundle.getString("pdf_payments").toUpperCase(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase40, 105, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase41, 206, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase42, 316, i, 0); Phrase phrase43 = new Phrase("opoppp", normalFont); Phrase phrase44 = new Phrase("2ws", normalFont); Phrase phrase45 = new Phrase("78900", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 59, i - 20, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 186, i - 20, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase45, 276, i - 20, 0); Phrase phrase46 = new Phrase(bundle.getString("pdf_sign_producer").toUpperCase(), normalFont); Phrase phrase47 = new Phrase(bundle.getString("pdf_sign_receiver").toUpperCase(), normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase46, 154, i - 40, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase47, 321, i - 40, 0); Phrase phrase48 = new Phrase(bundle.getString("article_imponible"), normalFont); Phrase phrase49 = new Phrase("opoppp", normalFont); Phrase phrase50 = new Phrase(bundle.getString("pdf_tax"), normalFont); Phrase phrase51 = new Phrase("78900", normalFont); Phrase phrase52 = new Phrase(bundle.getString("pdf_total_receipt"), normalFont); Phrase phrase53 = new Phrase("2ws", normalFont); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 356, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase49, 566, i, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 356, i - 25, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase51, 566, i - 25, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 356, i - 50, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase53, 566, i - 50, 0); PdfPTable table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 47, 18, 18, 17 }); PdfPCell cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 47, 18, 18, 17 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 47, 18, 18, 17 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 47, 18, 18, 17 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); document.add(table); table = new PdfPTable(1); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(3); table.addCell(cell); document.add(table); table = new PdfPTable(3); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 38, 48, 14 }); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(40); table.addCell(cell); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); table.addCell(cell); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); table.addCell(cell); document.add(table); table = new PdfPTable(1); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); cell = new PdfPCell(); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.TOP); cell.setPadding(3); table.addCell(cell); document.add(table); table = new PdfPTable(7); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(10); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(7); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 }); cell = new PdfPCell(); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.TOP); cell.setPadding(j * 8 - 2234); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(5); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 20, 20, 20, 20, 20 }); cell = new PdfPCell(); cell.setPadding(20); table.addCell(cell); table.addCell(cell); table.addCell(cell); cell.disableBorderSide(PdfPCell.BOTTOM); table.addCell(cell); table.addCell(cell); document.add(table); table = new PdfPTable(4); table.getDefaultCell().setPadding(50); table.setWidthPercentage(105); table.setWidths(new float[] { 30, 30, 20, 20 }); cell = new PdfPCell(); cell.setPadding(20); table.addCell(cell); table.addCell(cell); cell.disableBorderSide(PdfPCell.TOP); table.addCell(cell); table.addCell(cell); document.add(table); document.close(); HttpServletResponse response = (HttpServletResponse) extCtx.getResponse(); response.setContentType("application/pdf"); response.addHeader("Content-disposition", "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\""); ServletOutputStream os = response.getOutputStream(); os.write(bytesOS.toByteArray()); os.flush(); os.close(); facesContext.responseComplete(); }
From source file:itext_result.Main.java
private int developScreeningSheet() { new SwingWorker<Object, Object>() { String filename;/* ww w . j a v a2s .c om*/ @Override protected void done() { // ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. "); } public PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException { BarcodeEAN barcode = new BarcodeEAN(); barcode.setCodeType(Barcode.EAN8); barcode.setCode(code); PdfPCell cell = new PdfPCell( barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY), true); cell.setPadding(10); return cell; } class ImageContent implements PdfPTableEvent { protected com.itextpdf.text.Image content; public ImageContent(com.itextpdf.text.Image content) { this.content = content; } public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { try { PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS]; float x = widths[3][1] + 10; float y = heights[3] - 10 - content.getScaledHeight(); content.setAbsolutePosition(x, y); canvas.addImage(content); } catch (DocumentException e) { throw new ExceptionConverter(e); } } } @Override protected Object doInBackground() throws Exception { // System.err.println(" Roll No Received ....." + rollno); Document doc = new Document(); try { PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("12345" + ".pdf")); doc.open(); doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : "); doc.addSubject("Confidential Report Eyes Only"); doc.addKeywords(""); doc.addAuthor("SOS"); doc.addCreator("SOS"); // A4 = 210mm x 297mm ~ 605points x 855points doc.setPageSize(PageSize.A5); doc.setMargins(15f, 15f, 15f, 15f); ///////////////////////////////////////////////////////////// int pageno = 1; for (int i = 0; i == pageno; i++) { // doc.add(imageRight); } PdfContentByte cb = writer.getDirectContent(); //DONE BarcodeEAN codeEAN = new BarcodeEAN(); codeEAN.setCodeType(Barcode.EAN8); Barcode128 code128 = new Barcode128(); code128.setCode(String.valueOf("123456")); Barcode128 code128_jacket = new Barcode128(); code128_jacket.setCode(String.valueOf("10345")); codeEAN.setCode(String.valueOf("123456")); com.itextpdf.text.Image imageEAN = code128.createImageWithBarcode(cb, null, null); // imageEAN.scalePercent(10f); //464f, 725f // imageEAN.setAbsolutePosition(474f, 662f); int i = 1; while (i <= pageno) { doc.newPage(); // cb.addImage(imageRight); // cb.addImage(imageEAN); i++; } com.itextpdf.text.Image carcode = code128_jacket.createImageWithBarcode(cb, null, null); carcode.scaleAbsolute(100f, 35f); carcode.setAbsolutePosition(500f, 600f); writer.addDirectImageSimple(carcode); // cb.addImage(carcode); com.itextpdf.text.Image carcode2 = code128.createImageWithBarcode(cb, null, null); carcode2.scaleAbsolute(100f, 35f); carcode2.setAbsolutePosition(450f, 760f); writer.addDirectImageSimple(carcode2); // cb.addImage(carcode2); Image image1 = Image.getInstance("jklogo.gif"); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(99); table.addCell(image1); doc.add(table); table = new PdfPTable(4); table.setWidthPercentage(99); float[] columnWidths = { 6, 2 }; PdfPTable CandidateTable = new PdfPTable(columnWidths); Font f = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); Font fsmall = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK); PdfPCell rollno = new PdfPCell(new Phrase("Roll No# " + String.valueOf("123456"), fsmall)); PdfPCell cname = new PdfPCell(new Phrase("Name #" + String.valueOf("John Doe"), fsmall)); // DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); // String today = formatter.format(cInfo.getDob()); PdfPCell dob = new PdfPCell(new Phrase("DOB#" + String.valueOf("12-03-1989"), fsmall)); PdfPCell fname = new PdfPCell(new Phrase("F/H Name #" + String.valueOf("Big John"), fsmall)); PdfPCell type = new PdfPCell(new Phrase("Total Time #" + String.valueOf("350.00"), fsmall)); // String scrtoday = formatter.format(cInfo.getScreeningdate()); // System.out.println("Today : " + today); PdfPCell scrdate = new PdfPCell(new Phrase("Laps #" + String.valueOf("4"), fsmall)); PdfPCell cell = new PdfPCell(new Phrase(" ", fsmall)); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); dob.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); fname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); type.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); scrdate.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); CandidateTable.addCell(rollno); CandidateTable.addCell(cell); CandidateTable.addCell(cname); CandidateTable.addCell(cell); CandidateTable.addCell(dob); CandidateTable.addCell(cell); PdfPTable CandidateOtherTable = new PdfPTable(columnWidths); CandidateOtherTable.addCell(fname); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(scrdate); CandidateOtherTable.addCell(cell); CandidateOtherTable.addCell(type); CandidateOtherTable.addCell(cell); PdfPCell race_start_time = new PdfPCell(new Phrase("Start Time :XX-XX-XX ", fsmall)); PdfPCell race_end_time = new PdfPCell(new Phrase("End Time :XX-XX-XX", fsmall)); PdfPCell race_total_time = new PdfPCell(new Phrase("Total Time : 350.00 ", fsmall)); race_start_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_end_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); race_total_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); PdfPTable CandidateRaceDetails = new PdfPTable(columnWidths); CandidateRaceDetails.addCell(race_start_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_end_time); CandidateRaceDetails.addCell(cell); CandidateRaceDetails.addCell(race_total_time); CandidateRaceDetails.addCell(cell); PdfPTable tablewith3cells = new PdfPTable(3); //1 St Col for Roll No Name and DOB tablewith3cells.addCell(CandidateTable); //2 nd Col for Father Name sCREEning Date Gurkha tablewith3cells.addCell(CandidateOtherTable); //3rd Col for Barcode to be Printed tablewith3cells.addCell(CandidateRaceDetails); // Setting the Width here to 101 tablewith3cells.setWidthPercentage(99); doc.add(tablewith3cells); PdfPTable userArea = new PdfPTable(1); userArea.setWidthPercentage(99); userArea.addCell(" \n \n Congratulations \n \n "); doc.add(userArea); PdfPTable footerCSBC = new PdfPTable(2); footerCSBC.setWidthPercentage(99); PdfPCell height_box = new PdfPCell(new Phrase("Height \n\n\n", f)); height_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_box = new PdfPCell(new Phrase("Chest \n\n\n", f)); chest_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell chest_exp_box = new PdfPCell(new Phrase("Chest Exp \n\n\n", f)); chest_exp_box.setBorder(com.itextpdf.text.Rectangle.BOX); PdfPCell pushup_box = new PdfPCell(new Phrase("Pushup \n\n\n", f)); pushup_box.setBorder(com.itextpdf.text.Rectangle.BOX); //CSignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); // ASignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX); footerCSBC.addCell(height_box); footerCSBC.addCell(chest_box); footerCSBC.addCell(chest_exp_box); footerCSBC.addCell(pushup_box); doc.add(footerCSBC); float[] columnWidths_ForBarcode = { 6, 3 }; PdfPTable terminalinfo = new PdfPTable(columnWidths_ForBarcode); // terminalinfo.setWidthPercentage(99); String computername = InetAddress.getLocalHost().getHostName(); System.out.println(computername); PdfPCell pcname = new PdfPCell(new Phrase("\t Jacket \n\n ", f)); String UserMatchScore = "\t Barcode\n\n"; PdfPCell score = new PdfPCell(new Phrase(UserMatchScore, f)); PdfPCell barcode = new PdfPCell(carcode2); PdfPCell jacketnumber = new PdfPCell(carcode); pcname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); score.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); barcode.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); jacketnumber.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); terminalinfo.addCell(score); terminalinfo.addCell(pcname); terminalinfo.addCell(barcode); terminalinfo.addCell(jacketnumber); doc.add(terminalinfo); PdfPCell eula_notice = new PdfPCell(new Phrase(" ", f)); eula_notice.setBorder(com.itextpdf.text.Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable eula_notice_table = new PdfPTable(1); eula_notice_table.setWidthPercentage(25); eula_notice_table.addCell(eula_notice); doc.add(eula_notice_table); } catch (Exception e) { System.err.println(e.getMessage()); // ConsoleMsg(e.getMessage()); } finally { doc.close(); doc.close(); doc.close(); } //ConsoleMsg("PDF... GENERATED"); return null; // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }.execute(); return 0; }
From source file:jeanderson.br.nota.Notas.java
public boolean gerarNotas(int desconto) { PdfPTable tabela = new PdfPTable(new float[] { 0.7f, 0.18f, 0.2f }); Document doc = new Document(PageSize.A4, 72, 72, 72, 72); try {//from w w w .j a v a 2s . co m OutputStream os = new FileOutputStream("/Users/" + System.getProperty("user.name") + "/Google Drive/Notas Fiscais/PDF/" + nomeCliente + ".pdf"); PdfWriter.getInstance(doc, os); // instancio o pdf que vou gravar doc.open(); // abro o pdf // seleciono a fonte, tamanho Font f = new Font(Font.FontFamily.COURIER, 20, Font.BOLD); //crio o paragrafo. Paragraph p1 = new Paragraph("Nota Eletrnica", f); Paragraph p2 = new Paragraph("Comprador(a): " + nomeCliente + "\nEndereo: " + endereco + "\nBairro: " + bairro + " " + "Cidade: " + cidade + "\nVendedor: Jonatha Monteiro"); PdfPCell celula = new PdfPCell(p1); celula.setColspan(3); celula.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(celula); PdfPCell celula2 = new PdfPCell(p2); celula2.setColspan(3); tabela.addCell(celula2); PdfPCell nProduto = new PdfPCell(new Paragraph("Produto")); PdfPCell nValor = new PdfPCell(new Paragraph("Valor(UN)")); nProduto.setHorizontalAlignment(Element.ALIGN_CENTER); nValor.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.addCell(nProduto); tabela.addCell("Quantidade"); tabela.addCell(nValor); double valorTotal = 0; for (int i = 0; i < this.produtos.size(); i++) { tabela.addCell(produtos.get(i)); tabela.addCell(quantidades.get(i)); tabela.addCell(valor.get(i)); valorTotal += Integer.parseInt(quantidades.get(i)) * Double.parseDouble(valor.get(i)); } Paragraph p3 = null; if (desconto == 0) { p3 = new Paragraph("Data de Emisso: " + new SimpleDateFormat("dd/MM/yyyy").format(new Date())); } else { p3 = new Paragraph( "\n\nData de Emisso: " + new SimpleDateFormat("dd/MM/yyyy").format(new Date())); } PdfPCell celula3 = new PdfPCell(p3); celula3.setColspan(1); tabela.addCell(celula3); DecimalFormat df = new DecimalFormat("###,##0.00"); Paragraph p4 = new Paragraph("Valor Total: R$" + df.format(valorTotal)); PdfPCell celula4 = null; double valorDesc = 0; double valorComDesc = 0; switch (desconto) { case 0: celula4 = new PdfPCell(p4); celula4.setColspan(2); tabela.addCell(celula4); break; case 1: valorDesc = (valorTotal * 7) / 100; valorComDesc = valorTotal - valorDesc; celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal) + "\n- 7% Desconto\nValor a pagar: R$" + df.format(valorComDesc))); celula4.setColspan(2); tabela.addCell(celula4); break; case 2: valorDesc = (valorTotal * 10) / 100; valorComDesc = valorTotal - valorDesc; celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal) + "\n - 10% Desconto\nValor a pagar: R$" + df.format(valorComDesc))); celula4.setColspan(2); tabela.addCell(celula4); break; case 3: valorDesc = (valorTotal * 12) / 100; valorComDesc = valorTotal - valorDesc; celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal) + "\n- 12% Desconto\nValor a pagar: R$" + df.format(valorComDesc))); celula4.setColspan(2); tabela.addCell(celula4); break; case 4: valorDesc = (valorTotal * 15) / 100; valorComDesc = valorTotal - valorDesc; celula4 = new PdfPCell(new Paragraph("Total: R$" + df.format(valorTotal) + "\n- 15% Desconto\nValor a pagar: R$" + df.format(valorComDesc))); celula4.setColspan(2); tabela.addCell(celula4); break; } //tabela.addCell(celula4); tabela.setWidthPercentage(100.0f); doc.add(tabela); // adiciono a tabela doc.close(); os.close(); return false; } catch (FileNotFoundException ex) { Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage()); Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex); return true; } catch (DocumentException ex) { Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage()); Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex); return true; } catch (IOException ex) { Relatar.bug(Notas.class.getName(), ex.getLocalizedMessage()); Logger.getLogger(Notas.class.getName()).log(Level.SEVERE, null, ex); return true; } }
From source file:jfx_horario.jefatura.JefaturaController.java
private void crearTablaEnPDF(Document document, Font fuente) throws DocumentException { Paragraph horarioSemanal = new Paragraph("Horario Semanal:", fuente); document.add(horarioSemanal);/*from www. ja v a2s. com*/ document.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(6); table.setWidthPercentage(105); table.addCell("Tramo"); table.addCell("Lunes"); table.addCell("Martes"); table.addCell("Miercoles"); table.addCell("Jueves"); table.addCell("Viernes"); for (int fila = 0; fila < datosCol.size(); fila++) { table.addCell(datosCol.get(fila).getTramo()); table.addCell(datosCol.get(fila).getLunes()); table.addCell(datosCol.get(fila).getMartes()); table.addCell(datosCol.get(fila).getMiercoles()); table.addCell(datosCol.get(fila).getJueves()); table.addCell(datosCol.get(fila).getViernes()); } document.add(table); document.add(new Paragraph(" ")); }
From source file:jsimpresos.ConexionCorteCaja.java
public void crearPdf(int idCorte) { try {/*from w ww.j ava2s . c o m*/ String query1 = "select * from detalleabono where idcorte=?"; PreparedStatement st = this.getConexion().prepareStatement(query1); st.setInt(1, idCorte); ResultSet rs = st.executeQuery(); ArrayList<Abono> abonos = new ArrayList(); while (rs.next()) { abonos.add(new Abono(rs.getInt(1), rs.getDouble(2), rs.getString(3), rs.getString(4), rs.getString(5), rs.getInt(6))); } String query2 = "select * from transaccionesmiembro where idcorte=?"; PreparedStatement st2 = this.getConexion().prepareStatement(query2); st2.setInt(1, idCorte); ResultSet rs2 = st2.executeQuery(); ArrayList<TransaccionesMiembro> transaccionesMiembro = new ArrayList(); while (rs2.next()) { transaccionesMiembro.add(new TransaccionesMiembro(rs2.getInt(1), rs2.getString(2), rs2.getDouble(3), rs2.getString(4), rs2.getInt(5))); } String query3 = "select * from cortesdecaja where idcorte =?"; PreparedStatement st3 = this.getConexion().prepareStatement(query3); st3.setInt(1, idCorte); ResultSet rs3 = st3.executeQuery(); String fecha = ""; while (rs3.next()) { fecha = Fechas.convertirFecha(rs3.getString(2)); } ArrayList<Abono> abonosEfectivo = new ArrayList(); ArrayList<Abono> abonosTarjeta = new ArrayList(); ArrayList<TransaccionesMiembro> recargasSaldo = new ArrayList(); ArrayList<TransaccionesMiembro> transaccionesPaypal = new ArrayList(); ArrayList<TransaccionesMiembro> registrosCliente = new ArrayList(); for (int i = 0; i < abonos.size(); i++) { String tipo = abonos.get(i).getTipoPago(); switch (tipo) { case "Efectivo": abonosEfectivo.add(abonos.get(i)); break; case "Tarjeta": abonosTarjeta.add(abonos.get(i)); break; } } for (int i = 0; i < transaccionesMiembro.size(); i++) { String tipo = transaccionesMiembro.get(i).getMovimiento(); switch (tipo) { case "Recarga": recargasSaldo.add(transaccionesMiembro.get(i)); break; case "Paypal": transaccionesPaypal.add(transaccionesMiembro.get(i)); break; case "Registro": registrosCliente.add(transaccionesMiembro.get(i)); break; } } int mayorEfectivo; if (abonosEfectivo.size() >= recargasSaldo.size() && abonosEfectivo.size() >= registrosCliente.size()) { mayorEfectivo = abonosEfectivo.size(); } else { if (recargasSaldo.size() >= registrosCliente.size()) { mayorEfectivo = recargasSaldo.size(); } else { mayorEfectivo = registrosCliente.size(); } } int mayorOtros; if (abonosTarjeta.size() >= transaccionesPaypal.size()) { mayorOtros = abonosTarjeta.size(); } else { mayorOtros = transaccionesPaypal.size(); } Document documento = new Document(); FileOutputStream ficheroPdf; try { File carpeta = new File("C:\\archivosPuntoDeVenta"); if (!carpeta.exists()) { carpeta.mkdir(); } ficheroPdf = new FileOutputStream("c:/archivosPuntoDeVenta/corte.pdf"); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); documento.setMargins(0, 0, 0, 0); documento.open(); PdfPTable tabla = new PdfPTable(8); tabla.setWidths(new float[] { 20, 10, 10, 20, 10, 10, 20, 10 }); tabla.setWidthPercentage(100); PdfPCell celdaVacia = new PdfPCell(new Paragraph(" ")); celdaVacia.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda1 = new PdfPCell(new Paragraph("Corte de caja del da " + fecha, FontFactory.getFont("Arial", 12, Font.BOLD))); celda1.setColspan(3); celda1.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda1); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda2 = new PdfPCell( new Paragraph("Transacciones en efectivo: ", FontFactory.getFont("Arial", 11, Font.BOLD))); celda2.setColspan(3); celda2.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda2); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda3 = new PdfPCell( new Paragraph("Abonos en efectivo", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda3); PdfPCell celda4 = new PdfPCell(new Paragraph("Monto", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda4); tabla.addCell(celdaVacia); PdfPCell celda5 = new PdfPCell( new Paragraph("Recargas de saldo", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda5); tabla.addCell(celda4); tabla.addCell(celdaVacia); PdfPCell celda6 = new PdfPCell( new Paragraph("Registro de clientes", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda6); tabla.addCell(celda4); double totalAbonosEfectivo = 0; double totalRecargasSaldo = 0; double totalRegistrosCliente = 0; for (int i = 0; i <= mayorEfectivo; i++) { if (abonosEfectivo.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Abono a la nota " + abonosEfectivo.get(i).getId(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + abonosEfectivo.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalAbonosEfectivo += abonosEfectivo.get(i).getMonto(); } else { if (abonosEfectivo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalAbonosEfectivo, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (recargasSaldo.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Recarga al cliente " + recargasSaldo.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + recargasSaldo.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalRecargasSaldo += recargasSaldo.get(i).getMonto(); } else { if (recargasSaldo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalRecargasSaldo, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (registrosCliente.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Registro del cliente " + registrosCliente.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + registrosCliente.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalRegistrosCliente += registrosCliente.get(i).getMonto(); } else { if (recargasSaldo.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalRegistrosCliente, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } } PdfPCell celda9 = new PdfPCell(new Paragraph( "Total de pagos en efectivo: $" + (totalAbonosEfectivo + totalRecargasSaldo + totalRegistrosCliente), FontFactory.getFont("Arial", 9, Font.BOLD))); celda9.setBorder(Rectangle.NO_BORDER); celda9.setColspan(8); tabla.addCell(celda9); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda10 = new PdfPCell( new Paragraph("Otras transacciones: ", FontFactory.getFont("Arial", 11, Font.BOLD))); celda10.setColspan(3); celda10.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda10); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); PdfPCell celda11 = new PdfPCell( new Paragraph("Abonos con tarjeta", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda11); PdfPCell celda12 = new PdfPCell( new Paragraph("Monto", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda12); tabla.addCell(celdaVacia); PdfPCell celda13 = new PdfPCell( new Paragraph("Paypal", FontFactory.getFont("Arial", 10, Font.BOLD))); tabla.addCell(celda13); tabla.addCell(celda12); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); double totalAbonosTarjeta = 0; double totalPaypal = 0; for (int i = 0; i <= mayorOtros; i++) { if (abonosTarjeta.size() > i) { PdfPCell celda7 = new PdfPCell( new Paragraph("Abono a la nota " + abonosTarjeta.get(i).getId(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + abonosTarjeta.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalAbonosTarjeta += abonosTarjeta.get(i).getMonto(); } else { if (abonosTarjeta.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalAbonosTarjeta, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); if (transaccionesPaypal.size() > i) { PdfPCell celda7 = new PdfPCell(new Paragraph( "Recarga con Paypal al cliente " + transaccionesPaypal.get(i).getIdMiembro(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Paragraph("$" + transaccionesPaypal.get(i).getMonto(), FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); totalPaypal += transaccionesPaypal.get(i).getMonto(); } else { if (transaccionesPaypal.size() == i) { PdfPCell celda7 = new PdfPCell(new Paragraph("Total", FontFactory.getFont("Arial", 9))); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell( new Paragraph("$" + totalPaypal, FontFactory.getFont("Arial", 9))); tabla.addCell(celda8); } else { tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } } tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); tabla.addCell(celdaVacia); } documento.add(tabla); documento.close(); abrirPDF(); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, "Error al generar el pdf"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al guardar pdf"); } } catch (SQLException ex) { System.out.println(ex.getMessage()); JOptionPane.showMessageDialog(null, "Error al conectar a la base de datos"); } }
From source file:jsimpresos.ConexionNotas.java
public void generarPdf(int idNota, String nombre, int cuenta) { Document documento = new Document(); Nota nota = this.getNotaPorId(idNota); FileOutputStream ficheroPdf;/* ww w.j av a 2 s. co m*/ try { File carpeta = new File("C:\\archivosPuntoDeVenta"); if (!carpeta.exists()) { carpeta.mkdir(); } ficheroPdf = new FileOutputStream("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); documento.setMargins(0, 0, 0, 0); documento.open(); Image foto = Image.getInstance("c:/archivosPuntoDeVenta/logo.JPG"); foto.scaleToFit(80, 90); PdfPTable tabla = new PdfPTable(5); tabla.setWidths(new float[] { 13, 12, 25, 25, 25 }); tabla.setWidthPercentage(100); PdfPCell celda = new PdfPCell(); celda.addElement(foto); celda.setBorder(Rectangle.NO_BORDER); celda.setRowspan(6); tabla.addCell(celda); PdfPCell celda2 = new PdfPCell( new Paragraph("NOTA DE PEDIDO", FontFactory.getFont("Arial", 15, Font.BOLD))); System.out.println(nota.getUsuario()); celda2.setColspan(3); celda2.setUseAscender(true); celda2.setBorder(Rectangle.NO_BORDER); celda2.setVerticalAlignment(Element.ALIGN_MIDDLE); tabla.addCell(celda2); PdfPCell celdaFecha = new PdfPCell(new Paragraph("Fecha: " + nota.getFecha())); celdaFecha.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdaFecha); PdfPCell celda3 = new PdfPCell(new Phrase("Calle del Rayo y 2 de Abril 31a. Col. centro, Parral, Chih.", FontFactory.getFont("Arial", 7, Font.BOLD, BaseColor.RED))); celda3.setColspan(2); celda3.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda3); PdfPCell celda4 = new PdfPCell(new Phrase("Tel. 5230073 y 6271034745", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.RED))); celda4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda4); Paragraph p = new Paragraph("No. " + nota.getIdNota(), FontFactory.getFont("Arial", 13, Font.BOLD, BaseColor.RED)); PdfPCell celda5 = new PdfPCell(); celda5.setUseAscender(true); celda5.setVerticalAlignment(Element.ALIGN_MIDDLE); celda5.setHorizontalAlignment(Element.ALIGN_MIDDLE); celda5.addElement(p); tabla.addCell(celda5); PdfPCell celdanueva = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva.setBorder(Rectangle.NO_BORDER); celdanueva.setColspan(4); tabla.addCell(celdanueva); PdfPCell celdanueva1 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva1.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva1); PdfPCell celdanueva2 = new PdfPCell( new Phrase("Datos del cliente", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva2.setBorder(Rectangle.NO_BORDER); celdanueva2.setColspan(3); tabla.addCell(celdanueva2); PdfPCell celdanueva3 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva3.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva3); if (nota.getCliente() == null) { PdfPCell celda6 = new PdfPCell( new Phrase("Cliente: " + nota.getNombres() + " " + nota.getApPaterno(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda6.setBorder(Rectangle.NO_BORDER); celda6.setColspan(3); tabla.addCell(celda6); PdfPCell celdanueva4 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva4); PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio: " + nota.getDomicilio(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda7.setBorder(Rectangle.NO_BORDER); celda7.setColspan(2); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getTelefono(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda8.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda8); } else { PdfPCell celda6 = new PdfPCell(new Phrase( "Cliente: " + nota.getCliente().getNombres() + " " + nota.getCliente().getApPaterno(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda6.setBorder(Rectangle.NO_BORDER); celda6.setColspan(3); tabla.addCell(celda6); PdfPCell celdanueva4 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celdanueva4.setBorder(Rectangle.NO_BORDER); tabla.addCell(celdanueva4); PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio: " + nota.getCliente().getDomicilio(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda7.setBorder(Rectangle.NO_BORDER); celda7.setColspan(2); tabla.addCell(celda7); PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getCliente().getTelefono(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda8.setBorder(Rectangle.NO_BORDER); tabla.addCell(celda8); } PdfPTable tabla2 = new PdfPTable(4); tabla2.setWidths(new float[] { 10, 70, 15, 15 }); tabla2.setWidthPercentage(99.5f); PdfPCell celda21 = new PdfPCell( new Phrase("Cantidad", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda21); PdfPCell celda22 = new PdfPCell( new Phrase("Artculo", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda22); PdfPCell celda23 = new PdfPCell( new Phrase("Precio unitario", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda23); PdfPCell celda24 = new PdfPCell( new Phrase("Total", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda24); double total = 0; for (int i = 0; i < 6; i++) { if (i < nota.getArticulos().size()) { PdfPCell celda25 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getCantidad() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda25); PdfPCell celda26 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getServicio() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda26); PdfPCell celda27 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getPrecio() + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda27); PdfPCell celda28 = new PdfPCell(new Phrase( (nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio()) + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda28); total += nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio(); } else { PdfPCell celda29 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla2.addCell(celda29); tabla2.addCell(celda29); tabla2.addCell(celda29); tabla2.addCell(celda29); } } PdfPTable tabla3 = new PdfPTable(4); tabla3.setWidths(new float[] { 55, 25, 15, 15 }); tabla3.setWidthPercentage(99.5f); PdfPCell celda31 = new PdfPCell(new Phrase("Observaciones: " + nota.getObservaciones(), FontFactory.getFont("Arial", 9, BaseColor.BLACK))); celda31.setRowspan(4); tabla3.addCell(celda31); PdfPCell celda32 = new PdfPCell(new Phrase( "Suma recibida de abono : " + nota.getAbonos().get(nota.getAbonos().size() - 1).getMonto(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda32.setRowspan(4); tabla3.addCell(celda32); PdfPCell celda33 = new PdfPCell( new Phrase("Total", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda33); PdfPCell celda34 = new PdfPCell( new Phrase(total + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda34); PdfPCell celda35 = new PdfPCell( new Phrase("Total abonado", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda35); double totalAbonado = 0; for (int i = 0; i < nota.getAbonos().size(); i++) { totalAbonado += nota.getAbonos().get(i).getMonto(); } PdfPCell celda36 = new PdfPCell( new Phrase(totalAbonado + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda36); PdfPCell celda37 = new PdfPCell( new Phrase("Saldo actual", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda37); PdfPCell celda38 = new PdfPCell(new Phrase((total - totalAbonado) + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda38); PdfPCell celda39 = new PdfPCell( new Phrase("Fecha entrega", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda39); PdfPCell celda40 = new PdfPCell(new Phrase(nota.getFechaEntrega(), FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); tabla3.addCell(celda40); PdfPTable tabla4 = new PdfPTable(3); tabla4.setWidths(new float[] { 30, 30, 30 }); tabla4.setWidthPercentage(99.5f); PdfPCell celda41 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda41.setBorder(Rectangle.NO_BORDER); celda41.setColspan(3); tabla4.addCell(celda41); PdfPCell celda42 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda42.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda42); PdfPCell celda43 = new PdfPCell(new Phrase("Firma de conformidad del cliente: ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda43.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda43); PdfPCell celda44 = new PdfPCell( new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK))); celda44.setBorder(Rectangle.NO_BORDER); tabla4.addCell(celda44); tabla4.addCell(celda41); tabla4.addCell(celda41); tabla4.addCell(celda41); documento.add(tabla); documento.add(tabla2); documento.add(tabla3); documento.add(tabla4); documento.add(tabla); documento.add(tabla2); documento.add(tabla3); documento.add(tabla4); documento.close(); abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); } catch (FileNotFoundException ex) { // JOptionPane.showMessageDialog(null, "Error con el pdf"); // System.out.println(ex.getMessage()); cuenta++; generarPdf(idNota, "nota", cuenta); abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al guardar pdf"); System.out.println(ex.getMessage()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error con el pdf"); } }
From source file:KTCNPM.ExportFile.java
public void exportFile(ArrayList<String> list, ArrayList<String> listTAW, ArrayList<String> listTBF, ArrayList<String> listTCF, ArrayList<String> listEF, ArrayList<String> listG) throws IOException { Document document = new Document(); try {// w w w . ja v a 2s . c o m String fileSRC = "E:\\KTCNPM.pdf"; File file = new File(fileSRC); if (file.exists()) { file.delete(); } else { file.createNewFile(); } PdfWriter.getInstance(document, new FileOutputStream(fileSRC)); document.open(); Font f1 = new Font( BaseFont.createFont("/newpackage/vuArialBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); Font f2 = new Font( BaseFont.createFont("/newpackage/vuArial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); f2.setSize(9); f1.setSize(13); Paragraph paragraph2 = new Paragraph("", f2); Paragraph paragraph3 = new Paragraph(); paragraph2.setIndentationLeft(80); paragraph2.setIndentationRight(80); paragraph2.setAlignment(Element.ALIGN_LEFT); paragraph2.setSpacingAfter(15); Phrase phrase2 = new Phrase("Tn phn m?m: Tnh chi ph phn m?m"); Phrase phrase3 = new Phrase(" "); paragraph3.add(phrase3); paragraph2.add(phrase2); //Phu luc 3 Phrase phrase5 = new Phrase( "Ph lc III: Bng tnh ton im cc tc nhn (actors) tng tc, trao i thng tin"); Paragraph paragraph5 = new Paragraph("", f1); paragraph5.setIndentationLeft(80); paragraph5.setIndentationRight(80); paragraph5.setAlignment(Element.ALIGN_CENTER); paragraph5.setSpacingAfter(10); paragraph5.add(phrase5); document.add(paragraph5); document.add(paragraph2); PdfPTable table3 = new PdfPTable(5); table3.setWidthPercentage(400 / 5.23f); table3.setWidths(new int[] { 1, 5, 3, 2, 3 }); for (int i = 0; i < listTAW.size(); i++) { Paragraph p = new Paragraph(listTAW.get(i), f2); PdfPCell data = new PdfPCell(p); table3.addCell(data); } document.add(table3); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); // phu luc 4 Phrase phrase41 = new Phrase( "Ph lc IV: Bng tnh ton im cc tr?ng hp s dung (use case)"); Paragraph paragraph41 = new Paragraph("", f1); paragraph41.setIndentationLeft(80); paragraph41.setIndentationRight(80); paragraph41.setAlignment(Element.ALIGN_CENTER); paragraph41.setSpacingAfter(10); paragraph41.add(phrase41); document.add(paragraph41); document.add(paragraph2); PdfPTable table4 = new PdfPTable(4); table4.setWidthPercentage(400 / 5.23f); table4.setWidths(new int[] { 1, 3, 3, 4 }); for (int i = 0; i < listTBF.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(listTBF.get(i), f2)); table4.addCell(data); } document.add(table4); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); // phu luc 5 Phrase phrase51 = new Phrase( "Ph lc V: Bng tnh ton h s phc tp k thut - cng ngh"); Paragraph paragraph51 = new Paragraph("", f1); paragraph51.setIndentationLeft(80); paragraph51.setIndentationRight(80); paragraph51.setAlignment(Element.ALIGN_CENTER); paragraph51.setSpacingAfter(10); paragraph51.add(phrase51); document.add(paragraph51); document.add(paragraph2); PdfPTable table5 = new PdfPTable(5); table5.setWidthPercentage(400 / 5.23f); table5.setWidths(new int[] { 1, 6, 2, 2, 2 }); for (int i = 0; i < listTCF.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(listTCF.get(i), f2)); table5.addCell(data); } document.add(table5); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); //phu luc 6 Phrase phrase61 = new Phrase( "Ph lc VI: Bng tnh ton h s tc ng mi tr?ng v nhm lm vic, h s phc tp v? mi tr?ng"); Paragraph paragraph61 = new Paragraph("", f1); paragraph61.setIndentationLeft(80); paragraph61.setIndentationRight(80); paragraph61.setAlignment(Element.ALIGN_CENTER); paragraph61.setSpacingAfter(10); paragraph61.add(phrase61); document.add(paragraph61); document.add(paragraph2); PdfPTable table6 = new PdfPTable(6); table6.setWidthPercentage(400 / 5.23f); table6.setWidths(new int[] { 1, 6, 2, 2, 2, 3 }); for (int i = 0; i < listEF.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(listEF.get(i), f2)); table6.addCell(data); } document.add(table6); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); //phu luc 7 Phrase phrase7 = new Phrase("Ph lc VII: Bng tnh ton gi tr phn m?m"); Paragraph paragraph7 = new Paragraph("", f1); paragraph7.setIndentationLeft(80); paragraph7.setIndentationRight(80); paragraph7.setAlignment(Element.ALIGN_CENTER); paragraph7.setSpacingAfter(10); paragraph7.add(phrase7); document.add(paragraph7); document.add(paragraph2); PdfPTable table7 = new PdfPTable(5); table7.setWidthPercentage(400 / 5.23f); table7.setWidths(new int[] { 1, 5, 5, 4, 2 }); for (int i = 0; i < listG.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(listG.get(i), f2)); table7.addCell(data); } document.add(table7); document.add(paragraph3); document.add(paragraph3); document.add(paragraph3); // phu luc 8 Paragraph paragraph1 = new Paragraph("", f1); paragraph1.setIndentationLeft(80); paragraph1.setIndentationRight(80); paragraph1.setAlignment(Element.ALIGN_CENTER); paragraph1.setSpacingAfter(10); Phrase phrase1 = new Phrase("Ph lc VIII: Bng tng hp chi ph phn m?m"); paragraph1.add(phrase1); document.add(paragraph1); document.add(paragraph2); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(400 / 5.23f); table.setWidths(new int[] { 1, 5, 3, 4, 2 }); for (int i = 0; i < list.size(); i++) { PdfPCell data = new PdfPCell(new Paragraph(list.get(i), f2)); table.addCell(data); } document.add(table); document.close(); } catch (DocumentException | FileNotFoundException e) { } }