List of usage examples for com.lowagie.text Paragraph setKeepTogether
public void setKeepTogether(boolean keeptogether)
From source file:com.aryjr.nheengatu.pdf.PDFText.java
License:Open Source License
public static Paragraph createParagraph(final Text htmlText, TagsManager tm) { if (tm == null) tm = TagsManager.getInstance();/* ww w. ja v a 2 s .co m*/ final Paragraph text = new Paragraph(htmlText != null ? htmlText.getText() : null, tm.getFont()); text.setAlignment(tm.getAlign()); text.setKeepTogether(true); // float b = tm.getSpacingBefore(); // float a = tm.getSpacingAfter(); text.setSpacingBefore(tm.getSpacingBefore()); text.setSpacingAfter(tm.getSpacingAfter()); text.setFirstLineIndent(tm.getTextIndent()); text.setIndentationLeft(tm.getMarginLeft()); // text.setFirstLineIndent(20f); text.setLeading(tm.getFont().getSize() * 1.5f); return text; }
From source file:com.preparatic.archivos.PdfGenerator.java
License:Apache License
/** * Ade una pregunta al test.//from ww w . j a va2 s. c o m * * @param resultados * @throws Exception */ private void agregarPregunta(PreguntaTest pregunta, boolean isLast) { // Creamos una lista para las respuestas. listaRespuestas = new com.lowagie.text.List(true, true); listaRespuestas.add(new ListItem(pregunta.getRespuesta_a(), miFuentePregs)); listaRespuestas.add(new ListItem(pregunta.getRespuesta_b(), miFuentePregs)); listaRespuestas.add(new ListItem(pregunta.getRespuesta_c(), miFuentePregs)); listaRespuestas.add(new ListItem(pregunta.getRespuesta_d(), miFuentePregs)); // Incorporamos la lista de respuestas en un nico Prrafo Paragraph parrafoPregunta = new Paragraph(pregunta.getPregunta(), miFuentePregs); parrafoPregunta.setKeepTogether(true); parrafoPregunta.add(listaRespuestas); if (!isLast) parrafoPregunta.setSpacingAfter(distanciaInterPregunta); // Metemos la pregunta como un Li en ListaPreguntas. ListItem li = new ListItem(parrafoPregunta); li.setKeepTogether(true); listaPreguntas.add(li); String cadenaSolucion = pregunta.getRespuesta_correcta().toUpperCase(); if (pregunta.getTemas() != null) cadenaSolucion += " (T" + pregunta.getTemas() + ")"; listaSoluciones.add(new ListItem(cadenaSolucion, miFuenteSols)); }
From source file:com.preparatic.archivos.PdfGenerator.java
License:Apache License
private void agregarPregunta(ResultSet resultados) throws Exception { // Creamos una lista para las respuestas. listaRespuestas = new com.lowagie.text.List(true, true); listaRespuestas.add(new ListItem(resultados.getString("RESPUESTA_A"), miFuentePregs)); listaRespuestas.add(new ListItem(resultados.getString("RESPUESTA_B"), miFuentePregs)); listaRespuestas.add(new ListItem(resultados.getString("RESPUESTA_C"), miFuentePregs)); listaRespuestas.add(new ListItem(resultados.getString("RESPUESTA_D"), miFuentePregs)); // Incorporamos la lista de respuestas en un nico Prrafo Paragraph parrafoPregunta = new Paragraph(resultados.getString("PREGUNTA"), miFuentePregs); parrafoPregunta.setKeepTogether(true); parrafoPregunta.add(listaRespuestas); if (!resultados.isLast()) parrafoPregunta.setSpacingAfter(distanciaInterPregunta); // Metemos la pregunta como un Li en ListaPreguntas. ListItem li = new ListItem(parrafoPregunta); li.setKeepTogether(true);/*from w ww .j a va 2s . co m*/ listaPreguntas.add(li); String cadenaSolucion = resultados.getString("RESPUESTA_CORRECTA").toUpperCase(); if (resultados.getString(7) != null) cadenaSolucion += " (T" + resultados.getString("TEMAS") + ")"; listaSoluciones.add(new ListItem(cadenaSolucion, miFuenteSols)); }
From source file:datasoul.servicelist.ServiceListExporterDocument.java
License:Open Source License
private LinkedList<Paragraph> addChordsShape(ArrayList<String> chordsName) throws DocumentException { ChordsDB chordsDB = ChordsDB.getInstance(); String notCatalogued = ""; LinkedList<Chunk> images = new LinkedList<Chunk>(); LinkedList<File> filesToDelete = new LinkedList<File>(); LinkedList<Paragraph> ret = new LinkedList<Paragraph>(); for (int i = 0; i < chordsName.size(); i++) { Chord chord = chordsDB.getChordByName(chordsName.get(i)); if (chord != null) { ChordShapePanel csp = new ChordShapePanel(2, chord.getName(), chord.getShape()); BufferedImage im = csp.createImage(); try { File tmp = File.createTempFile("datasoul-img", ".png"); tmp.deleteOnExit();//www.jav a2s . co m filesToDelete.add(tmp); ImageIO.write(im, "png", tmp); Chunk c = new Chunk(Image.getInstance(tmp.getAbsolutePath()), 0, 0, false); images.add(c); } catch (IOException e) { JOptionPane.showMessageDialog(null, java.util.ResourceBundle .getBundle("datasoul/internationalize").getString("INTERNAL ERROR: ") + e.getMessage()); } } else { notCatalogued += chordsName.get(i); } } Paragraph p = new Paragraph(); if (!images.isEmpty()) { for (Chunk c : images) { p.add(c); } p.setLeading(images.getFirst().getImage().getScaledHeight()); p.setKeepTogether(true); } ret.add(p); if (!notCatalogued.equals("")) { p = new Paragraph( java.util.ResourceBundle.getBundle("datasoul/internationalize") .getString("THE FOLLOWING CHORDS ARE NOT CATALOGED: ") + notCatalogued, FontFactory.getFont(FontFactory.HELVETICA, 8)); ret.add(p); } for (File f : filesToDelete) { try { f.delete(); } catch (Exception e) { //ignore, it will be deleted on exit } } return ret; }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addProjectCCAFSOutcomes(String number) { PdfPTable table = new PdfPTable(3); Paragraph cell = new Paragraph(); Paragraph indicatorsBlock = new Paragraph(); indicatorsBlock.setAlignment(Element.ALIGN_JUSTIFIED); indicatorsBlock.setKeepTogether(true); Paragraph title = new Paragraph(number + ".2 " + this.getText("summaries.project.indicatorsContribution"), HEADING3_FONT);/*from ww w. j a v a 2s .c om*/ indicatorsBlock.add(Chunk.NEWLINE); indicatorsBlock.add(title); try { document.add(indicatorsBlock); List<IPElement> listIPElements = this.getMidOutcomesPerIndicators(); if (!listIPElements.isEmpty()) { if (project.isReporting()) { for (IPElement outcome : listIPElements) { Paragraph outcomeBlock = new Paragraph(); int indicatorIndex = 1; outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomeBlock.setFont(BODY_TEXT_BOLD_FONT); outcomeBlock.add(outcome.getProgram().getAcronym()); outcomeBlock.add(" - " + this.getText("summaries.project.midoutcome")); outcomeBlock.setFont(BODY_TEXT_FONT); outcomeBlock.add(outcome.getDescription()); outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.add(Chunk.NEWLINE); document.add(outcomeBlock); for (IPIndicator outcomeIndicator : outcome.getIndicators()) { outcomeIndicator = outcomeIndicator.getParent() != null ? outcomeIndicator.getParent() : outcomeIndicator; List<IPIndicator> indicators = project.getIndicatorsByParent(outcomeIndicator.getId()); if (indicators.isEmpty()) { continue; } Paragraph indicatorDescription = new Paragraph(); indicatorDescription.setFont(BODY_TEXT_BOLD_FONT); indicatorDescription.add(this.getText("summaries.project.indicators")); indicatorDescription.add(String.valueOf(indicatorIndex) + ": "); indicatorDescription.setFont(BODY_TEXT_FONT); indicatorDescription.setAlignment(Element.ALIGN_JUSTIFIED); indicatorDescription.add(outcomeIndicator.getDescription()); document.add(indicatorDescription); document.add(Chunk.NEWLINE); ; PdfPCell cell_new; for (IPIndicator indicator : indicators) { table = new PdfPTable(3); table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 3, 3, 3 }); table.setHeaderRows(1); if (indicator.getOutcome().getId() != outcome.getId()) { continue; } cell = new Paragraph(this.messageReturn(String.valueOf(indicator.getYear())), TABLE_HEADER_FONT); cell_new = new PdfPCell(cell); // Set alignment cell_new.setHorizontalAlignment(Element.ALIGN_CENTER); cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND); // Set padding cell_new.setUseBorderPadding(true); cell_new.setPadding(3); // Set border color cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR); cell_new.setColspan(3); this.addTableHeaderCell(table, cell_new); // Target value cell = new Paragraph(this.getText("summaries.project.indicator.targetValue"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getTarget())); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); // Cumulative target to date // TODO cell = new Paragraph(this.getText("summaries.project.indicator.cumulative"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn( project.calculateAcumulativeTarget(indicator.getYear(), indicator))); if (indicator.getYear() <= this.currentReportingYear) { this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); // achieved cell = new Paragraph(this.getText("summaries.project.indicator.archieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); if (indicator.getArchived() == null) { cell.add(this.messageReturn(null)); } else { cell.add(this.messageReturn(String.valueOf(indicator.getArchived()))); } this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } else { this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 2); } // target narrative cell = new Paragraph(this.getText("summaries.project.indicator.targetNarrative"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getDescription())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); // targets achieved if (indicator.getYear() <= this.currentReportingYear) { cell = new Paragraph( this.getText("summaries.project.indicator.targetsAchieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getNarrativeTargets())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); } // Target gender cell = new Paragraph(this.getText("summaries.project.indicator.targetGender"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getGender())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); // Target achieved gender if (indicator.getYear() <= this.currentReportingYear) { cell = new Paragraph(this.getText("summaries.project.indicator.genderAchieved"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(indicator.getNarrativeGender())); this.addTableColSpanCell(table, cell, Element.ALIGN_JUSTIFIED, 1, 3); } document.add(table); document.add(Chunk.NEWLINE); } indicatorIndex++; } } //////////// Planning } else { for (IPElement outcome : listIPElements) { Paragraph outcomeBlock = new Paragraph(); int indicatorIndex = 1; outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomeBlock.setFont(BODY_TEXT_BOLD_FONT); outcomeBlock.add(outcome.getProgram().getAcronym()); outcomeBlock.add(" - " + this.getText("summaries.project.midoutcome")); outcomeBlock.setFont(BODY_TEXT_FONT); outcomeBlock.add(outcome.getDescription()); outcomeBlock.add(Chunk.NEWLINE); outcomeBlock.add(Chunk.NEWLINE); document.add(outcomeBlock); for (IPIndicator outcomeIndicator : outcome.getIndicators()) { outcomeIndicator = outcomeIndicator.getParent() != null ? outcomeIndicator.getParent() : outcomeIndicator; List<IPIndicator> indicators = project.getIndicatorsByParent(outcomeIndicator.getId()); if (indicators.isEmpty()) { continue; } Paragraph indicatorDescription = new Paragraph(); indicatorDescription.setFont(BODY_TEXT_BOLD_FONT); indicatorDescription.add(this.getText("summaries.project.indicators")); indicatorDescription.add(String.valueOf(indicatorIndex) + ": "); indicatorDescription.setFont(BODY_TEXT_FONT); indicatorDescription.setAlignment(Element.ALIGN_JUSTIFIED); indicatorDescription.add(outcomeIndicator.getDescription()); document.add(indicatorDescription); document.add(Chunk.NEWLINE); ; table = new PdfPTable(4); table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 1, 3, 3, 3 }); table.setHeaderRows(1); // Headers cell = new Paragraph(this.getText("summaries.project.indicator.year"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetValue"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetNarrative"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.indicator.targetGender"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); for (IPIndicator indicator : indicators) { if (indicator.getOutcome().getId() != outcome.getId()) { continue; } cell = new Paragraph(this.messageReturn(String.valueOf(indicator.getYear())), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(this.messageReturn(indicator.getTarget()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(this.messageReturn(indicator.getDescription()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(this.messageReturn(indicator.getGender()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } indicatorIndex++; document.add(table); document.add(Chunk.NEWLINE); } } } // When there isn't elements in indicators } else { cell = new Paragraph(this.getText("summaries.project.empty")); document.add(cell); } } catch ( DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * Entering the project partners in the summary *///from w ww .j a v a 2 s . c om private void addProjectPartners() { Paragraph partnersBlock = new Paragraph(); partnersBlock.setAlignment(Element.ALIGN_JUSTIFIED); partnersBlock.setKeepTogether(true); Paragraph title = new Paragraph(32, "2. " + this.getText("summaries.project.projectPartners"), HEADING2_FONT); partnersBlock.add(title); try { document.newPage(); if (project.getLeader() == null && project.getProjectPartners().isEmpty()) { title = new Paragraph(this.getText("summaries.project.empty"), BODY_TEXT_FONT); partnersBlock.add(title); document.add(partnersBlock); document.add(Chunk.NEWLINE); } else { document.add(partnersBlock); document.add(Chunk.NEWLINE); int c = 1; List<ProjectPartner> partnersList = project.getProjectPartners(); if (!partnersList.isEmpty()) { for (ProjectPartner partner : partnersList) { this.addPartner(partner, c); c++; } } } if (project.isReporting()) { // Please describe how your partnerships overall ha List<ProjectPartner> partnersList = project.getProjectPartners(); partnersBlock = new Paragraph(); partnersBlock.setAlignment(Element.ALIGN_JUSTIFIED); partnersBlock.setFont(BODY_TEXT_BOLD_FONT); partnersBlock.add(this.getText("summaries.project.partner.reporting.overall")); partnersBlock.setFont(BODY_TEXT_FONT); if (!partnersList.isEmpty()) { partnersBlock.add(this.messageReturn(partnersList.get(0).getOverall())); } else { partnersBlock.add(this.messageReturn(null)); } partnersBlock.add(Chunk.NEWLINE); partnersBlock.add(Chunk.NEWLINE); document.add(partnersBlock); } // Leason regardins partnersBlock = new Paragraph(); partnersBlock.setAlignment(Element.ALIGN_JUSTIFIED); partnersBlock.setFont(BODY_TEXT_BOLD_FONT); partnersBlock.add(this.getText("summaries.project.partner.planning.lessonRegarding")); partnersBlock.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("partners") != null) { partnersBlock.add(this.messageReturn(project.getComponentLesson("partners").getLessons())); } else { partnersBlock.add(this.messageReturn(null)); } document.add(partnersBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } }
From source file:oscar.form.pdfservlet.FrmCustomedPDFServlet.java
License:Open Source License
protected ByteArrayOutputStream generatePDFDocumentBytes(final HttpServletRequest req, final ServletContext ctx) throws DocumentException { logger.debug("***in generatePDFDocumentBytes2 FrmCustomedPDFServlet.java***"); // added by vic, hsfo Enumeration<String> em = req.getParameterNames(); while (em.hasMoreElements()) { logger.debug("para=" + em.nextElement()); }/*from w ww. java 2 s . c om*/ em = req.getAttributeNames(); while (em.hasMoreElements()) logger.debug("attr: " + em.nextElement()); if (HSFO_RX_DATA_KEY.equals(req.getParameter("__title"))) { return generateHsfoRxPDF(req); } String newline = System.getProperty("line.separator"); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter writer = null; String method = req.getParameter("__method"); String origPrintDate = null; String numPrint = null; if (method != null && method.equalsIgnoreCase("rePrint")) { origPrintDate = req.getParameter("origPrintDate"); numPrint = req.getParameter("numPrints"); } logger.debug("method in generatePDFDocumentBytes " + method); String clinicName; String clinicTel; String clinicFax; // check if satellite clinic is used String useSatelliteClinic = req.getParameter("useSC"); logger.debug(useSatelliteClinic); if (useSatelliteClinic != null && useSatelliteClinic.equalsIgnoreCase("true")) { String scAddress = req.getParameter("scAddress"); logger.debug("clinic detail" + "=" + scAddress); HashMap<String, String> hm = parseSCAddress(scAddress); clinicName = hm.get("clinicName"); clinicTel = hm.get("clinicTel"); clinicFax = hm.get("clinicFax"); } else { // parameters need to be passed to header and footer clinicName = req.getParameter("clinicName"); logger.debug("clinicName" + "=" + clinicName); clinicTel = req.getParameter("clinicPhone"); clinicFax = req.getParameter("clinicFax"); } String patientPhone = req.getParameter("patientPhone"); String patientCityPostal = req.getParameter("patientCityPostal"); String patientAddress = req.getParameter("patientAddress"); String patientName = req.getParameter("patientName"); String sigDoctorName = req.getParameter("sigDoctorName"); String rxDate = req.getParameter("rxDate"); String rx = req.getParameter("rx"); String patientDOB = req.getParameter("patientDOB"); String showPatientDOB = req.getParameter("showPatientDOB"); String imgFile = req.getParameter("imgFile"); String patientHIN = req.getParameter("patientHIN"); String patientChartNo = req.getParameter("patientChartNo"); String pracNo = req.getParameter("pracNo"); Locale locale = req.getLocale(); boolean isShowDemoDOB = false; if (showPatientDOB != null && showPatientDOB.equalsIgnoreCase("true")) { isShowDemoDOB = true; } if (!isShowDemoDOB) patientDOB = ""; if (rx == null) { rx = ""; } String additNotes = req.getParameter("additNotes"); String[] rxA = rx.split(newline); List<String> listRx = new ArrayList<String>(); String listElem = ""; // parse rx and put into a list of rx; for (String s : rxA) { if (s.equals("") || s.equals(newline) || s.length() == 1) { listRx.add(listElem); listElem = ""; } else { listElem = listElem + s; listElem += newline; } } // get the print prop values Properties props = new Properties(); StringBuilder temp = new StringBuilder(); for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();) { temp = new StringBuilder(e.nextElement().toString()); props.setProperty(temp.toString(), req.getParameter(temp.toString())); } for (Enumeration<String> e = req.getAttributeNames(); e.hasMoreElements();) { temp = new StringBuilder(e.nextElement().toString()); props.setProperty(temp.toString(), req.getAttribute(temp.toString()).toString()); } Document document = new Document(); try { String title = req.getParameter("__title") != null ? req.getParameter("__title") : "Unknown"; // specify the page of the picture using __graphicPage, it may be used multiple times to specify multiple pages // however the same graphic will be applied to all pages // ie. __graphicPage=2&__graphicPage=3 String[] cfgGraphicFile = req.getParameterValues("__cfgGraphicFile"); int cfgGraphicFileNo = cfgGraphicFile == null ? 0 : cfgGraphicFile.length; if (cfgGraphicFile != null) { // for (String s : cfgGraphicFile) { // p("cfgGraphicFile", s); // } } String[] graphicPage = req.getParameterValues("__graphicPage"); ArrayList<String> graphicPageArray = new ArrayList<String>(); if (graphicPage != null) { // for (String s : graphicPage) { // p("graphicPage", s); // } graphicPageArray = new ArrayList<String>(Arrays.asList(graphicPage)); } // A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA // and FLSE // the following shows a temp way to get a print page size Rectangle pageSize = PageSize.LETTER; String pageSizeParameter = req.getParameter("rxPageSize"); if (pageSizeParameter != null) { if ("PageSize.HALFLETTER".equals(pageSizeParameter)) { pageSize = PageSize.HALFLETTER; } else if ("PageSize.A6".equals(pageSizeParameter)) { pageSize = PageSize.A6; } else if ("PageSize.A4".equals(pageSizeParameter)) { pageSize = PageSize.A4; } } /* * if ("PageSize.HALFLETTER".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.HALFLETTER; } else if ("PageSize.A6".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.A6; } else if * ("PageSize.A4".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.A4; } */ // p("size of page ", props.getProperty(PAGESIZE)); document.setPageSize(pageSize); // 285=left margin+width of box, 5f is space for looking nice document.setMargins(15, pageSize.getWidth() - 285f + 5f, 170, 60);// left, right, top , bottom writer = PdfWriter.getInstance(document, baosPDF); writer.setPageEvent(new EndPage(clinicName, clinicTel, clinicFax, patientPhone, patientCityPostal, patientAddress, patientName, patientDOB, sigDoctorName, rxDate, origPrintDate, numPrint, imgFile, patientHIN, patientChartNo, pracNo, locale)); document.addTitle(title); document.addSubject(""); document.addKeywords("pdf, itext"); document.addCreator("OSCAR"); document.addAuthor(""); document.addHeader("Expires", "0"); document.open(); document.newPage(); PdfContentByte cb = writer.getDirectContent(); BaseFont bf; // = normFont; cb.setRGBColorStroke(0, 0, 255); // render prescriptions for (String rxStr : listRx) { bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph(new Phrase(rxStr, new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(5f); document.add(p); } // render additional notes if (additNotes != null && !additNotes.equals("")) { bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph(new Phrase(additNotes, new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(10f); document.add(p); } // render optometristEyeParam if (req.getAttribute("optometristEyeParam") != null) { bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph( new Phrase("Eye " + (String) req.getAttribute("optometristEyeParam"), new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(15f); document.add(p); } // render QrCode if (PrescriptionQrCodeUIBean.isPrescriptionQrCodeEnabledForCurrentProvider()) { Integer scriptId = Integer.parseInt(req.getParameter("scriptId")); byte[] qrCodeImage = PrescriptionQrCodeUIBean.getPrescriptionHl7QrCodeImage(scriptId); Image qrCode = Image.getInstance(qrCodeImage); document.add(qrCode); } } catch (DocumentException dex) { baosPDF.reset(); throw dex; } catch (Exception e) { logger.error("Error", e); } finally { if (document != null) { document.close(); } if (writer != null) { writer.close(); } } logger.debug("***END in generatePDFDocumentBytes2 FrmCustomedPDFServlet.java***"); return baosPDF; }
From source file:tufts.vue.PresentationNotes.java
License:Educational Community License
public static void createSpeakerNotes1PerPage(File file) { // step 1: creation of a document-object //This is a bit of a mess but because of hte bugs with drawing the slides //the easy way, we have no other choice but to render them directly onto the pdf //which makes it hard to use tables for stuff like formatting text...so we'll render // a blank table cell then render the image into it. Document document = new Document(); try {/*from www. j av a2s. c o m*/ GUI.activateWaitCursor(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); // step 3: we open the document document.open(); PdfPTable table; PdfPCell cell; int currentIndex = VUE.getActivePathway().getIndex(); VUE.getActivePathway().setIndex(-1); for (LWPathway.Entry entry : VUE.getActivePathway().getEntries()) { final LWSlide slide = entry.produceSlide(); final LWComponent toDraw = (slide == null ? entry.node : slide); final String notes = entry.getNotes(); //String label = entry.getLabel(); PdfContentByte cb = writer.getDirectContent(); Point2D.Float offset = new Point2D.Float(); Rectangle2D bounds = null; //if (!entry.isMapView()) bounds = slide.getBounds(); //else //bounds = entry.getFocal().getBounds(); Dimension page = null; page = new Dimension(432, 324); PdfTemplate tp = cb.createTemplate(432, 324); double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); PdfGraphics2D g2d = (PdfGraphics2D) tp.createGraphics(432, 324, getFontMapper(), false, 60.0f); DrawContext dc = new DrawContext(g2d, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle entry.isMapView() ? entry.getFocal() : slide, false); // todo: absolute links shouldn't be spec'd here dc.setClipOptimized(false); dc.setPrintQuality(); /*if (!entry.isMapView()) slide.drawZero(dc); else { entry.getFocal().draw(dc); }*/ toDraw.drawFit(dc, 0); g2d.dispose(); cb.addTemplate(tp, 80, 482); //Paragraph p = new Paragraph(); //p.setExtraParagraphSpace(330); // p.setSpacingBefore(330f); // p.setAlignment(Element.ALIGN_CENTER); Paragraph phrase = new Paragraph(notes); //phrase.setExtraParagraphSpace(340f); phrase.setSpacingBefore(320f); phrase.setKeepTogether(true); //cell = new PdfPCell(phrase); //cell.setBorder(0); // table = new PdfPTable(new float[]{ 1 }); // table.setWidthPercentage(100.0f); // table.getDefaultCell().setBorder(0); //table.getDefaultCell().setPaddingTop(30); //PdfPCell c2 = new PdfPCell(); //c2.setFixedHeight(340); //slides are 540x405 //c2.setBorder(0); //table.addCell(c2); //table.addCell(cell); //table.setKeepTogether(false); //cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); //p.add(table); //System.out.println("CELL HEIGHT : " + cell.getHeight()); //Section s1 = new Section(); //ColumnText chunk2 = new ColumnText(cb); //chunk2.setText(phrase); //chunk2.setSi //chunk2.setSimpleColumn(phrase,70, 330, document.getPageSize().width()-70,document.getPageSize().height()-70,15, Element.ALIGN_LEFT); // chunk2.go(); //PdfChunk chunk2 = new PdfChunk); Paragraph p2 = new Paragraph(" "); p2.setKeepTogether(false); phrase.setKeepTogether(false); // p2.setExtraParagraphSpace(230f); document.add(p2); document.add(phrase); document.newPage(); } VUE.getActivePathway().setIndex(currentIndex); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } finally { GUI.clearWaitCursor(); } // step 5: we close the document document.close(); }
From source file:wikitopdf.pdf.PdfTitleWrapper.java
License:Open Source License
public void writeTitle(String line) throws DocumentException { try {//from w w w. j a va2s . c o m System.out.println("line " + line); float widthLine = wikiFontSelector.getCommonFont().getBaseFont().getWidthPoint(line, wikiFontSelector.getCommonFont().getSize()); if (widthLine > 40) { line = longTitle(line, 20);//do the function returning the correct string. } Phrase ph = wikiFontSelector.getTitleFontSelector().process(line); ph.setLeading(8); Paragraph pr = new Paragraph(ph); pr.setKeepTogether(true);//should this always be set to true? //if word wraps //this needs to be adjusted to indent wrapped words 2013 if (mct.isOverflow()) { System.out.println("page is end :" + pdfDocument.getPageNumber() + " " + line); mct.nextColumn(); pdfDocument.newPage(); } mct.addElement(pr); // System.out.println(mct); pdfDocument.add(mct); headerFooter.setCurrentLine(line); //ph.setFontSize(20); } catch (Exception ex) { ex.printStackTrace(); } currentTitleNum++; }