Example usage for com.itextpdf.text.pdf PdfPCell setFixedHeight

List of usage examples for com.itextpdf.text.pdf PdfPCell setFixedHeight

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setFixedHeight.

Prototype

public void setFixedHeight(float fixedHeight) 

Source Link

Document

Set a fixed height for the cell.

Usage

From source file:org.inspira.condominio.pdf.DocumentoEgresos.java

private float agregarEgresos(PdfPTable table, InformacionEgreso[] egresos) {
    float total = 0;
    for (InformacionEgreso egreso : egresos) {
        PdfPCell cell4 = new PdfPCell(
                new Phrase(DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault())
                        .format(new Date(egreso.getFecha())), F_NORMAL));
        cell4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell4.setColspan(2);/*from  w w  w.  j a va 2 s.c  o  m*/
        cell4.setFixedHeight(20f);
        PdfPCell cell5 = new PdfPCell(new Phrase(egreso.getDescripcion(), F_NORMAL));
        cell5.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell5.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell5.setColspan(6);
        cell5.setFixedHeight(20f);
        PdfPCell cell6 = new PdfPCell(new Phrase(String.format("%.2f pesos", egreso.getMonto()), F_NORMAL));
        cell6.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell6.setColspan(2);
        cell6.setFixedHeight(20f);
        PdfPCell cell7 = new PdfPCell(new Phrase(egreso.getTipoDePago(), F_NORMAL));
        cell7.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell7.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cell7.setColspan(2);
        cell7.setFixedHeight(20f);
        table.addCell(cell4);
        table.addCell(cell5);
        table.addCell(cell6);
        table.addCell(cell7);
        total += egreso.getMonto();
    }
    return total;
}

From source file:org.inspira.condominio.pdf.DocumentoEstadoDeCuenta.java

private void bakeContent(String path, String imgResString) throws IOException, DocumentException {
    File outFile = new File(path);
    outFile.getParentFile().mkdirs();//from w  w  w .ja  v  a  2  s.  co m
    PdfWriter.getInstance(documento, new FileOutputStream(outFile));
    documento.open();
    documento.add(new Paragraph(
            "Ciudad de Mxico, "
                    + DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(new Date()),
            new Font(FontFamily.HELVETICA, 18, Font.NORMAL, new BaseColor(0x000000))));
    Paragraph intro = new Paragraph(new Phrase("Comprobante de estado de cuenta", F_NORMAL));
    intro.setAlignment(Paragraph.ALIGN_RIGHT);
    intro.setSpacingBefore(10f);
    documento.add(intro);
    Image image = Image.getInstance(imgResString);
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(image.getScaledWidth());
    table.setLockedWidth(true);
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);
    //cell.setCellEvent(new ImageBackgroundEvent(image));
    cell.setFixedHeight(image.getScaledHeight());
    table.addCell(cell);
    documento.add(table);
    Paragraph p1 = new Paragraph("Estado de cuenta: ".concat(idEdoCta), F_NORMAL);
    p1.setSpacingBefore(5f);
    p1.setSpacingAfter(25f);
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(p1);
    documento.add(new Paragraph("Pagos", F_NORMAL));
    agregaTablaDePagos();
    Paragraph pNotas = new Paragraph("Notas: ".concat(notas), F_NORMAL);
    pNotas.setSpacingAfter(12f);
    pNotas.setSpacingAfter(2f);
    documento.add(pNotas);
    Paragraph pAdeudos = new Paragraph("Adeudos", F_NORMAL);
    pAdeudos.setSpacingBefore(25f);
    documento.add(pAdeudos);
    agregaTablaDeAdeudos();
    documento.add(new Paragraph(
            "Recuerde que puede consultar su estado de pagos y adeudos desde la aplicacin mvil o directamente con su administrador.",
            F_NORMAL));
    Paragraph hechoPor = new Paragraph("Elabor:", F_NORMAL);
    hechoPor.setSpacingBefore(30f);
    hechoPor.setSpacingAfter(15f);
    documento.add(hechoPor);
    Paragraph nombreDelAdmin = new Paragraph(admin, F_NORMAL);
    nombreDelAdmin.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(nombreDelAdmin);
    Paragraph nombreDeCondominio = new Paragraph(condominio, F_NORMAL);
    nombreDeCondominio.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(nombreDeCondominio);
}

