Example usage for com.itextpdf.text PageSize LETTER

List of usage examples for com.itextpdf.text PageSize LETTER

Introduction

In this page you can find the example usage for com.itextpdf.text PageSize LETTER.

Prototype

Rectangle LETTER

To view the source code for com.itextpdf.text PageSize LETTER.

Click Source Link

Document

This is the letter format

Usage

From source file:org.gephi.ui.exporter.preview.UIExporterPDFPanel.java

License:Open Source License

public UIExporterPDFPanel() {
    initComponents();//from  ww w.  j  a v  a 2 s .  c om

    sizeFormatter = NumberFormat.getNumberInstance();
    sizeFormatter.setMaximumFractionDigits(3);
    marginFormatter = NumberFormat.getNumberInstance();
    marginFormatter.setMaximumFractionDigits(1);

    //Page size model - http://en.wikipedia.org/wiki/Paper_size
    DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
    comboBoxModel.addElement(new PageSizeItem(PageSize.A0, "A0", 841, 1189, 33.1, 46.8));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A1, "A1", 594, 841, 23.4, 33.1));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A2, "A2", 420, 594, 16.5, 23.4));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A3, "A3", 297, 420, 11.7, 16.5));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A4, "A4", 210, 297, 8.3, 11.7));
    comboBoxModel.addElement(new PageSizeItem(PageSize.A5, "A5", 148, 210, 5.8, 8.3));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_A, "ARCH A", 229, 305, 9, 12));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_B, "ARCH B", 305, 457, 12, 18));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_C, "ARCH C", 457, 610, 18, 24));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_D, "ARCH D", 610, 914, 24, 36));
    comboBoxModel.addElement(new PageSizeItem(PageSize.ARCH_E, "ARCH E", 914, 1219, 36, 48));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B0, "B0", 1000, 1414, 39.4, 55.7));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B1, "B1", 707, 1000, 27.8, 39.4));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B2, "B2", 500, 707, 19.7, 27.8));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B3, "B3", 353, 500, 13.9, 19.7));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B4, "B4", 250, 353, 9.8, 13.9));
    comboBoxModel.addElement(new PageSizeItem(PageSize.B5, "B5", 176, 250, 6.9, 9.8));
    comboBoxModel.addElement(new PageSizeItem(PageSize.LEDGER, "Ledger", 432, 279, 17, 11));
    comboBoxModel.addElement(new PageSizeItem(PageSize.LEGAL, "Legal", 216, 356, 8.5, 14));
    comboBoxModel.addElement(new PageSizeItem(PageSize.LETTER, "Letter", 216, 279, 8.5, 11));
    comboBoxModel.addElement(new PageSizeItem(PageSize.TABLOID, "Tabloid", 279, 432, 11, 17));

    customSizeString = NbBundle.getMessage(UIExporterPDFPanel.class, "UIExporterPDFPanel.pageSize.custom");
    comboBoxModel.addElement(customSizeString);
    pageSizeCombo.setModel(comboBoxModel);

    loadPreferences();

    initEvents();
    refreshUnit(false);
}

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 ww. j  av  a 2 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.me.modelos.PDFHelper.java

