Example usage for com.itextpdf.text Document addTitle

List of usage examples for com.itextpdf.text Document addTitle

Introduction

In this page you can find the example usage for com.itextpdf.text Document addTitle.

Prototype


public boolean addTitle(String title) 

Source Link

Document

Adds the title to a Document.

Usage

From source file:org.cidte.sii.negocio.PDFWriter.java

public void writePDF(ArrayList<Writable> list, String directorio, String nombre, java.awt.Image image)
        throws DocumentException, FileNotFoundException, BadElementException, IOException {

    Document doc = new Document();
    PdfWriter docWriter;/*  w  w w. ja v a2s .  c o  m*/

    // 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
    String path = directorio + nombre + ".pdf";
    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(new File(path)));

    // document header attributes
    doc.addAuthor("sii");
    doc.addCreationDate();
    doc.addProducer();
    doc.addCreator("sii");
    doc.addTitle(nombre);
    doc.setPageSize(PageSize.LETTER);

    // open document
    doc.open();

    Image img = Image.getInstance(image, null);
    img.setAlignment(Element.ALIGN_LEFT);
    doc.add(img);

    // 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.");

    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(list.get(0).getNames().length);
    // set table width a percentage of the page width
    table.setWidthPercentage(100);
    table.setSpacingBefore(10f); // Space before table
    table.setSpacingAfter(10f); // Space after table

    // insert column headings
    String[] headings = list.get(0).getNames();
    for (String heading : headings) {
        insertCell(table, heading, Element.ALIGN_CENTER, 1, bfBold12);
    }
    table.setHeaderRows(1);

    // insert the data
    for (int i = 0; i < list.size(); i++) {
        Writable w = list.get(i);
        Object[] arr = w.getAsArray();
        for (int j = 0; j < arr.length; j++) {
            // arr[j]
            insertCell(table, arr[j].toString(), Element.ALIGN_LEFT, 1, bf12);
        }
    }

    // insert an empty row
    // insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);
    // add the PDF table to the paragraph
    paragraph.add(table);
    // add the paragraph to the document
    doc.add(paragraph);

    // close the document
    doc.close();

    // close the writer
    docWriter.close();

}

From source file:org.com.controller.ProductController.java

@RequestMapping(value = "/repProduct", method = RequestMethod.GET)
public void productReport(Model m, HttpServletResponse response, HttpServletRequest request,
        OutputStream outputStream) throws Exception {
    String name = "ProductReport-";
    Date d = new Date();
    name = name + d.toString() + ".pdf";
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "attachment; filename=" + name);
    Rectangle pagesize = new Rectangle(216f, 720f);
    Document document = new Document(PageSize.A4);
    PdfWriter.getInstance(document, outputStream);
    document.open();//from   w w w  .  j  av  a 2  s . c  o m
    document.addTitle("PRODUCT DETAILSA REPORT");
    document.add(new Paragraph("PRODUCT DETAILSA REPORT ",
            FontFactory.getFont(FontFactory.HELVETICA, 28, BaseColor.CYAN)));
    document.add(new Paragraph("DATE: " + new Date()));
    document.add(new Paragraph("-------------------------------------------------------- "));
    document.add(new Paragraph(" "));
    ProductDaoImpl pdi = new ProductDaoImpl();
    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell("ID");
    table.addCell("TITLE");
    table.addCell("PUBLISHER");
    table.addCell("PRICE");
    ArrayList<ProductTable> list = pdi.getAllProduct();
    for (ProductTable u : list) {
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(u.getPid().toString());
        table.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
        table.addCell(u.getPname());
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(u.getPublisher());
        table.getDefaultCell().setBackgroundColor(BaseColor.GRAY);
        table.addCell(u.getSprice().toString());
    }
    document.add(table);
    document.close();

}

From source file:org.ednovo.gooru.domain.service.resource.ResourceServiceImpl.java

License:Open Source License

/**
 * @param mainFileUrl/*from  w  w w  .ja va 2  s  . c om*/
 *            : PDF file that has to be splitted
 * @param splittedPageSize
 *            : Page size of each splitted files
 */
