List of usage examples for com.itextpdf.text Document newPage
public boolean newPage()
From source file:net.vzurczak.timesheetgenerator.PdfGenerator.java
License:Apache License
/** * Adds a page for a given week.//from w w w. ja va 2 s . c o m * @param i the week number * @param doc the document to update * @param bean a generation bean (not null) * @throws DocumentException */ private void addPageForWeek(int weekNumber, Document doc, GenerationDataBean bean) throws DocumentException { doc.newPage(); final Font boldFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD); final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA); Calendar calendar = Utils.findCalendar(weekNumber); // Title Paragraph paragraph = new Paragraph("Bordereau de Dclaration des Temps", boldFont); paragraph.setAlignment(Element.ALIGN_CENTER); doc.add(paragraph); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); // Meta: week final PdfPTable metaTable = new PdfPTable(1); paragraph = new Paragraph(); paragraph.add(new Chunk("Semaine : ", boldFont)); paragraph.add(new Chunk(String.valueOf(weekNumber), normalFont)); PdfPCell c = new PdfPCell(paragraph); c.setBorder(Rectangle.NO_BORDER); metaTable.addCell(c); // Meta: date Calendar endOfWeekCalendar = ((Calendar) calendar.clone()); endOfWeekCalendar.add(Calendar.DATE, 4); String formattedDate = new SimpleDateFormat("dd/MM/yyyy").format(endOfWeekCalendar.getTime()); paragraph = new Paragraph(); paragraph.add(new Chunk("Date : ", boldFont)); paragraph.add(new Chunk(formattedDate, normalFont)); c = new PdfPCell(paragraph); c.setBorder(Rectangle.NO_BORDER); metaTable.addCell(c); doc.add(metaTable); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); // Signatures final PdfPTable signaturesTable = new PdfPTable(2); paragraph = new Paragraph(); paragraph.add(new Chunk("Nom : ", boldFont)); paragraph.add(new Chunk(bean.getName(), normalFont)); c = new PdfPCell(paragraph); c.setBorder(Rectangle.NO_BORDER); signaturesTable.addCell(c); paragraph = new Paragraph(); paragraph.add(new Chunk("Responsable : ", boldFont)); paragraph.add(new Chunk(bean.getManagerName(), normalFont)); c = new PdfPCell(paragraph); c.setBorder(Rectangle.NO_BORDER); signaturesTable.addCell(c); c = new PdfPCell(new Paragraph("Signature : ", boldFont)); c.setBorder(Rectangle.NO_BORDER); signaturesTable.addCell(c); c = new PdfPCell(new Paragraph("Signature : ", boldFont)); c.setBorder(Rectangle.NO_BORDER); signaturesTable.addCell(c); doc.add(signaturesTable); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); doc.add(new Paragraph(" ")); // Calendar final PdfPTable timeTable = new PdfPTable(7); timeTable.addCell(new PdfPCell()); for (int i = 0; i < 5; i++) { final String date = this.sdf.format(calendar.getTime()); timeTable.addCell(newCell(date, 10)); calendar.add(Calendar.DATE, 1); } timeTable.addCell(newCell("Total", 10)); timeTable.addCell(newCell("Heures Effectues", 20)); for (int i = 0; i < 5; i++) timeTable.addCell(newCell("", 20)); if (bean.getTotalHours() > 0) timeTable.addCell(newCell(bean.getTotalHours() + " h", 20)); timeTable.completeRow(); doc.add(timeTable); }
From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java
License:Apache License
/** * Export a report to a pdf file./* ww w . ja va 2s . co m*/ * * @param allMetricsMap map of all QC metrics - keys and description. * @param selectedReports the report units to be exported in PDF format. * @param preferredPDFDirectory the directory the pdf document should be exported to. * @return Path of the created PDF document if it is successfully created - otherwise return empty string. */ public static String exportReportUnitInPDFFormat(final Map<String, String> allMetricsMap, final ArrayList<ReportUnit> selectedReports, final String preferredPDFDirectory) { //Obtain current timestamp. final java.util.Date date = new java.util.Date(); final String timestampString = CREATION_DATE_TIME_FORMAT.format(date); //Replace all occurrences of special character ':' from time stamp since ':' is not allowed in filename. final String filenameTimestamp = timestampString.replace(':', '-'); //Instantiation of document object - landscape format using the rotate() method final Document document = new Document(PageSize.A4.rotate(), PDF_PAGE_MARGIN, PDF_PAGE_MARGIN, PDF_PAGE_MARGIN, PDF_PAGE_MARGIN); final String pdfFileName = preferredPDFDirectory + "\\QCReports-" + filenameTimestamp + FILE_TYPE_EXTENSION; try { //Creation of PdfWriter object // PdfWriter writer; // writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFileName)); document.open(); for (ReportUnit reportUnit : selectedReports) { //New page for each report. document.newPage(); //Creation of chapter object final Paragraph pageTitle = new Paragraph( String.format(PDF_PAGE_TITLE, reportUnit.getMsrunName(), timestampString), Constants.PDF_TITLE_FONT); pageTitle.setAlignment(Element.ALIGN_CENTER); final Chapter chapter1 = new Chapter(pageTitle, 1); chapter1.setNumberDepth(0); //Creation of TIC graph section object final String graphTitle = String.format(TIC_GRAPH_SECTION_TITLE, reportUnit.getMsrunName()); final Paragraph ticGraphSection = new Paragraph(graphTitle, Constants.PDF_SECTION_FONT); ticGraphSection.setSpacingBefore(PDF_PARAGRAPH_SPACING); ticGraphSection.add(Chunk.NEWLINE); //Insert TIC Graph in ticGraphSection. ticGraphSection.add(createTICChartImage(reportUnit)); chapter1.addSection(ticGraphSection); final String metricsTitle = String.format(METRICS_VALUES_SECTION_TITLE, reportUnit.getMsrunName()); final Paragraph metricsValuesSection = new Paragraph(metricsTitle, Constants.PDF_SECTION_FONT); metricsValuesSection.setSpacingBefore(PDF_PARAGRAPH_SPACING); //Reference: http://www.java-connect.com/itext/add-table-in-PDF-document-using-java-iText-library.html //TODO: Insert metrics values table in metricsValuesSection metricsValuesSection.add(createMetricsValuesTable(allMetricsMap, reportUnit)); chapter1.addSection(metricsValuesSection); //Addition of a chapter to the main document document.add(chapter1); } document.close(); return pdfFileName; } catch (final DocumentException e) { // TODO Explain when these exception can occur. /* FileNotFoundException will be thrown by the FileInputStream, FileOutputStream, and * RandomAccessFile constructors when a file with the specified path name does not exist. * It will also be thrown by these constructors if the file does exist but for some reason * is inaccessible, for example when an attempt is made to open a read-only file for writing. * DocumentException Signals that an error has occurred in a Document. */ logger.log(Level.SEVERE, PDF_EXPORT_EXCEPTION_MESSAGE, e); return ""; } }
From source file:nz.ac.waikato.cms.doc.HyperLinkGrades.java
License:Open Source License
/** * Adds the index with locations to the existing PDF. * * @param locations the locations to index * @param input the input PDF// ww w. j av a 2 s .com * @param output the output PDF * @return true if successfully generated */ public static boolean addIndex(List<Location> locations, File input, File output) { try { // copy pages, add target PdfReader reader = new PdfReader(input.getAbsolutePath()); Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(output.getAbsolutePath())); document.open(); PdfContentByte canvas = writer.getDirectContent(); PdfImportedPage page; float height = 0; for (int i = 1; i <= reader.getNumberOfPages(); i++) { document.newPage(); page = writer.getImportedPage(reader, i); canvas.addTemplate(page, 1f, 0, 0, 1, 0, 0); Chunk loc = new Chunk(" "); loc.setLocalDestination("loc" + i); height = page.getHeight(); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(loc), 50, height - 50, 0); } // add index for (int i = 0; i < locations.size(); i++) { Location loc = locations.get(i); if (i % MAX_ITEMS_PER_PAGE == 0) document.newPage(); String text = loc.getID() + " " + (loc.getName() == null ? "???" : loc.getName()); Chunk chunk = new Chunk("Page " + (loc.getPage() + 1) + ": " + text); chunk.setAction(PdfAction.gotoLocalPage("loc" + (loc.getPage() + 1), false)); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(chunk), 50, height - 100 - (i % MAX_ITEMS_PER_PAGE) * 20, 0); } document.close(); return true; } catch (Exception e) { System.err.println("Failed to overlay locations!"); e.printStackTrace(); return false; } }
From source file:nz.ac.waikato.cms.doc.OverlayFilename.java
License:Open Source License
/** * Performs the overlay./*from w w w. j av a 2 s.com*/ * * @param input the input file/dir * @param output the output file/dir * @param vpos the vertical position * @param hpos the horizontal position * @param stripPath whether to strip the path * @param stripExt whether to strip the extension * @param pages the array of pages (1-based) to add the overlay to, null for all * @param evenPages whether to enforce even pages in the document * @return true if successfully overlay */ public boolean overlay(File input, File output, int vpos, int hpos, boolean stripPath, boolean stripExt, int[] pages, boolean evenPages) { PdfReader reader; PdfStamper stamper; FileOutputStream fos; PdfContentByte canvas; int i; String text; int numPages; File tmpFile; Document document; PdfWriter writer; PdfImportedPage page; PdfContentByte cb; reader = null; stamper = null; fos = null; numPages = -1; try { reader = new PdfReader(input.getAbsolutePath()); fos = new FileOutputStream(output.getAbsolutePath()); stamper = new PdfStamper(reader, fos); numPages = reader.getNumberOfPages(); if (pages == null) { pages = new int[reader.getNumberOfPages()]; for (i = 0; i < pages.length; i++) pages[i] = i + 1; } if (stripPath) text = input.getName(); else text = input.getAbsolutePath(); if (stripExt) text = text.replaceFirst("\\.[pP][dD][fF]$", ""); for (i = 0; i < pages.length; i++) { canvas = stamper.getOverContent(pages[i]); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Paragraph(text), hpos, vpos, 0.0f); } } catch (Exception e) { System.err.println("Failed to process " + input + ":"); e.printStackTrace(); return false; } finally { try { if (stamper != null) stamper.close(); } catch (Exception e) { // ignored } try { if (reader != null) reader.close(); } catch (Exception e) { // ignored } try { if (fos != null) { fos.flush(); fos.close(); } } catch (Exception e) { // ignored } } // enforce even pages? if (evenPages && (numPages > 0) && (numPages % 2 == 1)) { reader = null; fos = null; writer = null; tmpFile = new File(output.getAbsolutePath() + "tmp"); try { if (!output.renameTo(tmpFile)) { System.err.println("Failed to rename '" + output + "' to '" + tmpFile + "'!"); return false; } reader = new PdfReader(tmpFile.getAbsolutePath()); document = new Document(reader.getPageSize(1)); fos = new FileOutputStream(output.getAbsoluteFile()); writer = PdfWriter.getInstance(document, fos); document.open(); document.addCreationDate(); document.addAuthor(System.getProperty("user.name")); cb = writer.getDirectContent(); for (i = 0; i < reader.getNumberOfPages(); i++) { page = writer.getImportedPage(reader, i + 1); document.newPage(); cb.addTemplate(page, 0, 0); } document.newPage(); document.add(new Paragraph(" ")); // fake content document.close(); } catch (Exception e) { System.err.println("Failed to process " + tmpFile + ":"); e.printStackTrace(); return false; } finally { try { if (fos != null) { fos.flush(); fos.close(); } } catch (Exception e) { // ignored } try { if (reader != null) reader.close(); } catch (Exception e) { // ignored } try { if (writer != null) writer.close(); } catch (Exception e) { // ignored } if (tmpFile.exists()) { try { tmpFile.delete(); } catch (Exception e) { // ignored } } } } return true; }
From source file:omr.score.ui.SheetPdfOutput.java
License:Open Source License
public void write() throws Exception { FileOutputStream fos = new FileOutputStream(file); Document document = null; PdfWriter writer = null;//from w w w . jav a2 s.c o m try { for (TreeNode pn : score.getPages()) { Page page = (Page) pn; Dimension dim = page.getDimension(); if (document == null) { document = new Document(new Rectangle(dim.width, dim.height)); writer = PdfWriter.getInstance(document, fos); document.open(); } else { document.setPageSize(new Rectangle(dim.width, dim.height)); document.newPage(); } PdfContentByte cb = writer.getDirectContent(); Graphics2D g2 = cb.createGraphics(dim.width, dim.height); g2.scale(1, 1); // Painting PagePhysicalPainter painter = new PagePhysicalPainter(g2, Color.BLACK, // Foreground color false, // No voice painting true, // Paint staff lines false); // No annotations page.accept(painter); // This is the end... g2.dispose(); } } catch (Exception ex) { logger.warn("Error printing " + score.getRadix(), ex); throw ex; } finally { if (document != null) { document.close(); } } fos.close(); }
From source file:org.alex73.skarynka.scan.process.pdf.PdfCreator.java
License:Open Source License
public static void create(File outFile, File[] jpegs) throws Exception { Document pdf = new Document(); pdf.setMargins(0, 0, 0, 0);/*from w w w.ja va2 s . com*/ Image image0 = Jpeg.getInstance(jpegs[0].getPath()); pdf.setPageSize(new Rectangle(0, 0, image0.getScaledWidth(), image0.getScaledHeight())); PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(outFile)); pdf.open(); float minWidth = Float.MAX_VALUE, maxWidth = Float.MIN_VALUE, minHeight = Float.MAX_VALUE, maxHeight = Float.MIN_VALUE; for (File jpeg : jpegs) { Image image = Jpeg.getInstance(jpeg.getPath()); float width, height; width = image.getScaledWidth(); height = image.getScaledHeight(); minWidth = Math.min(minWidth, width); maxWidth = Math.max(maxWidth, width); minHeight = Math.min(minHeight, height); maxHeight = Math.max(maxHeight, height); pdf.setPageSize(new Rectangle(0, 0, width, height)); pdf.newPage(); pdf.add(image); } pdf.close(); writer.flush(); writer.close(); }
From source file:org.apli.jbs.utilidades.DocsPDFJB.java
public String creaContratoPaquete(String sNombrePac, String sTutor, int nFolioPaquete, float nAnticipo, float nPrecioCesaria, float nBloqueo, String sNombrePaq, String sTipoHab, int nTipoPaquete, List<DetallePaquete> carritoServicios) throws FileNotFoundException, Exception { String nombrePDF = ""; if (sNombrePac.equals("") || nFolioPaquete == 0) { throw new Exception("Funcion.creaContratoIngresHosp: error de programacin, faltan datos"); } else {//from ww w.ja v a2s. co m nombrePDF = "docs/contratosCreadosPac/ContratoPaquete-" + nFolioPaquete + ".pdf"; ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); File folder = new File(extCont.getRealPath("/resources/")); String urlImg = extCont.getRealPath("/utilidades/"); try { //urlImg = urlImg.replace("/utilidades", "/"); urlImg = urlImg.replace("\\utilidades", "\\"); System.out.println(urlImg); Document document = new Document(PageSize.LETTER, 70, 70, 30, 30); PdfWriter.getInstance(document, new FileOutputStream( new File(folder, "docs/contratosCreadosPac/ContratoPaquete-" + nFolioPaquete + ".pdf"))); document.open(); Phrase phrase = new Phrase(90); HTMLWorker htmlWorker = new HTMLWorker(document); String str = "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo() + "' width=\"400\" height=\"119\"></p>\n" + "<div style=\" line-height:90%;font-size:10.0pt;\">\n"; File myhtml = new File(folder, "docs/contratos/ContratoPaqueteEmbarazo.html"); switch (nTipoPaquete) { case TipoPaquete.MATERNIDAD: myhtml = new File(folder, "docs/contratos/ContratoPaqueteEmbarazo.html"); break; case TipoPaquete.PEDIATRICO: myhtml = new File(folder, "docs/contratos/ContratoPaquetePediatrico.html"); break; case TipoPaquete.QUIRURGICO: myhtml = new File(folder, "docs/contratos/ContratoPaqueteOtros.html"); break; default: myhtml = new File(folder, "docs/contratos/ContratoPaqueteOtros.html"); break; } FileInputStream fileinput = null; BufferedInputStream mybuffer = null; DataInputStream datainput = null; fileinput = new FileInputStream(myhtml); mybuffer = new BufferedInputStream(fileinput); datainput = new DataInputStream(mybuffer); Calendar c1 = GregorianCalendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy"); List<String> meses = new ArrayList<String>(); meses.add("ENERO"); meses.add("FEBRERO"); meses.add("MARZO"); meses.add("ABRIL"); meses.add("MAYO"); meses.add("JUNIO"); meses.add("JULIO"); meses.add("AGOSTO"); meses.add("SEPTIEMBRE"); meses.add("OCTUBRE"); meses.add("NOVIEMBRE"); meses.add("DICIEMBRE"); String sTablaServicios = "<ul>\n"; for (int i = 0; i < carritoServicios.size(); i++) { sTablaServicios += "<li>"; sTablaServicios += (i + 1) + ".- " + carritoServicios.get(i).getConceptoIngreso().getDescripcion(); sTablaServicios += "</li>\n"; } sTablaServicios += "\n</ul>"; System.out.println("servicios " + sTablaServicios); int i = 0; while (datainput.available() != 0) { i++; String linea = datainput.readLine(); if (linea.indexOf("NOMBREPAC") > 0) { linea = linea.replace("NOMBREPAC", sNombrePac); } if (linea.indexOf("NOMBRETUTOR") > 0) { linea = linea.replace("NOMBRETUTOR", sTutor); } if (linea.indexOf("ANNTTICCIPPO") > 0) { linea = linea.replace("ANNTTICCIPPO", "" + nAnticipo); } if (linea.indexOf("PRECIOCESAREA") > 0) { linea = linea.replace("PRECIOCESAREA", "" + nPrecioCesaria); } if (linea.indexOf("FECHA-DIA") > 0) { linea = linea.replace("FECHA-DIA", "" + c1.get(Calendar.DAY_OF_MONTH)); } if (linea.indexOf("FECHA-MES") > 0) { linea = linea.replace("FECHA-MES", "" + meses.get(c1.get(Calendar.MONTH))); } if (linea.indexOf("FECHA-ANIO") > 0) { linea = linea.replace("FECHA-ANIO", "" + c1.get(Calendar.YEAR)); } if (linea.indexOf("NOMBREPAQUETE") > 0) { linea = linea.replace("NOMBREPAQUETE", sNombrePaq); } //agregar linea en el html if (linea.indexOf("LISTASERVICIOSPAQUETE") > 0) { linea = linea.replace("LISTASERVICIOSPAQUETE", sTablaServicios); } str += linea + " "; } str += "</div>"; htmlWorker.parse(new StringReader(str)); if (nTipoPaquete == TipoPaquete.MATERNIDAD) { document.newPage(); str = ""; str += "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo() + "' width=\"400\" height=\"119\"></p>\n" + "<div style=\" line-height:110%;font-size:9.0pt;\">\n"; File myhtml2 = new File(folder, "docs/contratos/InfoPaqMat.html"); FileInputStream fileinput2 = null; BufferedInputStream mybuffer2 = null; DataInputStream datainput2 = null; fileinput2 = new FileInputStream(myhtml2); mybuffer2 = new BufferedInputStream(fileinput2); datainput2 = new DataInputStream(mybuffer2); while (datainput2.available() != 0) { String linea = datainput2.readLine(); if (linea.indexOf("NOMBREPAC") > 0) { linea = linea.replace("NOMBREPAC", sNombrePac); } if (linea.indexOf("ANNTTICCIPPO") > 0) { linea = linea.replace("ANNTTICCIPPO", "" + nAnticipo); } if (linea.indexOf("FECHACOMPLETA") > 0) { linea = linea.replace("FECHACOMPLETA", "" + sdf.format(new Date())); } if (linea.indexOf("NOMBREPAQUETE") > 0) { linea = linea.replace("NOMBREPAQUETE", sNombrePaq); } if (linea.indexOf("TTIIPPOOHHAABB") > 0) { linea = linea.replace("TTIIPPOOHHAABB", "" + sTipoHab); } if (linea.contains("BBLLOOQQUUEEOO")) { linea = linea.replace("BBLLOOQQUUEEOO", "" + nBloqueo); } str += linea + " "; } str += "</div>"; htmlWorker.parse(new StringReader(str)); } document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } return nombrePDF; }
From source file:org.apli.jbs.utilidades.DocsPDFJB.java
public String creaSolicitudInterconsulta(List<ConceptoIngreso> servicios, int epi, String pac, int hab, String tratante, String capturista) throws FileNotFoundException, Exception { String nombrePDF = ""; if (servicios.isEmpty() || epi == 0 || pac.equals("") || tratante.equals("") || capturista.equals("")) { throw new Exception("Funcion.creaSolicitudInterconsulta: error de programacin, faltan datos"); } else {//from ww w. j a v a 2 s . c o m nombrePDF = "docs/contratosCreadosPac/solicitudInterconsulta-" + epi + ".pdf"; ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); File folder = new File(extCont.getRealPath("//resources//")); String urlImg = extCont.getRealPath("//utilidades//"); try { urlImg = urlImg.replace("\\utilidades", "\\"); Document document = new Document(PageSize.LETTER, 70, 70, 25, 25); PdfWriter.getInstance(document, new FileOutputStream( new File(folder, "docs/contratosCreadosPac/solicitudInterconsulta-" + epi + ".pdf"))); document.open(); Phrase phrase = new Phrase(60); HTMLWorker htmlWorker = new HTMLWorker(document); for (int j = 0; j < servicios.size(); j++) { String str = "<body>"; File myhtml = new File(folder, "docs/contratos/solicitudInterconsulta.html"); FileInputStream fileinput = null; BufferedInputStream mybuffer = null; DataInputStream datainput = null; fileinput = new FileInputStream(myhtml); mybuffer = new BufferedInputStream(fileinput); datainput = new DataInputStream(mybuffer); SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy"); SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss"); int i = 0; while (datainput.available() != 0) { i++; String linea = datainput.readLine(); if (linea.indexOf("IMAGEN") > 0) { linea = linea.replace("IMAGEN", urlImg + new PlantillaJB().getLogo()); } if (linea.indexOf("NOMBREPAC") > 0) { linea = linea.replace("NOMBREPAC", pac); } if (linea.indexOf("NOHAB") > 0) { linea = linea.replace("NOHAB", ("" + ((hab == 0) ? "Consulta Externa" : hab))); } if (linea.indexOf("FECHACOMPLETA") > 0) { linea = linea.replace("FECHACOMPLETA", sdf.format(servicios.get(j).getConServ().getFechaInterconsulta())); } if (linea.indexOf("FECHAHORA") > 0) { linea = linea.replace("FECHAHORA", sdf2.format(servicios.get(j).getConServ().getFechaInterconsulta())); } if (linea.indexOf("FOLIOSERV") > 0) { linea = linea.replace("FOLIOSERV", servicios.get(j).getConServ().getFolioServ()); } if (linea.indexOf("NOMBREMEDINTE") > 0) { linea = linea.replace("NOMBREMEDINTE", "" + servicios.get(j).getConServ().getMedicoHonorarios().getNombreCompleto()); } if (linea.indexOf("NOMBRECONC") > 0) { linea = linea.replace("NOMBRECONC", servicios.get(j).getDescripcion()); } if (linea.indexOf("NOMBREMEDTRA") > 0) { linea = linea.replace("NOMBREMEDTRA", "" + tratante); } if (linea.indexOf("NOMBRECAP") > 0) { linea = linea.replace("NOMBRECAP", "" + capturista); } str += linea + " "; } str += "</body>"; String str2 = str; str2 += "<br><br><br>"; str2 += str; htmlWorker.parse(new StringReader(str2)); if ((servicios.size() - 1) != i) { document.newPage(); } } document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } return nombrePDF; }
From source file:org.apli.jbs.utilidades.DocsPDFJB.java
public String creaComprobanteProceQuirurgico(List<ServicioPrestado> servicios, int epi, String pac, int hab, String tratante) throws FileNotFoundException, Exception { String nombrePDF = ""; if (servicios.isEmpty() || epi == 0 || pac.equals("") || hab == 0 || tratante.equals("")) { throw new Exception("Funcion.creaSolicitudInterconsulta: error de programacin, faltan datos"); } else {/* w ww. j av a 2 s .c o m*/ nombrePDF = "docs/contratosCreadosPac/comprobanteProceQuirurgico-" + epi + ".pdf"; ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); File folder = new File(extCont.getRealPath("//resources//")); String urlImg = extCont.getRealPath("//utilidades//"); try { urlImg = urlImg.replace("\\utilidades", "\\"); Document document = new Document(PageSize.LETTER, 70, 70, 25, 25); PdfWriter.getInstance(document, new FileOutputStream( new File(folder, "docs/contratosCreadosPac/comprobanteProceQuirurgico-" + epi + ".pdf"))); document.open(); Phrase phrase = new Phrase(60); HTMLWorker htmlWorker = new HTMLWorker(document); for (int j = 0; j < servicios.size(); j++) { String str = "<body>"; File myhtml = new File(folder, "docs/contratos/comprobanteProceQuirurgico.html"); FileInputStream fileinput = null; BufferedInputStream mybuffer = null; DataInputStream datainput = null; fileinput = new FileInputStream(myhtml); mybuffer = new BufferedInputStream(fileinput); datainput = new DataInputStream(mybuffer); SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy h:mm:ss"); SimpleDateFormat sdf2 = new SimpleDateFormat("h:mm:ss"); int i = 0; long tiempoInicial = servicios.get(j).getServProcQx().getProcedimientoRealizado().getIni() .getTime(); long tiempoFinal = servicios.get(j).getServProcQx().getProcedimientoRealizado().getFin() .getTime(); long resta = tiempoFinal - tiempoInicial; while (datainput.available() != 0) { i++; String linea = datainput.readLine(); if (linea.indexOf("IMAGEN") > 0) { linea = linea.replace("IMAGEN", urlImg + new PlantillaJB().getLogo()); } if (linea.indexOf("NOMBREPAC") > 0) { linea = linea.replace("NOMBREPAC", pac); } if (linea.indexOf("NOHAB") > 0) { linea = linea.replace("NOHAB", "" + hab); } if (linea.indexOf("FECHAINICIO") > 0) { linea = linea.replace("FECHAINICIO", sdf .format(servicios.get(j).getServProcQx().getProcedimientoRealizado().getIni())); } if (linea.indexOf("FECHAFIN") > 0) { linea = linea.replace("FECHAFIN", sdf .format(servicios.get(j).getServProcQx().getProcedimientoRealizado().getFin())); } if (linea.indexOf("FOLIOSERV") > 0) { linea = linea.replace("FOLIOSERV", servicios.get(j).getIdFolio()); } if (linea.indexOf("PPRROOCCEE") > 0) { linea = linea.replace("PPRROOCCEE", servicios.get(j).getServProcQx() .getProcedimientoRealizado().getTipoProcQx().getDescripcion()); } if (linea.indexOf("DDUURRAACCIIOONN") > 0) { linea = linea.replace("DDUURRAACCIIOONN", "" + sdf2.format(new Date(resta))); } if (linea.indexOf("MEDENF") > 0) { linea = linea.replace("MEDENF", "" + servicios.get(j).getMedico().getNombreCompleto()); } if (linea.indexOf("NOMBREMEDTRA") > 0) { linea = linea.replace("NOMBREMEDTRA", "" + tratante); } if (linea.indexOf("RROOLLF") > 0) { linea = linea.replace("RROOLLF", "" + servicios.get(j).getServProcQx().getDescripRol()); } str += linea + " "; } str += "</body>"; String str2 = str; str2 += "<br><br><br>"; str2 += str; htmlWorker.parse(new StringReader(str2)); if ((servicios.size() - 1) != i) { document.newPage(); } } document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } return nombrePDF; }
From source file:org.apli.jbs.utilidades.DocsPDFJB.java
public String creaEncuestaHospitalYCheckList(int nEpi, String sNombrePac, boolean encuesta, boolean checklist, int nHab, Date dFechaIngreso, Date dFechaEgreso) throws FileNotFoundException, Exception { String nombrePDF = ""; if (sNombrePac.equals("") || nEpi == 0) { throw new Exception("Funcion.creaContratoIngresHosp: error de programacin, faltan datos"); } else {//from w w w. j a v a 2 s . c o m if (encuesta || checklist) { nombrePDF = "docs/contratosCreadosPac/encuestaHospitalYCheckList-" + nEpi + ".pdf"; ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext(); File folder = new File(extCont.getRealPath("//resources//")); String urlImg = extCont.getRealPath("//utilidades//"); try { urlImg = urlImg.replace("\\utilidades", "\\"); Document document = new Document(PageSize.LETTER, 70, 70, 25, 25); PdfWriter.getInstance(document, new FileOutputStream(new File(folder, "docs/contratosCreadosPac/encuestaHospitalYCheckList-" + nEpi + ".pdf"))); SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy"); HTMLWorker htmlWorker = new HTMLWorker(document); document.open(); String str = ""; if (encuesta) { str += "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo() + "' width=\"400\" height=\"119\"></p>\n" + "<div style=\" line-height:110%\">\n"; File myhtml = new File(folder, "docs/contratos/encuestaHospital.html"); FileInputStream fileinput = null; BufferedInputStream mybuffer = null; DataInputStream datainput = null; fileinput = new FileInputStream(myhtml); mybuffer = new BufferedInputStream(fileinput); datainput = new DataInputStream(mybuffer); while (datainput.available() != 0) { String linea = datainput.readLine(); if (linea.indexOf("NOMBREPAC") > 0) { linea = linea.replace("NOMBREPAC", sNombrePac); } if (linea.indexOf("FECHACOMPL") > 0) { linea = linea.replace("FECHACOMPL", sdf.format(new Date())); } str += linea + " "; } str += "</div>"; htmlWorker.parse(new StringReader(str)); if (checklist) { document.newPage(); } } if (checklist) { str = ""; str += "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo() + "' width=\"400\" height=\"119\"></p>\n" + "<div style=\" line-height:110%\">\n"; File myhtml = new File(folder, "docs/contratos/checkListExpedienteClinico.html"); FileInputStream fileinput = null; BufferedInputStream mybuffer = null; DataInputStream datainput = null; fileinput = new FileInputStream(myhtml); mybuffer = new BufferedInputStream(fileinput); datainput = new DataInputStream(mybuffer); while (datainput.available() != 0) { String linea = datainput.readLine(); if (linea.indexOf("NOMBREPAC") > 0) { linea = linea.replace("NOMBREPAC", sNombrePac); } if (linea.indexOf("NOHAB") > 0) { linea = linea.replace("NOHAB", "" + nHab); } if (linea.indexOf("FECHAINGRESO") > 0) { linea = linea.replace("FECHAINGRESO", sdf.format(dFechaIngreso)); } if (linea.indexOf("FECHAEGRESO") > 0) { linea = linea.replace("FECHAEGRESO", sdf.format(dFechaEgreso)); } str += linea + " "; } str += "</div>"; htmlWorker.parse(new StringReader(str)); } document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } } return nombrePDF; }