public void tablaToPdf(JTable jTable, File pdfNewFile, String title) {
    try {/*from   w w w.  j  a v a 2s  .c  om*/
        Font subCategoryFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD);
        Document document = new Document(PageSize.LETTER.rotate());
        PdfWriter writer = null;
        try {
            writer = PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile));
        } catch (FileNotFoundException fileNotFoundException) {
            Message.showErrorMessage(fileNotFoundException.getMessage());
        }

        writer.setBoxSize("art", new Rectangle(150, 10, 700, 580));
        writer.setPageEvent(new HeaderFooterPageEvent());
        document.open();
        document.addTitle(title);

        document.addSubject("Reporte");
        document.addKeywords("reportes, gestion, pdf");
        document.addAuthor("Gestion de Proyectos de software");
        document.addCreator("gestion de proyectos");

        Paragraph parrafo = new Paragraph(title, subCategoryFont);

        PdfPTable table = new PdfPTable(jTable.getColumnCount());
        table.setWidthPercentage(100);
        PdfPCell columnHeader;

        for (int column = 0; column < jTable.getColumnCount(); column++) {
            Font font = new Font(Font.FontFamily.HELVETICA);
            font.setColor(255, 255, 255);
            columnHeader = new PdfPCell(new Phrase(jTable.getColumnName(column), font));
            columnHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
            columnHeader.setBackgroundColor(new BaseColor(96, 125, 139));
            table.addCell(columnHeader);
        }
        table.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255));
        table.setHeaderRows(1);
        BaseColor verdad = new BaseColor(255, 255, 255);
        BaseColor falso = new BaseColor(214, 230, 244);
        boolean bandera = false;
        for (int row = 0; row < jTable.getRowCount(); row++) {

            for (int column = 0; column < jTable.getColumnCount(); column++) {

                if (bandera) {
                    table.getDefaultCell().setBackgroundColor(verdad);
                } else {
                    table.getDefaultCell().setBackgroundColor(falso);
                }
                table.addCell(jTable.getValueAt(row, column).toString());
                bandera = !bandera;
            }

        }

        parrafo.add(table);
        document.add(parrafo);
        document.close();
        //JOptionPane.showMessageDialog(null, "Se ha creado el pdf en " + pdfNewFile.getPath(),
        //        "RESULTADO", JOptionPane.INFORMATION_MESSAGE);
    } catch (DocumentException documentException) {
        System.out.println("Se ha producido un error " + documentException);
        JOptionPane.showMessageDialog(null, "Se ha producido un error" + documentException, "ERROR",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.qnot.passtab.PDFOutput.java

License:Open Source License

private void createPDF(OutputStream out, String[][] array) throws IOException, DocumentException {
    Document document = new Document(PageSize.LETTER.rotate());
    PdfWriter.getInstance(document, out);
    document.open();/*from  w w  w .  jav  a  2  s. c o m*/

    PdfPTable table = new PdfPTable(array[0].length);
    table.setTotalWidth((float) array.length * PDFOutput.CELL_WIDTH);
    table.setLockedWidth(true);
    table.setHorizontalAlignment(Element.ALIGN_CENTER);

    for (int i = 0; i < array.length; i++) {
        for (int j = 0; j < array[0].length; j++) {
            addCell(table, array[i][j], (j % 2) != 0, (i % 2) != 0, j == 0, i == 0);
        }
    }

    document.add(table);
    document.close();
}

From source file:org.restate.project.controller.PaymentReceiptController.java

License:Open Source License

@RequestMapping(method = RequestMethod.GET, value = "receipt.print")
public void downloadDocument(HttpServletResponse response,
        @RequestParam(value = "id", required = false) Integer id) throws Exception {

    if (id == null) {
        return;//  ww w.j  a  v a  2  s.c o m
    }

    // creation of the document with a certain size and certain margins
    // may want to use PageSize.LETTER instead
    // Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    Document doc = new Document();
    PdfWriter docWriter = null;

    DecimalFormat df = new DecimalFormat("0.00");
    File tmpFile = File.createTempFile("paymentReceipt", ".pdf");

    try {

        //special font sizes
        Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12);

        //file path

        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(tmpFile));

        //document header attributes
        doc.addAuthor("betterThanZero");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("MySampleCode.com");
        doc.addTitle("Report with Column Headings");
        doc.setPageSize(PageSize.LETTER);

        //open document
        doc.open();

        //create a paragraph
        Paragraph paragraph = new Paragraph("iText  is a library that allows you to create and "
                + "manipulate PDF documents. It enables developers looking to enhance web and other "
                + "applications with dynamic PDF document generation and/or manipulation.");

        //specify column widths
        float[] columnWidths = { 1.5f, 2f, 5f, 2f };
        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(90f);

        //insert column headings
        insertCell(table, "Order No", Element.ALIGN_RIGHT, 1, bfBold12);
        insertCell(table, "Account No", Element.ALIGN_LEFT, 1, bfBold12);
        insertCell(table, "Account Name", Element.ALIGN_LEFT, 1, bfBold12);
        insertCell(table, "Order Total", Element.ALIGN_RIGHT, 1, bfBold12);
        table.setHeaderRows(1);

        //insert an empty row
        insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);
        //create section heading by cell merging
        insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);
        double orderTotal, total = 0;

        //just some random data to fill
        for (int x = 1; x < 5; x++) {

            insertCell(table, "10010" + x, Element.ALIGN_RIGHT, 1, bf12);
            insertCell(table, "ABC00" + x, Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, "This is Customer Number ABC00" + x, Element.ALIGN_LEFT, 1, bf12);

            orderTotal = Double.valueOf(df.format(Math.random() * 1000));
            total = total + orderTotal;
            insertCell(table, df.format(orderTotal), Element.ALIGN_RIGHT, 1, bf12);

        }
        //merge the cells to create a footer for that section
        insertCell(table, "New York Total...", Element.ALIGN_RIGHT, 3, bfBold12);
        insertCell(table, df.format(total), Element.ALIGN_RIGHT, 1, bfBold12);

        //repeat the same as above to display another location
        insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);
        insertCell(table, "California Orders ...", Element.ALIGN_LEFT, 4, bfBold12);
        orderTotal = 0;

        for (int x = 1; x < 7; x++) {

            insertCell(table, "20020" + x, Element.ALIGN_RIGHT, 1, bf12);
            insertCell(table, "XYZ00" + x, Element.ALIGN_LEFT, 1, bf12);
            insertCell(table, "This is Customer Number XYZ00" + x, Element.ALIGN_LEFT, 1, bf12);

            orderTotal = Double.valueOf(df.format(Math.random() * 1000));
            total = total + orderTotal;
            insertCell(table, df.format(orderTotal), Element.ALIGN_RIGHT, 1, bf12);

        }
        insertCell(table, "California Total...", Element.ALIGN_RIGHT, 3, bfBold12);
        insertCell(table, df.format(total), Element.ALIGN_RIGHT, 1, bfBold12);

        //add the PDF table to the paragraph
        paragraph.add(table);
        // add the paragraph to the document
        doc.add(paragraph);

    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (doc != null) {
            //close the document
            doc.close();

        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }

        response.setHeader("Content-disposition", "attachment; filename=" + "sampleDoc" + ".pdf");
        response.setContentType("application/pdf");
        OutputStream outputStream = response.getOutputStream();
        FileInputStream fileInputStream = new FileInputStream(tmpFile);

        IOUtils.copy(fileInputStream, outputStream);
        fileInputStream.close();
        outputStream.flush();

        tmpFile.delete();
    }

}

