List of usage examples for com.itextpdf.text.pdf PdfPTable setWidths
public void setWidths(final int relativeWidths[]) throws DocumentException
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterUnterschriftenLine(Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase("Schulleiter(in)", footerFont)); leftCell.setBorder(Rectangle.TOP); leftCell.setBorderWidth(1f);// w w w. ja v a 2s. c o m leftCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont)); centerCell.setBorder(Rectangle.TOP); centerCell.setBorderWidth(1f); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("Klassenleiter(in)", footerFont)); rightCell.setBorder(Rectangle.TOP); rightCell.setBorderWidth(1f); rightCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] { 0.3f, 0.3f, 0.3f }); return table; }
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterHalbjahrDatumLine(String datumString, Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase(datumString, footerFont)); leftCell.setBorder(Rectangle.NO_BORDER); leftCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont)); centerCell.setBorder(Rectangle.NO_BORDER); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont)); rightCell.setBorder(Rectangle.NO_BORDER); rightCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f);/* w ww .j av a 2 s . com*/ table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] { 0.3f, 0.3f, 0.3f }); return table; }
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterHalbjahrDatumKlassenleiterLine(Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase("Datum", footerFont)); leftCell.setBorder(Rectangle.TOP); leftCell.setBorderWidth(1f);/*from ww w. ja v a2s.c o m*/ leftCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell centerCell = new PdfPCell(new Phrase("", footerFont)); centerCell.setBorder(Rectangle.TOP); centerCell.setBorderWidth(1f); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("Klassenleiter(in)", footerFont)); rightCell.setBorder(Rectangle.TOP); rightCell.setBorderWidth(1f); rightCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100f); table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] { 0.3f, 0.3f, 0.3f }); return table; }
From source file:org.larz.dom4.editor.ReportGenerator.java
License:Open Source License
public static void generateReport(XtextEditor sourcePage, final Shell shell) { final IXtextDocument myDocument = ((XtextEditor) sourcePage).getDocument(); myDocument.modify(new IUnitOfWork.Void<XtextResource>() { @Override//from w w w .java 2 s . com public void process(XtextResource resource) throws Exception { Map<String, Map<String, ModObject>> cellMap = new HashMap<String, Map<String, ModObject>>(); Dom4Mod dom4Mod = (Dom4Mod) resource.getContents().get(0); EList<AbstractElement> elements = dom4Mod.getElements(); for (AbstractElement element : elements) { if (element instanceof SelectArmorById || element instanceof SelectArmorByName) { String name = getSelectArmorname((Armor) element); if (name == null) continue; String id = getArmorid((Armor) element); Map<String, ModObject> map = cellMap.get(ARMOR); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(ARMOR, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Armor) element, modObject.propertyMap); } else if (element instanceof NewArmor) { String name = getArmorname((Armor) element); String id = getArmorid((Armor) element); Map<String, ModObject> map = cellMap.get(ARMOR); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(ARMOR, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Armor) element, modObject.propertyMap); } else if (element instanceof SelectWeaponById || element instanceof SelectWeaponByName) { String name = getSelectWeaponname((Weapon) element); String id = getWeaponid((Weapon) element); Map<String, ModObject> map = cellMap.get(WEAPONS); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(WEAPONS, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Weapon) element, modObject.propertyMap); } else if (element instanceof NewWeapon) { String name = getWeaponname((Weapon) element); String id = getWeaponid((Weapon) element); Map<String, ModObject> map = cellMap.get(WEAPONS); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(WEAPONS, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Weapon) element, modObject.propertyMap); } else if (element instanceof SelectMonsterById || element instanceof SelectMonsterByName) { String name = getSelectMonstername((Monster) element); String id = getMonsterid((Monster) element); Map<String, ModObject> map = cellMap.get(MONSTERS); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(MONSTERS, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Monster) element, modObject.propertyMap); } else if (element instanceof NewMonster) { String name = getMonstername((Monster) element); String id = getMonsterid((Monster) element); Map<String, ModObject> map = cellMap.get(MONSTERS); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(MONSTERS, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Monster) element, modObject.propertyMap); } else if (element instanceof SelectSpellById || element instanceof SelectSpellByName) { String name = getSelectSpellname((Spell) element); String id = getSpellid((Spell) element); Map<String, ModObject> map = cellMap.get(SPELLS); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(SPELLS, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Spell) element, modObject.propertyMap); } else if (element instanceof NewSpell) { String name = getSpellname((Spell) element); //String id = getSpellid((Spell)element); Map<String, ModObject> map = cellMap.get(SPELLS); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(SPELLS, map); } ModObject modObject = map.get(name); if (modObject == null) { modObject = new ModObject(); modObject.title = "" + name; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(name, modObject); } setPropertyValues((Spell) element, modObject.propertyMap); } else if (element instanceof SelectItemById || element instanceof SelectItemByName) { String name = getSelectItemname((Item) element); String id = getItemid((Item) element); Map<String, ModObject> map = cellMap.get(ITEMS); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(ITEMS, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Item) element, modObject.propertyMap); } else if (element instanceof NewItem) { String name = getItemname((Item) element); //String id = getItemid((Item)element); Map<String, ModObject> map = cellMap.get(ITEMS); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(ITEMS, map); } ModObject modObject = map.get(name); if (modObject == null) { modObject = new ModObject(); modObject.title = name; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(name, modObject); } setPropertyValues((Item) element, modObject.propertyMap); } else if (element instanceof SelectSiteById || element instanceof SelectSiteByName) { String name = getSelectSitename((Site) element); String id = getSiteid((Site) element); Map<String, ModObject> map = cellMap.get(SITES); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(SITES, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Site) element, modObject.propertyMap); } else if (element instanceof NewSite) { String name = getSitename((Site) element); String id = getSiteid((Site) element); Map<String, ModObject> map = cellMap.get(SITES); if (map == null) { map = new HashMap<String, ModObject>(); cellMap.put(SITES, map); } ModObject modObject = map.get(id); if (modObject == null) { modObject = new ModObject(); modObject.title = name + " (" + id + ")"; modObject.propertyMap = new HashMap<String, PropertyValues>(); map.put(id, modObject); } setPropertyValues((Site) element, modObject.propertyMap); } else if (element instanceof SelectNation) { // String name = getSelectNationname((Nation)element); // String id = getNationid((Nation)element); // // Map<String, ModObject> map = cellMap.get(NATIONS); // if (map == null) { // map = new HashMap<String, ModObject>(); // cellMap.put(NATIONS, map); // } // ModObject modObject = map.get(id); // if (modObject == null) { // modObject = new ModObject(); // modObject.title = name + " (" + id + ")"; // modObject.propertyMap = new HashMap<String, PropertyValues>(); // map.put(id, modObject); // } // setPropertyValues((SelectNation)element, modObject.propertyMap, resource); } } try { // step 1 Document document = new Document(PageSize.LETTER.rotate()); // step 2 File tempFile = File.createTempFile("dom4editor", ".pdf"); tempFile.deleteOnExit(); FileOutputStream tempFileOutputStream = new FileOutputStream(tempFile); PdfWriter.getInstance(document, tempFileOutputStream); // step 3 document.open(); List<Map.Entry<String, Map<String, ModObject>>> cellList = new ArrayList<Map.Entry<String, Map<String, ModObject>>>(); for (Map.Entry<String, Map<String, ModObject>> innerEntry : cellMap.entrySet()) { cellList.add(innerEntry); } Collections.sort(cellList, new Comparator<Map.Entry<String, Map<String, ModObject>>>() { @Override public int compare(Map.Entry<String, Map<String, ModObject>> o1, Map.Entry<String, Map<String, ModObject>> o2) { return o1.getKey().compareTo(o2.getKey()); } }); for (Map.Entry<String, Map<String, ModObject>> entry : cellList) { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100f); PdfPCell cell = new PdfPCell(new Phrase(entry.getKey(), TITLE)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setFixedHeight(26f); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); table.addCell(cell); table.setHeaderRows(1); List<Map.Entry<String, ModObject>> list = new ArrayList<Map.Entry<String, ModObject>>(); for (Map.Entry<String, ModObject> innerEntry : entry.getValue().entrySet()) { list.add(innerEntry); } Collections.sort(list, new Comparator<Map.Entry<String, ModObject>>() { @Override public int compare(Map.Entry<String, ModObject> o1, Map.Entry<String, ModObject> o2) { return o1.getValue().title.compareTo(o2.getValue().title); } }); PdfPTable propertyTable = null; if (entry.getKey().equals(ARMOR)) { propertyTable = getTable(new String[] { "name", "type", "prot", "def", "enc", "rcost" }, new String[] { "Name", "Type", "Prot", "Def", "Enc", "Rcost" }, new ValueTranslator[] { null, new ValueTranslator() { @Override public String translate(String value) { if (value == null) return null; if (value.equals("4")) return "Shield"; if (value.equals("5")) return "Body Armor"; if (value.equals("6")) return "Helmet"; return "Unknown"; } }, null, null, null, null }, null, list); propertyTable.setWidths(new float[] { 5, 1, 1, 1, 1, 1 }); } if (entry.getKey().equals(WEAPONS)) { propertyTable = getTable( new String[] { "name", "dmg", "att", "nratt", "def", "len", "range", "ammo", "rcost" }, new String[] { "Name", "Dmg", "Att", "Nratt", "Def", "Len", "Range", "Ammo", "Rcost" }, null, null, list); propertyTable.setWidths(new float[] { 5, 1, 1, 1, 1, 1, 1, 1, 1 }); } if (entry.getKey().equals(MONSTERS)) { propertyTable = getTable( new String[] { "name", "hp", "prot", "MOVE", "size", "ressize", "str", "enc", "att", "def", "prec", "mr", "mor", "gcost", "rcost" }, new String[] { "Name", "HP", "Prot", "Move", "Size", "Rsize", "Str", "Enc", "Att", "Def", "Prec", "MR", "Mor", "Gcost", "Rcost" }, null, new ValueCombiner[] { null, null, null, new ValueCombiner() { @Override public String translate(String[] value) { if (value[0] == null && value[1] == null) return null; return value[0] + "/" + value[1]; } @Override public String[] getNeededColumns() { return new String[] { "mapmove", "ap" }; } }, null, null, null, null, null, null, null, null, null, null, null }, list); propertyTable.setWidths(new float[] { 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); } if (entry.getKey().equals(ITEMS)) { propertyTable = getTable( new String[] { "name", "constlevel", "PATH", "type", "weapon", "armor" }, new String[] { "Name", "Constlevel", "Path Req", "Type", "Weapon", "Armor" }, new ValueTranslator[] { null, null, null, new ValueTranslator() { @Override public String translate(String value) { if (value == null) return null; if (value.equals("1")) return "1-h Weapon"; if (value.equals("2")) return "2-h Weapon"; if (value.equals("3")) return "Missile Weapon"; if (value.equals("4")) return "Shield"; if (value.equals("5")) return "Body Armor"; if (value.equals("6")) return "Helmet"; if (value.equals("7")) return "Boots"; if (value.equals("8")) return "Misc"; return "Unknown"; } }, null, null }, new ValueCombiner[] { null, null, new ValueCombiner() { @Override public String translate(String[] value) { if (value[0] == null && value[1] == null && value[2] == null && value[3] == null) return null; StringBuffer buf = new StringBuffer(); if (value[0] != null && !value[0].equals("null")) { buf.append(getPathName(Integer.parseInt(value[0])) + value[1]); } if (value[2] != null && !value[2].equals("null") && !value[2].equals("-1")) { buf.append(getPathName(Integer.parseInt(value[2])) + value[3]); } return buf.toString(); } @Override public String[] getNeededColumns() { return new String[] { "mainpath", "mainlevel", "secondarypath", "secondarylevel" }; } }, null, null, null }, list); propertyTable.setWidths(new float[] { 2.5f, 1, 1, 1, 2.5f, 2.5f }); } if (entry.getKey().equals(SPELLS)) { propertyTable = getTable( new String[] { "name", "school", "researchlevel", "aoe", "damage", "effect", "fatiguecost", "nreff", "range", "precision", "spec", "nextspell" }, new String[] { "Name", "School", "Research", "AOE", "Damage", "Effect", "Fatigue", "Nreff", "Range", "Precision", "Spec", "Nextspell" }, null, null, list); propertyTable.setWidths(new float[] { 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); } if (entry.getKey().equals(NATIONS)) { propertyTable = getTable(new String[] { "name", "startsite1", "startsite2", "startsite3", "startsite4", "era", "startfort" }, list); propertyTable.setWidths(new float[] { 5, 1, 1, 1, 1, 1, 1 }); } if (entry.getKey().equals(SITES)) { propertyTable = getTable( new String[] { "name", "path", "level", "rarity", "loc", "homemon", "homecom", "gold", "res" }, new String[] { "Name", "Path", "Level", "Rarity", "Loc", "Homemon", "Homecom", "Gold", "Res" }, new ValueTranslator[] { null, new ValueTranslator() { @Override public String translate(String value) { if (value == null) return null; if (value.equals("0")) return "Fire"; if (value.equals("1")) return "Air"; if (value.equals("2")) return "Water"; if (value.equals("3")) return "Earth"; if (value.equals("4")) return "Astral"; if (value.equals("5")) return "Death"; if (value.equals("6")) return "Nature"; if (value.equals("7")) return "Blood"; return "Unknown"; } }, null, null, null, null, null, null, null }, null, list); propertyTable.setWidths(new float[] { 5, 1, 1, 1, 1, 1, 1, 1, 1 }); } PdfPCell innerCell = new PdfPCell(); innerCell.addElement(propertyTable); innerCell.setBorder(PdfPCell.NO_BORDER); innerCell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(innerCell); document.add(table); document.newPage(); } document.close(); tempFileOutputStream.flush(); tempFileOutputStream.close(); Program pdfViewer = Program.findProgram("pdf"); if (pdfViewer != null) { pdfViewer.execute(tempFile.getAbsolutePath()); } else { FileDialog dialog = new FileDialog(shell, SWT.SAVE); dialog.setFilterExtensions(new String[] { "*.pdf" }); if (dialog.open() != null) { FileInputStream from = null; FileOutputStream to = null; try { String filterPath = dialog.getFilterPath(); String name = dialog.getFileName(); from = new FileInputStream(new File(tempFile.getAbsolutePath())); to = new FileOutputStream(new File(filterPath + File.separator + name)); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = from.read(buffer)) != -1) { to.write(buffer, 0, bytesRead); // write } } finally { if (from != null) { from.close(); } if (to != null) { to.close(); } } } } } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private PdfPTable prepareTable(List<? extends Column> visibleColumns) throws DocumentException { java.util.List<Integer> widths = new ArrayList<>(); for (Column column : visibleColumns) { widths.add(column.getColumnWidth()); }//from w ww .j a v a 2 s. co m PdfPTable table = new PdfPTable(widths.size()); table.setWidths(ArrayUtils.toPrimitive(widths.toArray(new Integer[widths.size()]))); table.getDefaultCell().setBackgroundColor(HEADER_BACKGROUND); table.getDefaultCell().setPadding(CELL_PADDING); table.setWidthPercentage(WIDTH_PERCENTAGE); table.setSpacingBefore(TABLE_SPACING); table.setHeaderRows(2); table.setFooterRows(1); setTableHeader(table, visibleColumns); setBlankFooter(table, visibleColumns.size()); return table; }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private PdfPTable prepareRequisitionHeaderTable() throws DocumentException { int[] columnWidths = { 160, 160, 160, 160, 160 }; PdfPTable table = new PdfPTable(columnWidths.length); table.setWidths(columnWidths); table.getDefaultCell().setBackgroundColor(HEADER_BACKGROUND); table.getDefaultCell().setPadding(10); table.getDefaultCell().setBorder(0); table.setWidthPercentage(WIDTH_PERCENTAGE); table.setSpacingBefore(TABLE_SPACING); table.setHeaderRows(1);/*from www .j a v a 2 s. co m*/ return table; }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
public PdfPTable getSummary() throws DocumentException { this.requisition.fillFullSupplyCost(); this.requisition.fillNonFullSupplyCost(); DecimalFormat formatter = new DecimalFormat("#,##0.00"); PdfPTable summaryTable = new PdfPTable(2); summaryTable.setWidths(new int[] { 30, 20 }); summaryTable.setSpacingBefore(TABLE_SPACING); summaryTable.setWidthPercentage(40); summaryTable.setHorizontalAlignment(0); PdfPCell summaryHeaderCell = headingCell(messageService.message("label.summary")); summaryHeaderCell.setColspan(2);//from w w w . j a va 2 s.c o m summaryHeaderCell.setPadding(10); summaryHeaderCell.setBorder(0); summaryTable.addCell(summaryHeaderCell); boolean showBudget = !requisition.isEmergency() && requisition.getProgram().getBudgetingApplies(); if (showBudget) { summaryTable.addCell(summaryCell(textCell(messageService.message("label.allocated.budget")))); PdfPCell allocatedBudgetCell = requisition.getAllocatedBudget() != null ? numberCell(messageService.message(LABEL_CURRENCY_SYMBOL) + formatter.format(new Money(requisition.getAllocatedBudget()).toDecimal())) : numberCell(messageService.message("msg.budget.not.allocated")); summaryTable.addCell(summaryCell(allocatedBudgetCell)); } summaryTable.addCell(summaryCell(textCell(messageService.message("label.total.cost.full.supply.items")))); summaryTable.addCell(summaryCell(numberCell(messageService.message(LABEL_CURRENCY_SYMBOL) + formatter.format(requisition.getFullSupplyItemsSubmittedCost().toDecimal())))); summaryTable .addCell(summaryCell(textCell(messageService.message("label.total.cost.non.full.supply.items")))); summaryTable.addCell(summaryCell(numberCell(messageService.message(LABEL_CURRENCY_SYMBOL) + formatter.format(requisition.getNonFullSupplyItemsSubmittedCost().toDecimal())))); summaryTable.addCell(summaryCell(textCell(messageService.message("label.total.cost")))); summaryTable.addCell(summaryCell(numberCell(messageService.message(LABEL_CURRENCY_SYMBOL) + formatter.format(this.getTotalCost(requisition).toDecimal()).toString()))); if (showBudget && requisition.getAllocatedBudget() != null && (requisition.getAllocatedBudget().compareTo(this.getTotalCost(requisition).getValue()) == -1)) { summaryTable.addCell(summaryCell(textCell(messageService.message("msg.cost.exceeds.budget")))); summaryTable.addCell(summaryCell(textCell(" "))); } summaryTable.addCell(summaryCell(textCell(" "))); summaryTable.addCell(summaryCell(textCell(" "))); summaryTable.addCell(summaryCell(textCell(" "))); summaryTable.addCell(summaryCell(textCell(" "))); fillAuditFields(summaryTable); return summaryTable; }
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 a 2 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());/*ww w .j a va 2s .co 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);/*from w w w . ja v a 2s . com*/ 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; }