From source file:org.inspira.condominio.pdf.DocumentoIngreso.java

private float addTablaFormatoIngresos(InformacionIngresos infoIngresos) throws DocumentException {
    PdfPCell cellHeader1 = new PdfPCell(new Phrase("Ingresos Ordinarios", F_CELL_HEADER_TEXT));
    cellHeader1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cellHeader1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellHeader1.setColspan(5);/*from   www  .  jav  a  2s  .c o m*/
    cellHeader1.setFixedHeight(20f);
    cellHeader1.setBackgroundColor(new BaseColor(0xff009846));
    PdfPCell cellHeader2 = new PdfPCell(new Phrase("Monto", F_CELL_HEADER_TEXT));
    cellHeader2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cellHeader2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellHeader2.setColspan(5);
    cellHeader2.setBackgroundColor(new BaseColor(0xff009846));
    cellHeader2.setFixedHeight(20f);
    PdfPCell cellHeader3 = new PdfPCell(new Phrase("En cuenta bancaria", F_NORMAL));
    cellHeader3.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cellHeader3.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellHeader3.setColspan(5);
    cellHeader3.setFixedHeight(20f);
    PdfPCell cellHeader4 = new PdfPCell(
            new Phrase(String.format("%.2f pesos", infoIngresos.getMontoCuentaBancaria()), F_NORMAL));
    cellHeader4.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cellHeader4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellHeader4.setColspan(5);
    cellHeader4.setFixedHeight(20f);
    PdfPCell cellHeader5 = new PdfPCell(new Phrase("En caja de administracin", F_NORMAL));
    cellHeader5.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cellHeader5.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellHeader5.setColspan(5);
    cellHeader5.setFixedHeight(20f);
    PdfPCell cellHeader6 = new PdfPCell(
            new Phrase(String.format("%.2f pesos", infoIngresos.getMontoEnCajaDeAdministracion()), F_NORMAL));
    cellHeader6.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cellHeader6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellHeader6.setColspan(5);
    cellHeader6.setFixedHeight(20f);
    PdfPCell cellHeader7 = new PdfPCell(new Phrase("Total", F_NORMAL));
    cellHeader7.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cellHeader7.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellHeader7.setColspan(5);
    cellHeader7.setFixedHeight(20f);
    PdfPCell cellHeader8 = new PdfPCell(new Phrase(
            String.format("%.2f pesos",
                    infoIngresos.getMontoCuentaBancaria() + infoIngresos.getMontoEnCajaDeAdministracion()),
            F_NORMAL));
    cellHeader8.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cellHeader8.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cellHeader8.setColspan(5);
    cellHeader8.setFixedHeight(20f);
    PdfPTable table = new PdfPTable(10);
    table.setWidthPercentage(100);
    table.addCell(cellHeader1);
    table.addCell(cellHeader2);
    table.addCell(cellHeader3);
    table.addCell(cellHeader4);
    table.addCell(cellHeader5);
    table.addCell(cellHeader6);
    table.addCell(cellHeader7);
    table.addCell(cellHeader8);
    table.setSpacingBefore(3f);
    documento.add(table);
    return infoIngresos.getMontoCuentaBancaria() + infoIngresos.getMontoEnCajaDeAdministracion();
}

From source file:org.inspira.condominio.pdf.DocumentoIngreso.java