From source file:org.sharegov.cirm.utils.PDFExportUtil.java

License:Apache License

public void exportData(OutputStream out, Json data) throws IOException {
    try {//  ww w.  ja  va 2s .  co m
        Document doc = new Document(PageSize.LETTER.rotate());
        PdfWriter.getInstance(doc, out);
        doc.open();
        //addMetaData(doc);
        addContent(doc, data);
        doc.close();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:org.spinsuite.print.ReportPrintData.java

License:Open Source License

/**
 * Create a PDF File/*from   www  . j  av a2  s.c om*/
 * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com 02/04/2014, 22:52:09
 * @param outFile
 * @throws FileNotFoundException
 * @throws DocumentException
 * @return void
 */
private void createPDF(File outFile) throws FileNotFoundException, DocumentException {
    Document document = new Document(PageSize.LETTER);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile));
    PDFHeaderAndFooter event = new PDFHeaderAndFooter();
    writer.setPageEvent(event);
    document.open();
    //   
    document.addAuthor(ctx.getResources().getString(R.string.app_name));
    document.addCreationDate();
    //   
    Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName());
    //   Set Font
    title.getFont().setStyle(Font.BOLD);
    //   Set Alignment
    title.setAlignment(Paragraph.ALIGN_CENTER);
    //   Add Title
    document.add(title);
    //   Add New Line
    document.add(Chunk.NEWLINE);
    //   Parameters
    ProcessInfoParameter[] param = m_pi.getParameter();
    //   Get Parameter
    if (param != null) {
        //   
        boolean isFirst = true;
        //   Iterate
        for (ProcessInfoParameter para : param) {
            //   Get SQL Name
            String name = para.getInfo();
            StringBuffer textParameter = new StringBuffer();
            if (para.getParameter() == null && para.getParameter_To() == null)
                continue;
            else {
                //   Add Parameters Title
                if (isFirst) {
                    Paragraph titleParam = new Paragraph(
                            ctx.getResources().getString(R.string.msg_ReportParameters));
                    //   Set Font
                    titleParam.getFont().setStyle(Font.BOLDITALIC);
                    //   Add to Document
                    document.add(titleParam);
                    isFirst = false;
                }
                //   Add Parameters Name
                if (para.getParameter() != null && para.getParameter_To() != null) { //   From and To is filled
                    //   
                    textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ")
                            .append(para.getDisplayValue_To());
                } else if (para.getParameter() != null) { //   Only From
                    //   
                    textParameter.append(name).append(" = ").append(para.getDisplayValue());
                } else if (para.getParameter_To() != null) { //   Only To
                    //   
                    textParameter.append(name).append(" <= ").append(para.getDisplayValue_To());
                }
            }
            //   Add to Document
            Paragraph viewParam = new Paragraph(textParameter.toString());
            document.add(viewParam);
        }
    }
    document.add(Chunk.NEWLINE);
    //   
    InfoReportField[] columns = m_reportQuery.getColumns();
    //   Add Table
    PdfPTable table = new PdfPTable(columns.length);
    table.setSpacingBefore(4);
    //   Add Header
    PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName()));
    headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    headerCell.setColspan(columns.length);
    //   Add to Table
    table.addCell(headerCell);
    //   Add Header
    //   Decimal and Date Format
    DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length];
    SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length];
    for (int i = 0; i < columns.length; i++) {
        InfoReportField column = columns[i];
        //   Only Numeric
        if (DisplayType.isNumeric(column.DisplayType))
            cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern);
        //   Only Date
        else if (DisplayType.isDate(column.DisplayType))
            cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern);
        //   
        Phrase phrase = new Phrase(column.PrintName);
        PdfPCell cell = new PdfPCell(phrase);
        if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        else
            cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
        //   
        table.addCell(cell);
    }
    //   Add Detail
    for (int row = 0; row < m_data.size(); row++) {
        //   Get Row
        RowPrintData rPrintData = m_data.get(row);
        //   Iterate
        for (int col = 0; col < columns.length; col++) {
            InfoReportField column = columns[col];
            ColumnPrintData cPrintData = rPrintData.get(col);
            Phrase phrase = null;
            PdfPCell cell = new PdfPCell();
            //   
            String value = cPrintData.getValue();
            //   Only Values
            if (value != null) {
                if (DisplayType.isNumeric(column.DisplayType)) { //   Number
                    //   Format
                    DecimalFormat decimalFormat = cDecimalFormat[col];
                    //   Format
                    if (decimalFormat != null)
                        value = decimalFormat.format(DisplayType.getNumber(value));
                    //   Set Value
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                } else if (DisplayType.isDate(column.DisplayType)) { //   Is Date
                    SimpleDateFormat dateFormat = cDateFormat[col];
                    if (dateFormat != null && value.trim().length() > 0) {
                        long date = Long.parseLong(value);
                        value = dateFormat.format(new Date(date));
                    }
                }
            }
            //   Set Value
            phrase = new Phrase(value);
            //   
            if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            else
                cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
            //   Set Font
            if (rPrintData.isFunctionRow()) {
                //   Set Function Value
                if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0)
                    phrase = new Phrase(cPrintData.getFunctionValue());
                //   Set Font
                phrase.getFont().setStyle(Font.BOLDITALIC);
            }
            //   Add to Table
            cell.setPhrase(phrase);
            table.addCell(cell);
        }
    }
    //   Add Table to Document
    document.add(table);
    //   New Line
    document.add(Chunk.NEWLINE);
    //   Add Footer
    StringBuffer footerText = new StringBuffer(Env.getContext("#SUser"));
    footerText.append("(");
    footerText.append(Env.getContext("#AD_Role_Name"));
    footerText.append("@");
    footerText.append(Env.getContext("#AD_Client_Name"));
    footerText.append(".");
    footerText.append(Env.getContext("#AD_Org_Name"));
    footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) ");
    //   Date
    SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME);
    footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = ");
    footerText.append(pattern.format(new Date()));
    //   
    Paragraph footer = new Paragraph(footerText.toString());
    footer.setAlignment(Paragraph.ALIGN_CENTER);
    //   Set Font
    footer.getFont().setSize(8);
    //   Add Footer
    document.add(footer);
    //   Close Document
    document.close();
}