private static String splitAndSaveChapter(String mainFileUrl, int pageBeginNum, int pageEndNum, String name) {
    try {
        PdfReader reader = new PdfReader(mainFileUrl);

        int splittedPageSize = pageEndNum - pageBeginNum + 1;
        int pageNum = pageBeginNum;

        String chapterUrl = mainFileUrl.substring(0, mainFileUrl.indexOf(DOT_PDF)) + "-" + name + DOT_PDF;

        Document document = new Document(reader.getPageSizeWithRotation(1));

        FileOutputStream fos = new FileOutputStream(chapterUrl);
        PdfCopy writer = new PdfCopy(document, fos);
        Map<String, String> info = reader.getInfo();

        document.open();
        if ((info != null) && (info.get(_AUTHOR) != null)) {
            document.addAuthor(info.get(_AUTHOR));
        }

        document.addTitle(name);

        for (int offset = 0; offset < splittedPageSize && (pageNum + offset) < pageEndNum; offset++) {
            PdfImportedPage page = writer.getImportedPage(reader, pageNum + offset);
            writer.addPage(page);
        }

        document.close();
        writer.close();
        return chapterUrl;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.gbif.ipt.task.Eml2Pdf.java

/**
   * Construct PDF document, mainly out of information extracted from Resource's EML object. 
   *//from  ww  w  .j  a v  a2s .c om
   * @param doc      Document
   * @param resource Resource
   * @param lng language of the document
   *
   * @throws DocumentException if problem occurs during add
*/

private void addMetaData(Document document) {
    log.info("Adding metadata info to document");
    document.addTitle(getText("pdf.title.doc"));
    document.addSubject(getText("pdf.subj.doc"));
    document.addAuthor(getText("pdf.author.doc"));
    document.addCreator(getText("pdf.creator.doc"));
}

From source file:org.me.modelos.PDFHelper.java

public void tablaToPdf(JTable jTable, File pdfNewFile, String title) {
    try {//ww  w .j  a v  a  2 s  . co  m
        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.opentox.io.publishable.PDFObject.java

License:Open Source License

public void publish(YaqpIOStream stream) throws YaqpException {
    if (stream == null) {
        throw new NullPointerException("Cannot public pdf to a null output stream");
    }//from w  w  w. j a va2 s  .  c  o  m
    try {
        Document doc = new Document();
        try {
            PdfWriter.getInstance(doc, (OutputStream) stream.getStream());
        } catch (ClassCastException ex) {
            throw new ClassCastException("The stream you provided is not a valid output stream");
        }
        doc.open();
        doc.addAuthor(pdfAuthor);
        doc.addCreationDate();
        doc.addProducer();
        doc.addSubject(subject);
        doc.addCreator(pdfCreator);
        doc.addTitle(pdfTitle);
        doc.addKeywords(pdfKeywords);
        doc.addHeader("License", "GNU GPL v3");
        Image image = null;
        try {
            image = Image.getInstance(new URL(OpenToxLogoUrl));
        } catch (Exception ex) {// OpenTox Logo was not found on the web...
            try {// use the cached image instead
                YaqpLogger.LOG.log(new Trace(getClass(), "OpenTox Logo not found at " + OpenToxLogoUrl));
                image = Image.getInstance(alternativeLogoPath);
            } catch (Exception ex1) {// if no image at local folder
                YaqpLogger.LOG.log(new Debug(getClass(),
                        "OpenTox Logo not found at " + alternativeLogoPath + " :: " + ex1));
            }
        }
        if (image != null) {
            image.scalePercent(40);
            image.setAnnotation(new Annotation(0, 0, 0, 0, "http://opentox.org"));
            Chunk ck_ot = new Chunk(image, -5, -30);
            doc.add(ck_ot);
        }
        try {
            Image yaqp = Image.getInstance(yaqpLogo);
            yaqp.scalePercent(30);
            yaqp.setAnnotation(new Annotation(0, 0, 0, 0, "https://opentox.ntua.gr"));
            yaqp.setAlt("YAQP(R), yet another QSAR Project");
            Chunk ck_yaqp = new Chunk(yaqp, 15, -30);
            doc.add(ck_yaqp);
        } catch (Exception ex) {
            YaqpLogger.LOG
                    .log(new Warning(getClass(), "YAQP Logo not found at " + kinkyDesignLogo + " :: " + ex));
        }
        doc.add(new Paragraph("\n\n\n"));
        for (Element e : elements) {
            doc.add(e);
        }
        doc.close();
    } catch (DocumentException ex) {
        String message = "Error while generating PDF representation.";
        YaqpLogger.LOG.log(new Warning(getClass(), message));
        throw new YaqpException(XPDF18, message, ex);
    }

}

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;//from   ww  w  .  java 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

private static void addMetaData(Document doc) {
    doc.addTitle("My title");
    doc.addSubject("My subject");
    doc.addKeywords("itext, java, export");
    doc.addAuthor("");
    doc.addCreator("");
}

From source file:org.sistemafinanciero.rest.impl.CuentaBancariaRESTService.java

License:Apache License

@Override
public Response getEstadoCuentaPdf(BigInteger idCuentaBancaria, Long desde, Long hasta) {
    Date dateDesde = (desde != null ? new Date(desde) : null);
    Date dateHasta = (desde != null ? new Date(hasta) : null);

    //dando formato a las fechas
    SimpleDateFormat fechaformato = new SimpleDateFormat("dd/MM/yyyy");
    String fechaDesde = fechaformato.format(dateDesde);
    String fechaHasta = fechaformato.format(dateHasta);

    Set<Titular> titulares = cuentaBancariaServiceNT.getTitulares(idCuentaBancaria, true);
    List<String> emails = new ArrayList<String>();
    for (Titular titular : titulares) {
        PersonaNatural personaNatural = titular.getPersonaNatural();
        String email = personaNatural.getEmail();
        if (email != null)
            emails.add(email);//w  ww.j ava 2 s  .c o  m
    }
    CuentaBancariaView cuentaBancariaView = cuentaBancariaServiceNT.findById(idCuentaBancaria);
    List<EstadocuentaBancariaView> list = cuentaBancariaServiceNT.getEstadoCuenta(idCuentaBancaria, dateDesde,
            dateHasta);

    /**obteniendo la moneda y dando formato**/
    Moneda moneda = monedaServiceNT.findById(cuentaBancariaView.getIdMoneda());
    NumberFormat df1 = NumberFormat.getCurrencyInstance();
    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setCurrencySymbol("");
    dfs.setGroupingSeparator(',');
    dfs.setMonetaryDecimalSeparator('.');
    ((DecimalFormat) df1).setDecimalFormatSymbols(dfs);

    /**PDF**/
    ByteArrayOutputStream outputStream = null;
    outputStream = new ByteArrayOutputStream();

    Document document = new Document();
    try {
        PdfWriter.getInstance(document, outputStream);
        document.open();

        document.addTitle("Estado de Cuenta");
        document.addSubject("Estado de Cuenta");
        document.addKeywords("email");
        document.addAuthor("Cooperativa de Ahorro y Crdito Caja Ventura");
        document.addCreator("Cooperativa de Ahorro y Crdito Caja Ventura");

        Paragraph saltoDeLinea = new Paragraph();
        document.add(saltoDeLinea);
    } catch (DocumentException e1) {
        e1.printStackTrace();
    }

    /******************* TITULO ******************/
    try {
        //Image img = Image.getInstance("/images/logo_coop_contrato.png");
        Image img = Image.getInstance("//usr//share//jboss//archivos//logoCartilla//logo_coop_contrato.png");
        img.setAlignment(Image.LEFT | Image.UNDERLYING);
        document.add(img);

        Paragraph parrafoPrincipal = new Paragraph();
        parrafoPrincipal.setSpacingAfter(30);
        //parrafoPrincipal.setSpacingBefore(50);
        parrafoPrincipal.setAlignment(Element.ALIGN_CENTER);
        parrafoPrincipal.setIndentationLeft(100);
        parrafoPrincipal.setIndentationRight(50);

        Paragraph parrafoSecundario = new Paragraph();
        parrafoSecundario.setSpacingAfter(20);
        parrafoSecundario.setSpacingBefore(-20);
        parrafoSecundario.setAlignment(Element.ALIGN_LEFT);
        parrafoSecundario.setIndentationLeft(160);
        parrafoSecundario.setIndentationRight(10);

        Chunk titulo = new Chunk("ESTADO DE CUENTA");
        Font fuenteTitulo = new Font(FontFamily.UNDEFINED, 13, Font.BOLD);
        titulo.setFont(fuenteTitulo);
        parrafoPrincipal.add(titulo);

        Font fuenteDatosCliente = new Font(FontFamily.UNDEFINED, 10);
        Date fechaSistema = new Date();
        SimpleDateFormat formatFecha = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        String fechaActual = formatFecha.format(fechaSistema);

        if (cuentaBancariaView.getTipoPersona() == TipoPersona.NATURAL) {
            Chunk clientePNNombres = new Chunk("CLIENTE       : " + cuentaBancariaView.getSocio() + "\n");
            Chunk clientePNDni = new Chunk(cuentaBancariaView.getTipoDocumento() + "                : "
                    + cuentaBancariaView.getNumeroDocumento() + "\n");
            //Chunk clientePNTitulares = new Chunk("TITULAR(ES): " + cuentaBancariaView.getTitulares() + "\n");
            Chunk clientePNFecha = new Chunk("FECHA          : " + fechaActual + "\n\n");

            Chunk tipoCuentaPN = new Chunk("CUENTA " + cuentaBancariaView.getTipoCuenta() + " N "
                    + cuentaBancariaView.getNumeroCuenta() + "\n");
            Chunk tipoMonedaPN;

            if (cuentaBancariaView.getIdMoneda().compareTo(BigInteger.ZERO) == 0) {
                tipoMonedaPN = new Chunk("MONEDA: " + "DOLARES AMERICANOS" + "\n");
            } else if (cuentaBancariaView.getIdMoneda().compareTo(BigInteger.ONE) == 0) {
                tipoMonedaPN = new Chunk("MONEDA: " + "NUEVOS SOLES" + "\n");
            } else {
                tipoMonedaPN = new Chunk("MONEDA: " + "EUROS" + "\n");
            }

            Chunk fechaEstadoCuenta = new Chunk("ESTADO DE CUENTA DEL " + fechaDesde + " AL " + fechaHasta);
            //obteniedo titulares
            /*String tPN = cuentaBancariaView.getTitulares();
            String[] arrayTitulares = tPN.split(",");
            Chunk clientePNTitulares = new Chunk("Titular(es):");
            for (int i = 0; i < arrayTitulares.length; i++) {
               String string = arrayTitulares[i];
            }*/

            clientePNNombres.setFont(fuenteDatosCliente);
            clientePNDni.setFont(fuenteDatosCliente);
            //clientePNTitulares.setFont(fuenteDatosCliente);
            clientePNFecha.setFont(fuenteDatosCliente);
            tipoCuentaPN.setFont(fuenteDatosCliente);
            tipoMonedaPN.setFont(fuenteDatosCliente);
            fechaEstadoCuenta.setFont(fuenteDatosCliente);

            parrafoSecundario.add(clientePNNombres);
            parrafoSecundario.add(clientePNDni);
            //parrafoSecundario.add(clientePNTitulares);
            parrafoSecundario.add(clientePNFecha);
            parrafoSecundario.add(tipoCuentaPN);
            parrafoSecundario.add(tipoMonedaPN);
            parrafoSecundario.add(fechaEstadoCuenta);

        } else {
            Chunk clientePJNombre = new Chunk("CLIENTE       : " + cuentaBancariaView.getSocio() + "\n");
            Chunk clientePJRuc = new Chunk(cuentaBancariaView.getTipoDocumento() + "               : "
                    + cuentaBancariaView.getNumeroDocumento() + "\n");
            //Chunk clientePJTitulares = new Chunk("TITULAR(ES): " + cuentaBancariaView.getTitulares() + "\n");
            Chunk clientePJFecha = new Chunk("FECHA          : " + fechaActual + "\n\n");

            Chunk tipoCuentaPJ = new Chunk("CUENTA " + cuentaBancariaView.getTipoCuenta() + " N "
                    + cuentaBancariaView.getNumeroCuenta() + "\n");
            Chunk tipoMonedaPJ;

            if (cuentaBancariaView.getIdMoneda().compareTo(BigInteger.ZERO) == 0) {
                tipoMonedaPJ = new Chunk("MONEDA: " + "DOLARES AMERICANOS" + "\n");
            } else if (cuentaBancariaView.getIdMoneda().compareTo(BigInteger.ONE) == 0) {
                tipoMonedaPJ = new Chunk("MONEDA: " + "NUEVOS SOLES" + "\n");
            } else {
                tipoMonedaPJ = new Chunk("MONEDA: " + "EUROS" + "\n");
            }

            Chunk fechaEstadoCuenta = new Chunk("ESTADO DE CUENTA DEL " + fechaDesde + " AL " + fechaHasta);
            //obteniedo titulares
            /*String tPN = cuentaBancariaView.getTitulares();
            String[] arrayTitulares = tPN.split(",");
            Chunk clientePNTitulares = new Chunk("Titular(es):");
            for (int i = 0; i < arrayTitulares.length; i++) {
               String string = arrayTitulares[i];
            }*/

            clientePJNombre.setFont(fuenteDatosCliente);
            clientePJRuc.setFont(fuenteDatosCliente);
            //clientePJTitulares.setFont(fuenteDatosCliente);
            clientePJFecha.setFont(fuenteDatosCliente);
            tipoCuentaPJ.setFont(fuenteDatosCliente);
            tipoMonedaPJ.setFont(fuenteDatosCliente);
            fechaEstadoCuenta.setFont(fuenteDatosCliente);

            parrafoSecundario.add(clientePJNombre);
            parrafoSecundario.add(clientePJRuc);
            //parrafoSecundario.add(clientePJTitulares);
            parrafoSecundario.add(clientePJFecha);
            parrafoSecundario.add(tipoCuentaPJ);
            parrafoSecundario.add(tipoMonedaPJ);
            parrafoSecundario.add(fechaEstadoCuenta);

        }

        document.add(parrafoPrincipal);
        document.add(parrafoSecundario);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Font fontTableCabecera = new Font(FontFamily.UNDEFINED, 9, Font.BOLD);
    Font fontTableCuerpo = new Font(FontFamily.UNDEFINED, 9, Font.NORMAL);

    float[] columnWidths = { 5f, 4f, 2.8f, 10f, 3.5f, 4f, 2.8f };
    PdfPTable table = new PdfPTable(columnWidths);
    table.setWidthPercentage(100);

    PdfPCell cellFechaHoraCabecera = new PdfPCell(new Paragraph("FECHA Y HORA", fontTableCabecera));
    PdfPCell cellTransaccionCabecera = new PdfPCell(new Paragraph("TIPO TRANS.", fontTableCabecera));
    PdfPCell cellOperacionCabecera = new PdfPCell(new Paragraph("NUM. OP.", fontTableCabecera));
    PdfPCell cellReferenciaCabecera = new PdfPCell(new Paragraph("REFERENCIA", fontTableCabecera));
    PdfPCell cellMontoCabecera = new PdfPCell(new Paragraph("MONTO", fontTableCabecera));
    PdfPCell cellSaldoDisponibleCabecera = new PdfPCell(new Paragraph("DISPONIBLE", fontTableCabecera));
    PdfPCell cellEstado = new PdfPCell(new Paragraph("ESTADO", fontTableCabecera));

    table.addCell(cellFechaHoraCabecera);
    table.addCell(cellTransaccionCabecera);
    table.addCell(cellOperacionCabecera);
    table.addCell(cellReferenciaCabecera);
    table.addCell(cellMontoCabecera);
    table.addCell(cellSaldoDisponibleCabecera);
    table.addCell(cellEstado);

    for (EstadocuentaBancariaView estadocuentaBancariaView : list) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        String fecHoraFormat = sdf.format(estadocuentaBancariaView.getHora());

        PdfPCell cellFechaHora = new PdfPCell(new Paragraph(fecHoraFormat, fontTableCuerpo));
        table.addCell(cellFechaHora);
        PdfPCell cellTipoTrasaccion = new PdfPCell(
                new Paragraph(estadocuentaBancariaView.getTipoTransaccionTransferencia(), fontTableCuerpo));
        table.addCell(cellTipoTrasaccion);
        PdfPCell cellNumOperacion = new PdfPCell(
                new Paragraph(estadocuentaBancariaView.getNumeroOperacion().toString(), fontTableCuerpo));
        table.addCell(cellNumOperacion);
        PdfPCell cellReferencia = new PdfPCell(
                new Paragraph(estadocuentaBancariaView.getReferencia(), fontTableCuerpo));
        table.addCell(cellReferencia);
        PdfPCell cellMonto = new PdfPCell(
                new Paragraph(df1.format(estadocuentaBancariaView.getMonto()), fontTableCuerpo));
        table.addCell(cellMonto);
        PdfPCell cellSaldoDisponible = new PdfPCell(
                new Paragraph(df1.format(estadocuentaBancariaView.getSaldoDisponible()), fontTableCuerpo));
        table.addCell(cellSaldoDisponible);
        if (estadocuentaBancariaView.getEstado()) {
            PdfPCell cellEstadoActivo = new PdfPCell(new Paragraph("Activo", fontTableCuerpo));
            table.addCell(cellEstadoActivo);
        } else {
            PdfPCell cellEstadoExtornado = new PdfPCell(new Paragraph("Extornado", fontTableCuerpo));
            table.addCell(cellEstadoExtornado);
        }
    }

    Paragraph saldoDisponible = new Paragraph();
    saldoDisponible.setAlignment(Element.ALIGN_CENTER);
    Chunk textoSaldoDisponible = new Chunk(
            "SALDO DISPONIBLE: " + moneda.getSimbolo() + df1.format(cuentaBancariaView.getSaldo()),
            fontTableCabecera);
    textoSaldoDisponible.setFont(fontTableCabecera);
    saldoDisponible.add(textoSaldoDisponible);

    try {
        document.add(table);
        document.add(saldoDisponible);
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    document.close();

    return Response.ok(outputStream.toByteArray()).type("application/pdf").build();
}

From source file:org.totschnig.myexpenses.model.Account.java

License:Open Source License

private void addMetaData(Document document) {
    document.addTitle(label);
    document.addSubject("Generated by MyExpenses.mobi");
}