private void addTablaCobranza(InformacionIngresos infoIngresos) throws DocumentException {
    PdfPCell cell1 = new PdfPCell(new Phrase("Tipo de condminos", F_CELL_HEADER_TEXT));
    cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell1.setColspan(6);//w  w w . j a  v a2s .c o  m
    cell1.setFixedHeight(20f);
    cell1.setBackgroundColor(new BaseColor(0xff009846));
    PdfPCell cell2 = new PdfPCell(new Phrase("Nmero", F_CELL_HEADER_TEXT));
    cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell2.setColspan(2);
    cell2.setBackgroundColor(new BaseColor(0xff009846));
    cell2.setFixedHeight(20f);
    PdfPCell cell3 = new PdfPCell(new Phrase("Porcentaje", F_CELL_HEADER_TEXT));
    cell3.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell3.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell3.setColspan(2);
    cell3.setBackgroundColor(new BaseColor(0xff009846));
    cell3.setFixedHeight(20f);
    PdfPCell cell4 = new PdfPCell(new Phrase("Condminos que efectuaron su pago", F_NORMAL));
    cell4.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell4.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell4.setColspan(6);
    cell4.setFixedHeight(20f);
    PdfPCell cell5 = new PdfPCell(new Phrase(String.valueOf(infoIngresos.getTotalRegulares()), F_NORMAL));
    cell5.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell5.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell5.setColspan(2);
    cell5.setFixedHeight(20f);
    PdfPCell cell6 = new PdfPCell(new Phrase(String.format("%.2f%%",
            ((float) infoIngresos.getTotalRegulares() / (float) infoIngresos.getTotalhabitantes()) * 100),
            F_NORMAL));
    cell6.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell6.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell6.setColspan(2);
    cell6.setFixedHeight(20f);
    PdfPCell cell7 = new PdfPCell(new Phrase("Condminos morosos", F_NORMAL));
    cell7.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell7.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell7.setColspan(6);
    cell7.setFixedHeight(20f);
    PdfPCell cell8 = new PdfPCell(new Phrase(
            String.valueOf(infoIngresos.getTotalhabitantes() - infoIngresos.getTotalRegulares()), F_NORMAL));
    cell8.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell8.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell8.setColspan(2);
    cell8.setFixedHeight(20f);
    PdfPCell cell9 = new PdfPCell(new Phrase(String.format("%.2f%%",
            (((float) infoIngresos.getTotalhabitantes() - (float) infoIngresos.getTotalRegulares())
                    / (float) infoIngresos.getTotalhabitantes()) * 100),
            F_NORMAL));
    cell9.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell9.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell9.setColspan(2);
    cell9.setFixedHeight(20f);
    PdfPCell cell10 = new PdfPCell(new Phrase("Total", F_NORMAL));
    cell10.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell10.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell10.setColspan(6);
    cell10.setFixedHeight(20f);
    PdfPCell cell11 = new PdfPCell(new Phrase(String.valueOf(infoIngresos.getTotalhabitantes()), F_NORMAL));
    cell11.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell11.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell11.setColspan(2);
    cell11.setFixedHeight(20f);
    PdfPCell cell12 = new PdfPCell(new Phrase("100%", F_NORMAL));
    cell12.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell12.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell12.setColspan(2);
    cell12.setFixedHeight(20f);
    PdfPTable table = new PdfPTable(10);
    table.setWidthPercentage(100);
    table.addCell(cell1);
    table.addCell(cell2);
    table.addCell(cell3);
    table.addCell(cell4);
    table.addCell(cell5);
    table.addCell(cell6);
    table.addCell(cell7);
    table.addCell(cell8);
    table.addCell(cell9);
    table.addCell(cell10);
    table.addCell(cell11);
    table.addCell(cell12);
    documento.add(table);
}

From source file:org.inspira.condominio.pdf.DocumentoIngreso.java