From source file:org.spinsuite.view.report.ReportPrintData.java

License:Open Source License

/**
 * Create a PDF File/* w ww  .j  a  v  a2  s .com*/
 * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 02/04/2014, 22:52:09
 * @param outFile
 * @throws FileNotFoundException
 * @throws DocumentException
 * @return void
 */
private void createPDF(File outFile) throws FileNotFoundException, DocumentException {
    Document document = new Document(PageSize.LETTER);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile));
    PDFHeaderAndFooter event = new PDFHeaderAndFooter();
    writer.setPageEvent(event);
    document.open();
    //   
    document.addAuthor(ctx.getResources().getString(R.string.app_name));
    document.addCreationDate();
    //   
    Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName());
    //   Set Font
    title.getFont().setStyle(Font.BOLD);
    //   Set Alignment
    title.setAlignment(Paragraph.ALIGN_CENTER);
    //   Add Title
    document.add(title);
    //   Add New Line
    document.add(Chunk.NEWLINE);
    //   Parameters
    ProcessInfoParameter[] param = m_pi.getParameter();
    //   Get Parameter
    if (param != null) {
        //   
        boolean isFirst = true;
        //   Iterate
        for (ProcessInfoParameter para : param) {
            //   Get SQL Name
            String name = para.getInfo();
            StringBuffer textParameter = new StringBuffer();
            if (para.getParameter() == null && para.getParameter_To() == null)
                continue;
            else {
                //   Add Parameters Title
                if (isFirst) {
                    Paragraph titleParam = new Paragraph(
                            ctx.getResources().getString(R.string.msg_ReportParameters));
                    //   Set Font
                    titleParam.getFont().setStyle(Font.BOLDITALIC);
                    //   Add to Document
                    document.add(titleParam);
                    isFirst = false;
                }
                //   Add Parameters Name
                if (para.getParameter() != null && para.getParameter_To() != null) { //   From and To is filled
                    //   
                    textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ")
                            .append(para.getDisplayValue_To());
                } else if (para.getParameter() != null) { //   Only From
                    //   
                    textParameter.append(name).append(" = ").append(para.getDisplayValue());
                } else if (para.getParameter_To() != null) { //   Only To
                    //   
                    textParameter.append(name).append(" <= ").append(para.getDisplayValue_To());
                }
            }
            //   Add to Document
            Paragraph viewParam = new Paragraph(textParameter.toString());
            document.add(viewParam);
        }
    }
    document.add(Chunk.NEWLINE);
    //   
    InfoReportField[] columns = m_reportQuery.getColumns();
    //   Add Table
    PdfPTable table = new PdfPTable(columns.length);
    table.setSpacingBefore(4);
    //   Add Header
    PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName()));
    headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    headerCell.setColspan(columns.length);
    //   Add to Table
    table.addCell(headerCell);
    //   Add Header
    //   Decimal and Date Format
    DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length];
    SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length];
    for (int i = 0; i < columns.length; i++) {
        InfoReportField column = columns[i];
        //   Only Numeric
        if (DisplayType.isNumeric(column.DisplayType))
            cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern);
        //   Only Date
        else if (DisplayType.isDate(column.DisplayType))
            cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern);
        //   
        Phrase phrase = new Phrase(column.PrintName);
        PdfPCell cell = new PdfPCell(phrase);
        if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        else
            cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
        //   
        table.addCell(cell);
    }
    //   Add Detail
    for (int row = 0; row < m_data.size(); row++) {
        //   Get Row
        RowPrintData rPrintData = m_data.get(row);
        //   Iterate
        for (int col = 0; col < columns.length; col++) {
            InfoReportField column = columns[col];
            ColumnPrintData cPrintData = rPrintData.get(col);
            Phrase phrase = null;
            PdfPCell cell = new PdfPCell();
            //   
            String value = cPrintData.getValue();
            if (DisplayType.isNumeric(column.DisplayType)) { //   Number
                //   Format
                DecimalFormat decimalFormat = cDecimalFormat[col];
                //   Format
                if (decimalFormat != null)
                    value = decimalFormat.format(DisplayType.getNumber(value));
                //   Set Value
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            } else if (DisplayType.isDate(column.DisplayType)) { //   Is Date
                SimpleDateFormat dateFormat = cDateFormat[col];
                if (dateFormat != null) {
                    long date = Long.getLong(value, 0);
                    value = dateFormat.format(new Date(date));
                }
            }
            //   Set Value
            phrase = new Phrase(value);
            //   
            if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            else
                cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
            //   Set Font
            if (rPrintData.isFunctionRow()) {
                //   Set Function Value
                if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0)
                    phrase = new Phrase(cPrintData.getFunctionValue());
                //   Set Font
                phrase.getFont().setStyle(Font.BOLDITALIC);
            }
            //   Add to Table
            cell.setPhrase(phrase);
            table.addCell(cell);
        }
    }
    //   Add Table to Document
    document.add(table);
    //   New Line
    document.add(Chunk.NEWLINE);
    //   Add Footer
    StringBuffer footerText = new StringBuffer(Env.getContext(ctx, "#SUser"));
    footerText.append("(");
    footerText.append(Env.getContext(ctx, "#AD_Role_Name"));
    footerText.append("@");
    footerText.append(Env.getContext(ctx, "#AD_Client_Name"));
    footerText.append(".");
    footerText.append(Env.getContext(ctx, "#AD_Org_Name"));
    footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) ");
    //   Date
    SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME);
    footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = ");
    footerText.append(pattern.format(new Date()));
    //   
    Paragraph footer = new Paragraph(footerText.toString());
    footer.setAlignment(Paragraph.ALIGN_CENTER);
    //   Set Font
    footer.getFont().setSize(8);
    //   Add Footer
    document.add(footer);
    //   Close Document
    document.close();
}

