List of usage examples for com.itextpdf.text Paragraph setAlignment
public void setAlignment(int alignment)
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException { int numLines = 0; Paragraph p = new Paragraph(); if (sponsor.image != null) { Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image)); if (sponsor.imageWidth != 0) { image.scaleToFit(sponsor.imageWidth, 1000); } else if (sponsor.imageHeight != 0) { image.scaleToFit(1000, sponsor.imageHeight); }/*from ww w . java 2 s . c om*/ Chunk imageChunk = new Chunk(image, 0, 0, true); p.add(imageChunk); } if (sponsor.twoColumns) { StringBuilder sb = new StringBuilder(); if (sponsor.name != null) { sb.append(sponsor.name); } if (sponsor.name2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.name2); } if (sponsor.address != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address); } if (sponsor.address2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address2); } p.add(Chunk.NEWLINE); p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))); numLines++; } else { if (sponsor.twoRows && sponsor.image != null) { p.add(Chunk.NEWLINE); } if (sponsor.name != null) { p.add(generateFittedChunk(sponsor.name, Font.BOLD)); numLines++; } if (sponsor.name2 != null) { p.add(Chunk.NEWLINE); p.add(generateFittedChunk(sponsor.name2, Font.BOLD)); numLines++; } if (sponsor.address != null) { p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL))); p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } if (sponsor.address2 != null) { p.add(Chunk.NEWLINE); p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } } p.setPaddingTop(0); p.setSpacingBefore(0); p.setAlignment(Element.ALIGN_CENTER); p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setFixedHeight(cellHeight); if (sponsor.twoColumns) { cell.setColspan(2); } if (sponsor.twoRows) { cell.setRowspan(2); if (sponsor.image == null) { p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f); } } cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(CELL_EVENT); cell.setPaddingBottom(4); cell.addElement(p); if (sponsor.isTodo()) { cell.setBackgroundColor(BaseColor.ORANGE); } return cell; }
From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java
public ByteArrayOutputStream generatePDFDocumentBytes(final HttpServletRequest req, ServletContext application, boolean filterApplied, int partsOfTransactionToPrint) throws DocumentException { ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter docWriter = null;/* w w w . ja va 2s . c om*/ this.req = req; this.application = application; sContextPath = req.getContextPath(); try { docWriter = PdfWriter.getInstance(doc, baosPDF); //*** META TAGS *********************************************************************** doc.addProducer(); doc.addAuthor(user.person.firstname + " " + user.person.lastname); doc.addCreationDate(); doc.addCreator("OpenClinic Software for Hospital Management"); doc.addTitle("Medical Record Data for " + patient.firstname + " " + patient.lastname); doc.addKeywords(patient.firstname + ", " + patient.lastname); doc.setPageSize(PageSize.A4); //*** FOOTER ************************************************************************** PDFFooter footer = new PDFFooter("OpenClinic pdf engine (c)2007, Post-Factum bvba\n" + MedwanQuery.getInstance().getLabel("web.occup", "medwan.common.patientrecord", sPrintLanguage) + " " + patient.getID("immatnew") + " " + patient.firstname + " " + patient.lastname); docWriter.setPageEvent(footer); doc.open(); //*** HEADER ************************************************************************** printDocumentHeader(req); //*** TITLE *************************************************************************** String title = getTran("Web.Occup", "medwan.common.occupational-health-record").toUpperCase(); // add date restriction to document title title += "\n(" + getTran("web", "printdate") + ": " + dateFormat.format(new Date()) + ")"; /* if(dateFrom!=null && dateTo!=null){ if(dateFrom.getTime() == dateTo.getTime()){ title+= "\n("+getTran("web","on")+" "+dateFormat.format(dateTo)+")"; } else{ title+= "\n("+getTran("pdf","date.from")+" "+dateFormat.format(dateFrom)+" "+getTran("pdf","date.to")+" "+dateFormat.format(dateTo)+")"; } } else if(dateFrom!=null){ title+= "\n("+getTran("web","since")+" "+dateFormat.format(dateFrom)+")"; } else if(dateTo!=null){ title+= "\n("+getTran("pdf","date.to")+" "+dateFormat.format(dateTo)+")"; }*/ Paragraph par = new Paragraph(title, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)); par.setAlignment(Paragraph.ALIGN_CENTER); doc.add(par); //*** OTHER DOCUMENT ELEMENTS ********************************************************* printAdminHeader(patient); //printKeyData(sessionContainerWO); printMedication(sessionContainerWO); printActiveDiagnosis(sessionContainerWO); printWarnings(sessionContainerWO); doc.add(new Paragraph(" ")); //*** VACCINATION CARD **************************************************************** new be.mxs.common.util.pdf.general.oc.examinations.PDFVaccinationCard().printCard(doc, sessionContainerWO, transactionVO, patient, req, sProject, sPrintLanguage, new Integer(partsOfTransactionToPrint)); //*** TRANSACTIONS ******************************************************************** Enumeration e = req.getParameterNames(); String paramName, paramValue, sTranID, sServerID; boolean transactionIDsSpecified = false; while (e.hasMoreElements()) { paramName = (String) e.nextElement(); // transactionIDs were specified as request-parameters if (paramName.startsWith("tranAndServerID_")) { transactionIDsSpecified = true; paramValue = checkString(req.getParameter(paramName)); sTranID = paramValue.substring(0, paramValue.indexOf("_")); sServerID = paramValue.substring(paramValue.indexOf("_") + 1); this.transactionVO = MedwanQuery.getInstance().loadTransaction(Integer.parseInt(sServerID), Integer.parseInt(sTranID)); loadTransaction(transactionVO, 2); // 2 = print whole transaction } } if (!transactionIDsSpecified) { printTransactions(filterApplied, partsOfTransactionToPrint); } doc.add(new Paragraph(" ")); printSignature(); } catch (DocumentException dex) { baosPDF.reset(); throw dex; } catch (Exception e) { e.printStackTrace(); } finally { if (doc != null) doc.close(); if (docWriter != null) docWriter.close(); } if (baosPDF.size() < 1) { throw new DocumentException("document has " + baosPDF.size() + " bytes"); } return baosPDF; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private byte[] personalize(byte[] pdf, Contact contact, Toc tableOfContents) throws IOException, DocumentException { try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { final PdfReader reader = new PdfReader(pdf); final PdfStamper stamper = new PdfStamper(reader, bos); // stamp some text on first page PdfContentByte text = stamper.getOverContent(1); text.beginText();/* w ww. j a v a 2s. c om*/ text.setColorFill(iTextUtil.getFontCoverText().getColor()); text.setFontAndSize(iTextUtil.getFontCoverText().getBaseFont(), iTextUtil.getFontCoverText().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle1, text.getPdfDocument().getPageSize().getWidth() - 15, 195, 0); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle2, text.getPdfDocument().getPageSize().getWidth() - 15, 175, 0); text.showTextAligned(Element.ALIGN_RIGHT, contact.getCurrency().getTitlePageDescription(), text.getPdfDocument().getPageSize().getWidth() - 15, 80, 0); text.setColorFill(iTextUtil.getFontCoverPricingguide().getColor()); text.setFontAndSize(iTextUtil.getFontCoverPricingguide().getBaseFont(), iTextUtil.getFontCoverPricingguide().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle3, text.getPdfDocument().getPageSize().getWidth() - 15, 145, 0); text.setColorFill(iTextUtil.getFontCoverYear().getColor()); text.setFontAndSize(iTextUtil.getFontCoverYear().getBaseFont(), iTextUtil.getFontCoverYear().getSize()); text.showTextAligned(Element.ALIGN_RIGHT, coverTitle4, text.getPdfDocument().getPageSize().getWidth() - 15, 105, 0); text.endText(); // stamp some text on first page of the table of contents page final Image logoImage = iTextUtil.getImageFromByteArray(HttpUtil.readByteArray( pdfTemplate.getLogo().getUrl(), defaultService.getUserName(), defaultService.getPassword())); final PdfContentByte tocContent = stamper.getOverContent(tableOfContents.getFirstPageOfToc()); final float resizeRatio = logoImage.getHeight() / 85; // define the desired height of the log tocContent.addImage(logoImage, logoImage.getWidth() / resizeRatio, 0, 0, logoImage.getHeight() / resizeRatio, 59, 615); text = stamper.getOverContent(tableOfContents.getFirstPageOfToc()); text.beginText(); text.setColorFill(iTextUtil.getFontPersonalization().getColor()); text.setFontAndSize(iTextUtil.getFontPersonalization().getBaseFont(), iTextUtil.getFontPersonalization().getSize()); text.showTextAligned(Element.ALIGN_LEFT, "Prepared for:", 355, 681, 0); text.showTextAligned(Element.ALIGN_LEFT, contact.getFullName(), 355, 662, 0); // set company name if (!StringUtils.isEmpty(contact.getCompany())) { text.showTextAligned(Element.ALIGN_LEFT, contact.getCompany(), 355, 643, 0); text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355, 624, 0); } else { text.showTextAligned(Element.ALIGN_LEFT, new SimpleDateFormat("MM-dd-yyyy").format(new Date()), 355, 643, 0); } text.endText(); final ColumnText ct = new ColumnText(tocContent); ct.setSimpleColumn(new Rectangle(55, 517, iTextUtil.PAGE_SIZE.getWidth() - 45, 575)); final List<Element> elements = HTMLWorker.parseToList(new StringReader(disclaimer), null); final Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); for (Element element : elements) { for (Chunk chunk : element.getChunks()) { chunk.setFont(iTextUtil.getFontDisclaimer()); } p.add(element); } ct.addElement(p); ct.go(); stamper.close(); reader.close(); return bos.toByteArray(); } }
From source file:be.zenodotus.creatie.GeneratePDF.java
License:Open Source License
public String vakantieAfdruk(Context context, String name, int jaar) { this.context = context; PdfWriter w = null;/*w ww .j a v a 2 s . c o m*/ Document d = new Document(PageSize.A4.rotate(), 5, 5, 10, 10); d.setPageCount(3); String fileName = name; String file = name; GregorianCalendar datum = new GregorianCalendar(); datum.set(GregorianCalendar.YEAR, jaar); String[] maanden = { "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December" }; int[] dagen = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; VerlofDao dao = new VerlofDao(context); FeestdagDao feestdagDao = new FeestdagDao(context); WerkdagDao werkdagDao = new WerkdagDao(context); File folder = new File(context.getFilesDir(), "pdfs"); folder.mkdirs(); if (datum.isLeapYear(jaar)) { dagen[1] = 29; } File temp = null; temp = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Jacqueline" + jaar + ".pdf"); fileName = temp.toString(); try { dao.open(); ArrayList<Verlof> verloflijst = dao.getAlleVerlovenPerJaar(jaar); w = PdfWriter.getInstance(d, new FileOutputStream(temp)); d.open(); d.addAuthor("Jacqueline Vandenbroecke"); d.addCreationDate(); d.addCreator("Verlofplanner"); d.addTitle("Vakantie " + jaar + " van Jacqueline Vandenbroecke"); Font standaard = FontFactory.getFont(FontFactory.HELVETICA, 8); Font standaardBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD); Paragraph gegeven = new Paragraph("Jacqueline Vandenbroecke Verlof " + jaar + "\n", standaardBold); gegeven.setAlignment(Paragraph.ALIGN_CENTER); d.add(gegeven); for (int paginas = 0; paginas < 2; paginas++) { int aantal = 0; if (paginas == 1) { d.newPage(); aantal = 6; } PdfPTable table = new PdfPTable(6); for (int i = aantal; i < (aantal + 6); i++) { PdfPCell cell = new PdfPCell(new Paragraph(maanden[i], standaardBold)); cell.setBorder(1); table.addCell(cell); } int dag = 1; int k = aantal; for (int i = aantal; i < (aantal + 6); i++) { for (int j = 0; j < 32; j++) { if (k > ((aantal + 6) - 1)) { k = aantal; dag++; } if (dag > dagen[k]) { PdfPCell cell = new PdfPCell(new Paragraph("", standaard)); table.addCell(cell); k++; } else { SimpleDateFormat formatterDag = new SimpleDateFormat("dd"); SimpleDateFormat formatterWeek = new SimpleDateFormat("EEE"); datum.set(jaar, k, dag); PdfPTable dagTabel = new PdfPTable(4); PdfPCell cellDag = new PdfPCell( new Paragraph(formatterDag.format(datum.getTime()), standaard)); PdfPCell cellWeek = new PdfPCell( new Paragraph(formatterWeek.format(datum.getTime()), standaard)); ArrayList<Verlof> verlof = new ArrayList<Verlof>(); for (int z = 0; z < verloflijst.size(); z++) { if (((verloflijst.get(z).getDag() + 1) == dag) && (verloflijst.get(z).getMaand() == k)) { verlof.add(verloflijst.get(z)); } } feestdagDao.open(); Feestdag feestdag = feestdagDao.getFeestdag(jaar, datum.get(GregorianCalendar.MONTH), datum.get(GregorianCalendar.DATE)); feestdagDao.close(); werkdagDao.open(); java.util.List<Werkdag> weekend = werkdagDao.getWeekend(); werkdagDao.close(); String Verlof = ""; String uur = ""; if (verlof.size() > 0) { if (verlof.size() > 1) { Verlof = verlof.get(0).getVerlofsoort() + "\n" + verlof.get(1).getVerlofsoort(); uur = verlof.get(0).getUrental() + "\n" + verlof.get(1).getUrental(); } else { Verlof = verlof.get(0).getVerlofsoort(); uur = verlof.get(0).getUrental(); } } PdfPCell cellVerlof = new PdfPCell(new Paragraph(Verlof, standaard)); PdfPCell uren = new PdfPCell(new Paragraph(uur, standaard)); if (verlof.size() > 0) { BaseColor kleur = new BaseColor(Color.GRAY); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } for (int z = 0; z < weekend.size(); z++) { if ((formatterWeek.format(datum.getTime())).equals(weekend.get(z).getDag())) { BaseColor kleur = new BaseColor(Color.LTGRAY); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } } if (feestdag != null) { BaseColor kleur = new BaseColor(Color.GREEN); uren.setBackgroundColor(kleur); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } dagTabel.addCell(cellDag); dagTabel.addCell(cellWeek); dagTabel.addCell(cellVerlof); dagTabel.addCell(uren); table.addCell(dagTabel); k++; } } } d.add(table); dao.close(); } } catch (Exception ex) { ex.printStackTrace(); } finally { d.close(); w.close(); } return fileName; }
From source file:Beans.ArchAssistantBean.java
public void GenerarReporteQAW(Proyecto pro) throws FileNotFoundException, DocumentException, IOException { Rationaleqaw ratq, ratq4;/* w w w. ja va 2 s .c o m*/ String paso = pro.getProAvance(); Paragraph parrafo; int anexo = 1; GuardarArchivo arch = new GuardarArchivo(); List<File> archivos = null; FileOutputStream archivo = new FileOutputStream(System.getProperty("user.home") + File.separator + "Downloads" + File.separator + "InformeQAW" + pro.getProNombre() + ".pdf"); String razonamiento; Document documento = new Document(); PdfWriter.getInstance(documento, archivo); List<Atributocalidad> listaAtributos = ListarAtr(); List<Atributocalidad> atrEscogidos; documento.open(); documento.addHeader("ArchAssistant", "ArchAssistant"); //documento.setMargins(2, 2, 4, 4); parrafo = new Paragraph("INFORME QAW ", chapterFont); parrafo.setAlignment(1); documento.add(parrafo); parrafo = new Paragraph("Proyecto " + pro.getProNombre(), chapterFont); parrafo.setAlignment(1); documento.add(parrafo); parrafo = new Paragraph("ArchAssistant\n\n", blueFontArchAssistant); parrafo.setAlignment(1); documento.add(parrafo); documento.add(new Paragraph("\n\n" + pro.getProDescripcion(), paragraphFont)); parrafo = new Paragraph("Autor: " + pro.getTblUsuarioidUsuario().getUsuNombre(), blueFont); parrafo.setAlignment(2); documento.add(parrafo); for (int i = 1; i <= 8; i++) { ratq = obtenerRationaleQAW(pro.getProID(), "qaw" + String.valueOf(i)); ratq4 = obtenerRationaleQAW(pro.getProID(), "qaw4"); documento.add(new Paragraph("QAW paso " + i + "\n", categoryFont)); if (ratq != null) { archivos = arch.listarArchivos(ratq.getRatQawArchivo()); razonamiento = ratq.getRatQawDescripcion(); if (razonamiento != null) { if (ratq.getRatQawPaso().equals("qaw4")) { ratq4 = ratq; atrEscogidos = ObtenerAtributosEscogidos(ratq); documento.add(new Paragraph("Atributos de Calidad:\n", subcategoryFont)); for (Atributocalidad atr : listaAtributos) { for (Atributocalidad atrEsc : atrEscogidos) { if (atr.getAcID() == atrEsc.getAcID()) { documento.add(new Paragraph(atr.getAcNombre(), blueFont)); } } } int indiceAtribs = 0; if (razonamiento != null || razonamiento != "") { indiceAtribs = razonamiento.indexOf("~|~|") + 4; } documento.add(new Paragraph("Justificacin de las decisiones", smallBold)); documento.add(new Paragraph(razonamiento.substring(indiceAtribs) + "\n", paragraphFont)); } else { if (ratq.getRatQawPaso().equals("qaw5")) { documento.add(new Paragraph("Escenarios generados en la lluvia de ideas:\n", subcategoryFont)); atrEscogidos = ObtenerAtributosEscogidos(ratq4); for (Atributocalidad atr : atrEscogidos) { documento.add(new Paragraph("\n" + atr.getAcNombre() + "\n\n", smallBold)); PdfPTable tabla = new PdfPTable(4); tabla.addCell("Nombre"); tabla.addCell("Estimulo"); tabla.addCell("Ambiente"); tabla.addCell("Respuesta"); List<Escenario> listaEsc = ListEscenarios(pro); for (Escenario esce : listaEsc) { if (esce.getTblAtributoCalidadacID().getAcID() == atr.getAcID()) { tabla.addCell(esce.getEscNombre()); tabla.addCell(esce.getEscEstimulo()); tabla.addCell(esce.getEscAmbiente()); tabla.addCell(esce.getEscRespuesta()); } } documento.add(tabla); } } if (ratq.getRatQawPaso().equals("qaw6")) { documento.add(new Paragraph("Escenarios consolodados:\n", subcategoryFont)); atrEscogidos = ObtenerAtributosEscogidos(ratq4); for (Atributocalidad atr : atrEscogidos) { documento.add(new Paragraph("\n" + atr.getAcNombre() + "\n\n", smallBold)); PdfPTable tabla = new PdfPTable(4); tabla.addCell("Nombre"); tabla.addCell("Estimulo"); tabla.addCell("Ambiente"); tabla.addCell("Respuesta"); List<Escenario> listaEsc = ListEscenarios(pro); for (Escenario esce : listaEsc) { if (esce.getTblAtributoCalidadacID().getAcID() == atr.getAcID()) { tabla.addCell(esce.getEscNombre()); tabla.addCell(esce.getEscEstimulo()); tabla.addCell(esce.getEscAmbiente()); tabla.addCell(esce.getEscRespuesta()); } } documento.add(tabla); } } if (ratq.getRatQawPaso().equals("qaw7")) { documento.add(new Paragraph("Escenarios priorizados:\n\n", subcategoryFont)); PdfPTable tabla = new PdfPTable(6); tabla.addCell("Nombre"); tabla.addCell("Estimulo"); tabla.addCell("Ambiente"); tabla.addCell("Respuesta"); tabla.addCell("Atributo"); tabla.addCell("Voto"); List<Escenario> listaEsc = ListEscenarios(pro); Collections.sort(listaEsc, new Comparator() { @Override public int compare(Object o1, Object o2) { Escenario esc1, esc2; esc1 = (Escenario) o1; esc2 = (Escenario) o2; return new Integer(esc1.getEscPrioridad()) .compareTo(new Integer(esc2.getEscPrioridad())); } }); for (Escenario esce : listaEsc) { tabla.addCell(esce.getEscNombre()); tabla.addCell(esce.getEscEstimulo()); tabla.addCell(esce.getEscAmbiente()); tabla.addCell(esce.getEscRespuesta()); tabla.addCell(esce.getTblAtributoCalidadacID().getAcNombre()); tabla.addCell(String.valueOf(esce.getEscPrioridad())); } documento.add(tabla); } if (ratq.getRatQawPaso().equals("qaw8")) { documento.add(new Paragraph("Escenarios Refinados:\n\n", subcategoryFont)); PdfPTable tabla = new PdfPTable(9); tabla.addCell("Nombre"); tabla.addCell("Estimulo"); tabla.addCell("Fuente"); tabla.addCell("Ambiente"); tabla.addCell("Artefacto"); tabla.addCell("Respuesta"); tabla.addCell("Medida"); tabla.addCell("Atributo"); tabla.addCell("Prioridad"); List<Escenario> listaEsc = ListEscenarios(pro); Collections.sort(listaEsc, new Comparator() { @Override public int compare(Object o1, Object o2) { Escenario esc1, esc2; esc1 = (Escenario) o1; esc2 = (Escenario) o2; return new Integer(esc1.getEscPrioridad()) .compareTo(new Integer(esc2.getEscPrioridad())); } }); for (Escenario esce : listaEsc) { tabla.addCell(esce.getEscNombre()); tabla.addCell(esce.getEscEstimulo()); tabla.addCell(esce.getEscFuente()); tabla.addCell(esce.getEscAmbiente()); tabla.addCell(esce.getEscArtefacto()); tabla.addCell(esce.getEscRespuesta()); tabla.addCell(esce.getEscMedidaRespuesta()); tabla.addCell(esce.getTblAtributoCalidadacID().getAcNombre()); tabla.addCell(String.valueOf(esce.getEscPrioridad())); } documento.add(tabla); } documento.add(new Paragraph("Justificacin de las decisiones", smallBold)); documento.add(new Paragraph(razonamiento + "\n", paragraphFont)); } } if (archivos != null) { documento.add(new Paragraph("Archivos anexos:\n", smallBold)); for (File archi : archivos) { documento.add(new Paragraph("Anexo" + anexo + ": " + archi.getName(), blueFont)); anexo++; } } } else { documento.add(new Paragraph("No se registr informacin para este paso\n\n", paragraphFont)); } } documento.close(); archivo.close(); }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
/** * createPdf es una funcin estatica que funciona como plantilla para generar * reportes dinamicos, segn la necesidad del usuario. * @param path La direccin del archivo donde se guardar el pdf * @param titulo El Ttulo que llevar el pdf * @param encabezado Un texto que se mostrar bajo el ttulo * @param tabla La tabla de resultados que mostrar el pdf *///w ww . j ava2 s . com static public void createPdf(String path, String titulo, String encabezado, PdfPTable tabla) { Document document = new Document(); // step 2 try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(14); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora del Reporte: " + fecha, myFontTitle); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); document.add(new Paragraph(encabezado + (tabla.getRows().size() - 1))); document.add(new Paragraph("\r\n")); document.add(tabla); // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createArrayListPdf(String path, String titulo, String encabezado, ArrayList<PdfPTable> tablas) { Document document = new Document(); ArrayList<String> NombreTablas = new DaoReportesEstadisticas().getNombreTablas(); //step 2/*from w w w . j av a 2s . c o m*/ try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); for (int i = 0; i < tablas.size(); i++) { document.add(new Paragraph(NombreTablas.get(i))); document.add(new Paragraph(encabezado + (tablas.get(i).getRows().size() - 1))); document.add(new Paragraph("\r\n")); document.add(tablas.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:biblioteca.reportes.PdfCreator.java
License:Open Source License
static public void createDinamicPdf(String path, String titulo, String encabezado, ArrayList<Element> contenido) { Document document = new Document(); //step 2//from w ww.ja v a2 s.c o m try { PdfWriter.getInstance(document, new FileOutputStream(path)); Font myFontTitle = new Font(); myFontTitle.setFamily("Arial"); myFontTitle.setStyle(Font.BOLD); myFontTitle.setSize(12); Font Univallef = new Font(); Univallef.setColor(BaseColor.RED); Univallef.setFamily("Arial"); Univallef.setSize(18); Image header = Image .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png")); header.setAlignment(Image.ALIGN_CENTER); header.scaleToFit(50, 75); Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef); Univalle.setAlignment(Paragraph.ALIGN_CENTER); Paragraph pTitulo = new Paragraph(titulo, myFontTitle); pTitulo.setAlignment(Paragraph.ALIGN_CENTER); Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle); biblioteca.setAlignment(Paragraph.ALIGN_CENTER); Paragraph developers = new Paragraph( "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle); developers.setAlignment(Paragraph.ALIGN_CENTER); Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle); //Paragraph Introduccion = new Paragraph("Reporte de usuarios registrados"); document.open(); // step 4 document.add(header); document.add(new Paragraph("\r\n")); document.add(Univalle); document.add(new Paragraph("\r\n")); document.add(pTitulo); document.add(new Paragraph("\r\n")); document.add(biblioteca); document.add(new Paragraph("\r\n")); document.add(developers); document.add(new Paragraph("\r\n")); document.add(Fecha); document.add(new Paragraph("\r\n")); // document.add(Introduccion); document.add(new Paragraph("\r\n")); for (int i = 0; i < contenido.size(); i++) { document.add(contenido.get(i).getClass().equals(new PdfPTable(2).getClass()) ? (PdfPTable) contenido.get(i) : contenido.get(i)); } // step 5 document.close(); } catch (DocumentException de) { System.err.println(de); } catch (IOException ioex) { System.err.println(ioex); } }
From source file:billerfx.FXMLBillController.java
File generatePDF() { File fi = null;/*from w ww . jav a2s. c om*/ try { Stage gg = ((Stage) imv.getParent().getScene().getWindow()); fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf"); fi.deleteOnExit(); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(fi)); Rectangle r = new RectangleReadOnly(207, 575); document.setPageSize(r); document.setMargins(15, 15, 0, 0); document.open(); Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL); Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL); String[] ll = Database.getCurrentSettings(); String ss = "-----------------------------------------------------\n"; ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n"; String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM" : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : ""); ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH)) + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at " + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE) + " " + kk + "\n"; ss += "Table No. " + c.getText() + " Bill No. " + a.getText() + "\n"; ss += "-----------------------------------------------------\n"; Paragraph para = new Paragraph(ss, fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); float[] columnWidths = { 3f, 1f }; table.setWidths(columnWidths); PdfPCell defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); ObservableList ob = map.get(Integer.parseInt(gg.getTitle())); for (int i = 0; i < ob.size(); i++) { Item2 ii = (Item2) ob.get(i); String s1 = ii.getQuantity() + " x " + ii.getName(); String s2 = "Rs. " + ii.getTotal(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(columnWidths); defaultCell = table.getDefaultCell(); defaultCell.setBorder(PdfPCell.NO_BORDER); String s1 = "Total:"; String s2 = "Rs. " + h.getText(); Paragraph para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); Paragraph para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); PdfPCell cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) { s1 = "Discount:"; s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText())); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[7].equals("1")) { s1 = ll[3]; s2 = "Rs. " + k.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } if (ll[8].equals("1")) { s1 = ll[4]; s2 = "Rs. " + l.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); } s1 = "Grand Total:"; s2 = "Rs. " + m.getText(); para1 = new Paragraph(s1, fontbold2); para1.setAlignment(Paragraph.ALIGN_LEFT); para2 = new Paragraph(s2, fontbold2); para2.setAlignment(Paragraph.ALIGN_RIGHT); cell1 = new PdfPCell(para1); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(para2); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell1); table.addCell(cell2); document.add(table); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL); para = new Paragraph( "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n", fontbold2); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); para = new Paragraph("-----------------------------------------------------\n", fontbold); para.setAlignment(Paragraph.ALIGN_CENTER); document.add(para); document.close(); } catch (Exception mm) { } return fi; }
From source file:bl.pdf.PDFFile.java
private Paragraph newLine(String txt, Font f, int alignment) { Paragraph ret; if (f != null) { ret = new Paragraph(txt, f); } else {// w w w . j av a 2 s . co m ret = new Paragraph(txt); } if (alignment != -1) { ret.setAlignment(alignment); } return ret; }