private void addHousePicture(String imgResStr) throws BadElementException, IOException, DocumentException {
    Image image = Image.getInstance(imgResStr);
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(image.getScaledWidth());
    table.setLockedWidth(true);/*  w w w  . j a  va2 s.c o m*/
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);
    //cell.setCellEvent(new ImageBackgroundEvent(image));
    cell.setFixedHeight(image.getScaledHeight());
    table.addCell(cell);
    table.setHorizontalAlignment(PdfPTable.ALIGN_RIGHT);
    documento.add(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 ww w  .  ja  v  a2 s. c om
        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.openmrs.module.maternalsummary.pdf.impl.ITextRenderer.java

License:Open Source License

@Override
public void tableAddInputField() throws PDFRendererException {
    PdfPCell cell = new PdfPCell();
    cell.setCellEvent(new ReferralCommentEvent());
    cell.setFixedHeight(120);
    _table.addCell(cell);/*  w  ww. j av a  2 s . c o m*/
}

From source file:org.techytax.report.helper.PdfReportHelper.java

License:Open Source License

private void addSpace(PdfPTable table) {
    PdfPCell cell = new PdfPCell();
    cell.setFixedHeight(15f);
    cell.setBorder(PdfPCell.NO_BORDER);// w  w w .  j  av a2  s .  co  m
    table.addCell(cell);
}

From source file:pdf.PDFDesign.java

public PdfPTable createPriceTable(List<Item> itemList) throws DocumentException, IOException {
    PdfPTable table = new PdfPTable(nColumns);
    table.setWidthPercentage(100.0f);//from   w  ww  .  ja  v a 2 s .c  om
    //PdfContentByte cb = writer.getDirectContent();

    for (int i = 0; i < itemList.size(); i++) {
        Item item = itemList.get(i);
        //cell.setBorder(0);
        //BarcodeEAN code = new BarcodeEAN();
        //code.setCode(item.getBarCode());
        //code.setGuardBars(false);
        //Image im = code.createImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLACK);
        //p.add(im);//new Chunk(im,0.5f,0.5f));

        PdfPTable innerTable = new PdfPTable(1);

        Paragraph p1 = new Paragraph();
        p1.setFont(titleLineFont);
        String t = item.getTitle();
        String[] split = t.split("//");
        //System.out.println(t);

        for (String split1 : split) {
            p1.add(split1 + "\n");
        }
        PdfPCell innercCell1 = new PdfPCell(p1);
        innercCell1.setLeading(11f, 0f);
        innercCell1.setBorder(0);
        if (t.contains("//")
                && (size.equals("4x6") || size.equals("4x7") || size.equals("5x6") || size.equals("5x7"))) {
            innercCell1.setFixedHeight(titleLineFixedHeight);
        } else {
            innercCell1.setFixedHeight(15.0f);
        }
        //innercCell1.setFixedHeight(titleLineFixedHeight);
        innercCell1.setHorizontalAlignment(Element.ALIGN_CENTER);

        Paragraph p2 = new Paragraph();
        p2.setFont(amountAndPriceLabelLineFont);
        p2.add("Mnostv: " + item.getAmount() + item.getUnit() + "\n");
        PdfPCell innercCell2 = new PdfPCell(p2);
        innercCell2.setLeading(5f + textFontInc, 0f);
        innercCell2.setBorder(0);
        innercCell2.setHorizontalAlignment(Element.ALIGN_CENTER);

        Paragraph p3 = new Paragraph();
        p3.setFont(bigPriceNumberFont);
        p3.add(item.getPrice().substring(0, item.getPrice().length() - 3));
        p3.setFont(decimalPriceNumberFont);
        p3.add(item.getPrice().substring(item.getPrice().length() - 3, item.getPrice().length()));
        p3.setFont(unitPriceLineFont);
        p3.add(item.getCurrency());
        PdfPCell innercCell3 = new PdfPCell(p3);
        if (styleName.equals("style6") /*&& (size.equals("4x7") || size.equals("4x6"))*/) {
            innercCell3 = new PdfPCell(createLine3Table(item, 45 + priceFontInc, 20, 15));
        }
        innercCell3.setBorder(0);
        innercCell3.setLeading(bigPriceNumberLeading, 0f);
        innercCell3.setHorizontalAlignment(Element.ALIGN_CENTER);

        Paragraph p4 = new Paragraph();
        p4.setFont(unitPriceLineFont);
        p4.add("Cena za " + item.getXAmount() + item.getXUnit() + ": " + item.getUnitPrice() + " "
                + item.getCurrency());
        PdfPCell innercCell4 = new PdfPCell(p4);
        innercCell4.setBorder(0);
        innercCell4.setLeading(5f + textFontInc, 0f);
        innercCell4.setHorizontalAlignment(Element.ALIGN_CENTER);

        innerTable.addCell(innercCell1);
        innerTable.addCell(innercCell2);
        innerTable.addCell(innercCell3);
        innerTable.addCell(innercCell4);

        PdfPCell cell = new PdfPCell(innerTable);
        cell.setFixedHeight(cellHeight);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderColor(BaseColor.GRAY);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
    }

    int remainder = itemList.size() % nColumns;
    if (remainder != 0) {
        remainder = nColumns - remainder;
    }
    for (int i = 0; i < remainder; i++) {
        PdfPCell c = new PdfPCell(new Phrase(" "));
        c.setBorderColor(BaseColor.GRAY);
        table.addCell(c);
    }

    return table;
}

From source file:pdf.PDFDesign.java

private PdfPTable createStyle6_4x7Table(List<Item> list) throws DocumentException, IOException {
    PdfPTable table = new PdfPTable(nColumns);
    table.setWidthPercentage(100.0f);/*from w  w w .j av  a2s .  c om*/

    for (int i = 0; i < list.size(); i++) {
        Item item = list.get(i);
        PdfPTable innerTable = new PdfPTable(1);
        Paragraph p1 = new Paragraph();
        p1.setFont(titleLineFont);
        String t = item.getTitle();
        String[] split = t.split("//");
        for (String split1 : split) {
            p1.add(split1 + "\n");
        }
        PdfPCell innercCell1 = new PdfPCell(p1);
        innercCell1.setBorder(0);
        if (t.contains("//")) {
            innercCell1.setFixedHeight(titleLineFixedHeight);
        } else {
            innercCell1.setFixedHeight(15.0f + textFontInc);
        }
        innercCell1.setHorizontalAlignment(Element.ALIGN_CENTER);

        Paragraph p2 = new Paragraph();
        p2.setFont(amountAndPriceLabelLineFont);
        p2.add("Mnostv: " + item.getAmount() + item.getUnit() + "\n");
        PdfPCell innercCell2 = new PdfPCell(p2);
        innercCell2.setLeading(5f, 0f);
        innercCell2.setBorder(0);
        innercCell2.setFixedHeight(12.0f);
        innercCell2.setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell innercCell3 = new PdfPCell(createLine3Table(item, 0, 0, 0));
        innercCell3.setBorder(0);
        innercCell3.setLeading(2.0f, 0f);
        innercCell3.setFixedHeight(67.0f);
        innercCell3.setHorizontalAlignment(Element.ALIGN_CENTER);

        Paragraph p4 = new Paragraph();
        p4.setFont(unitPriceLineFont);
        p4.add("Cena za 1" + item.getXUnit() + ": " + item.getUnitPrice() + " " + item.getCurrency());
        PdfPCell innercCell4 = new PdfPCell(p4);
        innercCell4.setBorder(0);
        innercCell4.setLeading(1f, 0f);
        innercCell4.setHorizontalAlignment(Element.ALIGN_CENTER);

        innerTable.addCell(innercCell1);
        innerTable.addCell(innercCell2);
        innerTable.addCell(innercCell3);
        innerTable.addCell(innercCell4);

        PdfPCell cell = new PdfPCell(innerTable);
        cell.setFixedHeight(cellHeight);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderColor(BaseColor.GRAY);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.addCell(cell);
    }

    int remainder = list.size() % nColumns;
    if (remainder != 0) {
        remainder = nColumns - remainder;
    }
    for (int i = 0; i < remainder; i++) {
        PdfPCell c = new PdfPCell(new Phrase(" "));
        c.setBorderColor(BaseColor.GRAY);
        table.addCell(c);
    }
    return table;
}