From source file:Presentacion.InterfacesAdmin.GeneracionInformes.java

public void InformeMensual() {
    String fecha = this.fechaInforme.getEditor().getText();
    try {/*  w w w.  j  a v a 2  s. c  o  m*/
        GeneradorPDF generador = new GeneradorPDF(PageSize.LETTER, 14, 12, 12);
        generador.GenerarPDF(this.jTextField1.getText());
        generador.openDoc();
        generador.addTitulo("INFORME CONTABLE PARQUEADERO MENSUAL");
        generador.addParagrafo("\n");
        generador.addParagrafo("\n");
        generador.addParagrafo("FECHA: " + fecha);
        generador.addParagrafo("\n");
        Administrador objadmin = new Administrador();
        ParqueaderoMes objfraccion = new ParqueaderoMes();
        ArrayList<Recepcionista> listarecep = new ArrayList<Recepcionista>();
        ArrayList<Object> inforecep = new ArrayList<Object>();
        listarecep = objadmin.GetInfoRecepcionista(Conexion.obtener());
        for (int i = 0; i < listarecep.size(); i++) {
            generador.addParagrafo("RECEPCIONISTA: " + listarecep.get(i).getRecepcionista_nombres() + " "
                    + listarecep.get(i).getRecepcionista_apellidos());
            generador.addParagrafo("\n");
            inforecep = objfraccion.CargarInformacionPorRecepcionista(Conexion.obtener(), fecha,
                    listarecep.get(i).getIdRecepcionista());
            if (inforecep.size() > 1) {
                PdfPTable tabla = new PdfPTable(2);
                generador.AgregarCeldaTabla("PLACA", tabla);
                generador.AgregarCeldaTabla("VALOR ABONADO", tabla);
                for (int j = 1; j < inforecep.size(); j++) {
                    ArrayList<String> datos = new ArrayList();
                    datos = (ArrayList<String>) inforecep.get(j);
                    generador.AgregarCeldaTabla(datos.get(1), tabla);
                    long valor = Long.parseLong(datos.get(3));
                    generador.AgregarCeldaTabla(Long.toString(valor), tabla);
                }
                generador.addTable(tabla);
                generador.addParagrafo("\n");
            } else {
                generador.addParagrafo("No tiene registros asociados");
                generador.addParagrafo("\n");
            }
        }
        ArrayList<String> total = objadmin.TotalesDiarios(Conexion.obtener(), fecha);
        generador.addParagrafo("TOTAL: " + total.get(1));
        generador.addParagrafo("\n");
        generador.closeDoc();
        JOptionPane.showMessageDialog(null, "Reporte creado con exito");
        File file = new File(generador.ruta);
        Desktop.getDesktop().open(file);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getMessage());
    }
}

