List of usage examples for com.itextpdf.text Chunk Chunk
private Chunk(final Float tabInterval, final boolean isWhitespace)
From source file:org.openlmis.web.view.pdf.requisition.RequisitionCellFactory.java
License:Open Source License
public static PdfPCell categoryRow(Integer visibleColumnsSize, LineItem lineItem) { Chunk chunk = new Chunk(lineItem.getCategoryName(), FontFactory.getFont(FontFactory.HELVETICA_BOLD)); PdfPCell cell = new PdfPCell(new Phrase(chunk)); cell.setColspan(visibleColumnsSize); cell.setBackgroundColor(HEADER_BACKGROUND); cell.setPadding(CELL_PADDING);/*from ww w .ja v a 2s. c o m*/ return cell; }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private void addHeading(PdfPTable table) throws DocumentException { Chunk chunk = new Chunk(String.format(messageService.message("label.requisition") + ": %s (%s)", this.requisition.getProgram().getName(), this.requisition.getFacility().getFacilityType().getName()), H1_FONT); PdfPCell cell = new PdfPCell(new Phrase(chunk)); cell.setColspan(5);// ww w.ja v a 2 s . c om cell.setPadding(10); cell.setBorder(0); table.addCell(cell); }
From source file:org.opentox.ontology.components.Algorithm.java
License:Open Source License
@Override public PDFObject getPDF() { PDFObject pdf = new PDFObject(); pdf.setPdfTitle(getMeta().identifier); pdf.setPdfKeywords(getMeta().subject); Paragraph p1 = new Paragraph( new Chunk("OpenTox - Algorithm Report\n\n", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14))); pdf.addElement(p1);/*from w w w. j a v a2 s. c om*/ try { PdfPTable table = new PdfPTable(2); table.setWidths(new int[] { 10, 50 }); PdfPCell cell = new PdfPCell(new Paragraph("Algorithm Presentation - General")); cell.setColspan(2); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("Name"); table.addCell(getMeta().getName()); table.addCell("Title"); table.addCell(getMeta().title); table.addCell("Subject"); table.addCell(getMeta().subject); table.addCell("Description"); table.addCell(getMeta().description); table.addCell("Identifier"); table.addCell(getMeta().identifier); pdf.addElement(table); pdf.addElement(new Paragraph("\n\n\n")); table = new PdfPTable(2); table.setWidths(new int[] { 10, 50 }); cell = new PdfPCell(new Paragraph("General Meta Information")); cell.setColspan(2); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("Type"); table.addCell(getMeta().type); table.addCell("Creator"); table.addCell(getMeta().creator); table.addCell("Publisher"); table.addCell(getMeta().publisher); table.addCell("Relation"); table.addCell(getMeta().relation); table.addCell("Rights"); table.addCell(getMeta().rights); table.addCell("Source"); table.addCell(getMeta().source); table.addCell("Provenance"); table.addCell(getMeta().provenance); table.addCell("Contributor"); table.addCell(getMeta().contributor); table.addCell("Language"); table.addCell(getMeta().language.getDisplayLanguage()); table.addCell("Created on"); table.addCell(getMeta().date.toString()); table.addCell("Formats"); ArrayList<MediaType> listMedia = getMeta().format; String formatTableEntry = ""; for (int i = 0; i < listMedia.size(); i++) { formatTableEntry += listMedia.get(i).toString(); if (i < listMedia.size() - 1) { formatTableEntry += "\n"; } } table.addCell(formatTableEntry); table.addCell("Audience"); ArrayList<Audience> audiences = getMeta().audience; String auds = ""; for (int i = 0; i < audiences.size(); i++) { auds += audiences.get(i).getName(); if (i < audiences.size() - 1) { auds += "\n"; } } table.addCell(auds); pdf.addElement(table); pdf.addElement(new Paragraph("\n\n\n")); table = new PdfPTable(4); table.setWidths(new int[] { 30, 30, 30, 30 }); cell = new PdfPCell(new Paragraph("Algorithm Parameters")); cell.setColspan(4); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("Parameter Name"); table.addCell("XSD DataType"); table.addCell("Default Value"); table.addCell("Scope"); Map<String, AlgorithmParameter> algParameters = getMeta().getParameters(); Set<Entry<String, AlgorithmParameter>> entrySet = algParameters.entrySet(); for (Entry e : entrySet) { String pName = (String) e.getKey(); AlgorithmParameter ap = (AlgorithmParameter) e.getValue(); table.addCell(pName); table.addCell(ap.dataType.getURI()); table.addCell(ap.paramValue.toString()); table.addCell(ap.paramScope.toString()); } pdf.addElement(table); pdf.addElement(new Paragraph("\n\n\n")); table = new PdfPTable(1); cell = new PdfPCell(new Paragraph("Ontologies")); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); OTAlgorithmTypes type = getMeta().getAlgorithmType(); table.addCell(type.getURI()); Set<Resource> superOntologies = type.getSuperEntities(); Iterator<Resource> it = superOntologies.iterator(); while (it.hasNext()) { table.addCell(it.next().getURI()); } pdf.addElement(table); } catch (final DocumentException ex) { YaqpLogger.LOG.log(new Warning(getClass(), "XCF316 - Pdf Exception :" + ex.toString())); } return pdf; }
From source file:org.opentox.ontology.components.User.java
License:Open Source License
@Override public PDFObject getPDF() { PDFObject pdf = new PDFObject(); pdf.setPdfTitle(getUserName());// w w w.ja v a 2s . c o m pdf.setPdfKeywords("User, " + getUserName() + ", Account"); pdf.setSubject("User Account Information for user " + getUserName()); Paragraph p1 = new Paragraph( new Chunk("OpenTox - User Report\n\n", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14))); pdf.addElement(p1); try { PdfPTable table = new PdfPTable(2); table.setWidths(new int[] { 30, 50 }); PdfPCell cell = new PdfPCell(new Paragraph("User Account Information")); cell.setColspan(2); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("UserName"); table.addCell(getUserName()); table.addCell("First Name"); table.addCell(getFirstName()); table.addCell("Last Name"); table.addCell(getLastName()); table.addCell("e-mail"); table.addCell(getEmail()); table.addCell("UserGroup"); table.addCell(getUserGroup().getName()); table.addCell("Authorization Level"); table.addCell(Integer.toString(getUserGroup().getLevel())); table.addCell("Organization"); table.addCell(getOrganization()); table.addCell("Country"); table.addCell(getCountry()); table.addCell("City"); table.addCell(getCity()); table.addCell("Address"); table.addCell(getAddress()); table.addCell("Web Page"); table.addCell(getWebpage()); table.addCell("Created on"); table.addCell(getTimeStamp()); pdf.addElement(table); } catch (DocumentException ex) { YaqpLogger.LOG.log( new Warning(getClass(), "XEI909 - Error while generating " + "PDF representation for User")); } return pdf; }
From source file:org.opentox.ontology.components.UserGroup.java
License:Open Source License
@Override public PDFObject getPDF() { PDFObject pdf = new PDFObject(); Paragraph p1 = new Paragraph( new Chunk("OpenTox - UserGroup Report\n\n", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14))); pdf.addElement(p1);// w ww .ja v a2 s. c o m try { PdfPTable table = new PdfPTable(2); table.setWidths(new int[] { 30, 50 }); PdfPCell cell = new PdfPCell(new Paragraph("UserGroup General Information")); cell.setColspan(2); cell.setBackgroundColor(new BaseColor(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("Name"); table.addCell(getName()); table.addCell("Authorization Level"); table.addCell(Integer.toString(getLevel())); pdf.addElement(table); } catch (DocumentException ex) { YaqpLogger.LOG.log(new Warning(getClass(), "XPI908 - Error while generating " + "PDF representation for User Group ")); } return pdf; }
From source file:org.primaresearch.pdf.PageToPdfConverter.java
License:Apache License
/** * Calculates the font size to fit the given text into the specified dimensions. * @param text/*from ww w .j a v a 2s . c om*/ * @param width * @param height * @return * @throws IOException */ private float calculateFontSize(String text, int width, int height) throws IOException { float sw = font.getWidth(text); //float textHeight = font.getFontDescriptor().getFontBoundingBox().getHeight() / 1000 * fontSize * 0.865; //float fontSizeY = height * 1000.0f / (font.get().getFontBoundingBox().getHeight() * 0.865f); float fontSizeX = width * 1000.0f / (sw * 0.865f); //Validate and reduce font size until it fits Chunk chunk = new Chunk(text, new Font(font, fontSizeX)); ; while (chunk.getWidthPoint() > width) { fontSizeX -= 0.5f; chunk = new Chunk(text, new Font(font, fontSizeX)); } //if (fontSizeX <= 0.0f && fontSizeY <= 0.0f) // return 12f; //return Math.min(fontSizeX, fontSizeY); return fontSizeX; }
From source file:org.smap.sdal.managers.PDFSurveyManager.java
License:Open Source License
private Paragraph getPara(String value, DisplayItem di, GlobalVariables gv, ArrayList<String> deps, Anchor anchor) {//w w w . ja v a 2 s .com boolean hasContent = false; Font f = null; boolean isRtl = false; String lang = ""; Paragraph para = new Paragraph("", defaultFont); if (value != null && value.trim().length() > 0) { lang = GeneralUtilityMethods.getLanguage(value); f = getFont(lang); isRtl = isRtl(lang); para.add(new Chunk(GeneralUtilityMethods.unesc(value), f)); hasContent = true; } // Add dependencies if (deps != null) { for (String n : deps) { if (n != null && n.trim().length() > 0) { if (hasContent) { para.add(new Chunk(",", defaultFont)); } lang = GeneralUtilityMethods.getLanguage(n); f = getFont(lang); if (!isRtl) { // Don't override RTL if it has already been set isRtl = isRtl(lang); } para.add(new Chunk(n, f)); } } } if (anchor != null) { para.setFont(defaultFontLink); para.add(anchor); para.setFont(defaultFontLink); } return para; }
From source file:org.smap.sdal.managers.PDFSurveyManager.java
License:Open Source License
private void processSelect(Parser parser, String remoteUser, PdfPCell cell, DisplayItem di, boolean generateBlank, GlobalVariables gv, int oId) throws Exception { Font f = null;/*from w w w. ja va 2s . c o m*/ boolean isRtl = false; // If generating blank template List list = new List(); list.setAutoindent(false); list.setSymbolIndent(24); String lang; boolean isSelectMultiple = di.type.equals("select") ? true : false; // Questions that append their values to this question ArrayList<String> deps = gv.addToList.get(di.fIdx + "_" + di.rec_number + "_" + di.name); /* * Add the value of this question unless * The form is not blank and the value is "other" and their are 1 or more dependent questions * In this case we assume that its only the values of the dependent questions that are needed */ if (generateBlank) { // TODO get real choices using choice manager Form form = survey.forms.get(di.fIdx); Question question = form.questions.get(di.qIdx); OptionList ol = survey.optionLists.get(question.list_name); for (Option o : ol.options) { String text = null; if (o.display_name != null && o.display_name.trim().length() > 0) { text = o.display_name; } else { text = o.labels.get(languageIdx).text; } lang = GeneralUtilityMethods.getLanguage(text); f = getFont(lang); isRtl = isRtl(lang); ListItem item = new ListItem(GeneralUtilityMethods.unesc(text), f); if (isSelectMultiple) { item.setListSymbol(new Chunk("\uf096", Symbols)); list.add(item); } else { item.setListSymbol(new Chunk("\uf10c", Symbols)); list.add(item); } } if (isRtl) { cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); } cell.addElement(list); } else { if (deps == null || (di.value != null && !di.value.trim().toLowerCase().equals("other"))) { String value = di.value; if (di.type.equals("select1")) { Form form = survey.forms.get(di.fIdx); Question question = form.questions.get(di.qIdx); ArrayList<String> matches = new ArrayList<String>(); matches.add(di.value); value = choiceManager.getLabel(sd, cResults, user, oId, survey.id, question.id, question.l_id, question.external_choices, question.external_table, survey.languages.get(languageIdx).name, languageIdx, matches, survey.ident); } else if (di.type.equals("select")) { String nameValue = value; if (nameValue != null) { String vArray[] = nameValue.split(" "); ArrayList<String> matches = new ArrayList<String>(); if (vArray != null) { for (String v : vArray) { matches.add(v); } } Form form = survey.forms.get(di.fIdx); Question question = form.questions.get(di.qIdx); value = choiceManager.getLabel(sd, cResults, user, oId, survey.id, question.id, question.l_id, question.external_choices, question.external_table, survey.languages.get(languageIdx).name, languageIdx, matches, survey.ident); } } if (GeneralUtilityMethods.isRtlLanguage(di.value)) { cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); } parser.elements.clear(); String html = getHtml(value, di, gv, deps); try { parser.xmlParser.parse(new StringReader(html)); } catch (Exception e) { log.info("Error parsing: " + html.toString() + " : " + e.getMessage()); lm.writeLog(sd, survey.getId(), remoteUser, LogManager.ERROR, e.getMessage() + " for: " + html.toString()); cell.addElement(getPara(html.toString(), di, gv, null, null)); } for (Element element : parser.elements) { cell.addElement(element); } //cell.addElement(getPara(value, di, gv, deps, null)); } } }
From source file:org.smap.sdal.managers.PDFSurveyManager.java
License:Open Source License
private void addValue(Document document, String value, float indent) throws DocumentException { Font f = null;/*from w w w . j ava2s. c o m*/ String lang; if (value != null && value.trim().length() > 0) { lang = GeneralUtilityMethods.getLanguage(value); f = getFont(lang); Paragraph para = new Paragraph("", f); para.setIndentationLeft(indent); para.add(new Chunk(GeneralUtilityMethods.unesc(value), f)); document.add(para); } }
From source file:org.smap.sdal.managers.PDFTableManager.java
License:Open Source License
private Paragraph getPara(String value) { Paragraph para = new Paragraph("", font); if (value != null && value.trim().length() > 0) { para.add(new Chunk(GeneralUtilityMethods.unesc(value), font)); }//from w w w . j a v a 2s. com return para; }