From source file:Presentacion.InterfacesAdmin.GeneracionInformes.java

public void InformeFraccion() {
    String fecha = this.fechaInforme.getEditor().getText();
    try {/*  w w w .j  av a 2s .c  om*/
        GeneradorPDF generador = new GeneradorPDF(PageSize.LETTER, 14, 12, 12);
        generador.GenerarPDF(this.jTextField1.getText());
        generador.openDoc();
        generador.addTitulo("INFORME CONTABLE PARQUEADERO POR FRACCIN");
        generador.addParagrafo("\n");
        generador.addParagrafo("\n");
        generador.addParagrafo("FECHA: " + fecha);
        generador.addParagrafo("\n");
        Administrador objadmin = new Administrador();
        ParquaderoFraccion objfraccion = new ParquaderoFraccion();
        ArrayList<Recepcionista> listarecep = new ArrayList<Recepcionista>();
        ArrayList<Informacion_Fraccion> inforecep = new ArrayList<Informacion_Fraccion>();
        listarecep = objadmin.GetInfoRecepcionista(Conexion.obtener());
        for (int i = 0; i < listarecep.size(); i++) {
            generador.addParagrafo("RECEPCIONISTA: " + listarecep.get(i).getRecepcionista_nombres() + " "
                    + listarecep.get(i).getRecepcionista_apellidos());
            generador.addParagrafo("\n");
            inforecep = objfraccion.LoadInfoPerRecepcionista(Conexion.obtener(), fecha,
                    listarecep.get(i).getIdRecepcionista());
            if (inforecep.size() != 0) {
                PdfPTable tabla = new PdfPTable(4);
                generador.AgregarCeldaTabla("PLACA", tabla);
                generador.AgregarCeldaTabla("FECHA INGRESO", tabla);
                generador.AgregarCeldaTabla("FECHA SALIDA", tabla);
                generador.AgregarCeldaTabla("VALOR COBRADO", tabla);
                for (int j = 0; j < inforecep.size(); j++) {
                    generador.AgregarCeldaTabla(inforecep.get(j).getVehiculo_placa(), tabla);
                    generador.AgregarCeldaTabla(inforecep.get(j).getFecha_entrada(), tabla);
                    generador.AgregarCeldaTabla(inforecep.get(j).getFecha_salida(), tabla);
                    generador.AgregarCeldaTabla(Long.toString((long) inforecep.get(j).getValor_pagar()), tabla);
                }
                generador.addTable(tabla);
                generador.addParagrafo("\n");
            } else {
                generador.addParagrafo("No tiene registros asociados");
                generador.addParagrafo("\n");
            }
        }
        ArrayList<String> total = objadmin.TotalesDiarios(Conexion.obtener(), fecha);
        generador.addParagrafo("TOTAL: " + total.get(0));
        generador.addParagrafo("\n");
        generador.closeDoc();
        JOptionPane.showMessageDialog(null, "Reporte creado con exito");
        File file = new File(generador.ruta);
        Desktop.getDesktop().open(file);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e.getMessage());
    }
}