Example usage for com.itextpdf.text Document addAuthor

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

Introduction

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

Prototype


public boolean addAuthor(String author) 

Source Link

Document

Adds the author to a Document.

Usage

From source file:com.algoboss.erp.util.report.PDFExporter2.java

License:Apache License

public void export(FacesContext context, DataTable table, String filename) throws IOException {
    try {/*from w  w w . ja va 2s. co  m*/
        Document document = new Document(PageSize.A4);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ByteArrayOutputStream baos2 = new ByteArrayOutputStream(1000000);
        FileOutputStream file = new FileOutputStream("D://Documents//testeLink.pdf");
        PdfWriter pdfWriter = PdfWriter.getInstance(document, file);
        document.open();
        document.addAuthor("Algo Boss");
        document.addCreator("Real's HowTo");
        document.addSubject("Thanks for your support");
        document.addCreationDate();
        document.addTitle("Please read this");
        //XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
        DataTableRenderer render = new DataTableRenderer();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.reset();
        ExternalContext externalContext = context.getExternalContext();
        //BufferedWriter writer = new BufferedWriter(baos2,true);
        OutputStreamWriter writer = new OutputStreamWriter(baos2, "iso-8859-1");

        context.setResponseWriter(context.getRenderKit().createResponseWriter(writer, null, "iso-8859-1"));
        render.encodeEnd(context, table);
        //System.out.println(new String(baos2.toByteArray(), "utf-8"));
        /*writer.write(
         "<link href=\"/ERP/f/javax.faces.resource/theme.css?ln=primefaces-cupertino\" rel=\"stylesheet\" type=\"text/css\">\n"
         + "<link href=\"/ERP/f/javax.faces.resource/primefaces.css?ln=primefaces\" rel=\"stylesheet\" type=\"text/css\">\n"
         + "<link href=\"/ERP/f/javax.faces.resource/schedule/schedule.css?ln=primefaces\" rel=\"stylesheet\" type=\"text/css\">\n"
         + "<meta content=\"application/pdf; charset=UTF-8\" http-equiv=\"Content-Type\">\n"
         + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/ERP/resources/css/default.css\">\n"
         + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/ERP/resources/css/cssLayout.css\">\n"
         + "<title>Plataforma de Gerenciamento</title>");*/
        /*
         externalContext.setResponseHeader("Expires", "0");
         externalContext.setResponseHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
         externalContext.setResponseHeader("Pragma", "public");
         externalContext.setResponseHeader("Content-disposition", "inline;filename=" + filename + ".pdf");
         externalContext.setResponseContentType("application/pdf");
         externalContext.setResponseContentLength(baos.size());
         externalContext.addResponseCookie(Constants.DOWNLOAD_COOKIE, "true", new HashMap<String, Object>());
         OutputStream out = externalContext.getResponseOutputStream();
         baos.writeTo(out);
         externalContext.responseFlushBuffer();     
         */

        response.setContentType("application/pdf");
        response.setHeader("Content-Disposition", "inline;filename=\"" + filename + "\";");

        //String str = "<html><head></head><body>" + new String(baos2.toByteArray()) + "</body></html>";
        String str = "<html><head></head><body>"
                + "<link href=\"/ERP/f/javax.faces.resource/theme.css?ln=primefaces-cupertino\" rel=\"stylesheet\" type=\"text/css\"/>\n"
                + "<link href=\"/ERP/f/javax.faces.resource/primefaces.css?ln=primefaces\" rel=\"stylesheet\" type=\"text/css\"/>\n"
                + "<link href=\"/ERP/f/javax.faces.resource/schedule/schedule.css?ln=primefaces\" rel=\"stylesheet\" type=\"text/css\"/>\n"
                + "<meta content=\"application/pdf; charset=UTF-8\" http-equiv=\"Content-Type\"/>\n"
                + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/ERP/resources/css/default.css\"/>\n"
                + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/ERP/resources/css/cssLayout.css\"/>\n"
                + "<title>Plataforma de Gerenciamento</title>"
                + "<div id='tabView:ad_j_id77' class='ui-datatable ui-widget ui-algo-element ui-algo-element-container data-list'><div class='ui-datatable-header ui-widget-header ui-corner-top'><div id='tabView:ad_j_id77:ad_j_id41' class='ui-panel ui-widget ui-widget-content ui-corner-all ui-algo-element ui-algo-element-container'><div id='tabView:ad_j_id77:ad_j_id41_content' class='ui-panel-content ui-widget-content'><label id='tabView:ad_j_id77:ad_j_id39' class='ui-outputlabel ui-algo-element ui-algo-element-value'>Listagem: FUNCION?RIO</label><label id='tabView:ad_j_id77:ad_j_id40' class='ui-outputlabel ui-algo-element ui-algo-element-value' style='float:right;top:-5px;position: relative;'>Pesquisar: <input id='tabView:ad_j_id77:globalFilter' name='tabView:ad_j_id77:globalFilter' type='text' value='' onkeyup='funcionarioDataTable.filter()' class='ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all ui-algo-element  ui-algo-element-value' /><script id='tabView:ad_j_id77:globalFilter_s' type='text/javascript'>PrimeFaces.cw('InputText','widget_tabView_ad_j_id77_globalFilter',{id:'tabView:ad_j_id77:globalFilter'});</script></label></div></div><script id='tabView:ad_j_id77:ad_j_id41_s' type='text/javascript'>PrimeFaces.cw('Panel','widget_tabView_ad_j_id77_ad_j_id41',{id:'tabView:ad_j_id77:ad_j_id41'});</script></div><div id='tabView:ad_j_id77_paginator_top' class='ui-paginator ui-paginator-top ui-widget-header'><span class='ui-paginator-first ui-state-default ui-corner-all ui-state-disabled'><span class='ui-icon ui-icon-seek-first'>p</span></span><span class='ui-paginator-prev ui-state-default ui-corner-all ui-state-disabled'><span class='ui-icon ui-icon-seek-prev'>p</span></span><span class='ui-paginator-pages'><span class='ui-paginator-page ui-state-default ui-state-active ui-corner-all'>1</span><span class='ui-paginator-page ui-state-default ui-corner-all'>2</span></span><span class='ui-paginator-next ui-state-default ui-corner-all'><span class='ui-icon ui-icon-seek-next'>p</span></span><span class='ui-paginator-last ui-state-default ui-corner-all'><span class='ui-icon ui-icon-seek-end'>p</span></span></div><div class='ui-datatable-tablewrapper'><table role='grid'><thead id='tabView:ad_j_id77_head'><tr role='row'><th id='tabView:ad_j_id77:ad_j_id44' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span>Nome</span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id44:filter' name='tabView:ad_j_id77:ad_j_id44:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id48' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id45'>Usurio</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id48:filter' name='tabView:ad_j_id77:ad_j_id48:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id52' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id49'>Admisso</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id52:filter' name='tabView:ad_j_id77:ad_j_id52:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id56' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader' style='text-align:center;'><span><span id='tabView:ad_j_id77:ad_j_id53'>Afastado</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id56:filter' name='tabView:ad_j_id77:ad_j_id56:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id60' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id57'>Veculo</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id60:filter' name='tabView:ad_j_id77:ad_j_id60:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id64' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id61'>MATR?CULA</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id64:filter' name='tabView:ad_j_id77:ad_j_id64:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id68' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id65'>CPF</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id68:filter' name='tabView:ad_j_id77:ad_j_id68:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id72' class='ui-state-default' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id69'>SAL?RIO</span></span></th><th id='tabView:ad_j_id77:ad_j_id76' class='ui-state-default' role='columnheader' style='text-align:center;'><span>Ao</span></th></tr></thead><tfoot></tfoot><tbody id='tabView:ad_j_id77_data' class='ui-datatable-data ui-widget-content'><tr data-ri='0' data-rk='315' class='ui-widget-content ui-datatable-even' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id42'>MARCUS2</span><a id='tabView:ad_j_id77:0:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id46'>SDASA2</span><a id='tabView:ad_j_id77:0:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id50'>2013/08/15</span><a id='tabView:ad_j_id77:0:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:0:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:0:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id58'>JQV-4404 - GM</span><a id='tabView:ad_j_id77:0:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id62'>123124</span><a id='tabView:ad_j_id77:0:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id66'></span><a id='tabView:ad_j_id77:0:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id70'></span><a id='tabView:ad_j_id77:0:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:0:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:0:ad_j_id74'> | </span><a id='tabView:ad_j_id77:0:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='1' data-rk='318' class='ui-widget-content ui-datatable-odd' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id42'>PAULO</span><a id='tabView:ad_j_id77:1:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id46'>PAULO</span><a id='tabView:ad_j_id77:1:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id50'>2013/08/07</span><a id='tabView:ad_j_id77:1:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:1:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:1:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id58'></span><a id='tabView:ad_j_id77:1:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id62'></span><a id='tabView:ad_j_id77:1:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id66'></span><a id='tabView:ad_j_id77:1:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id70'></span><a id='tabView:ad_j_id77:1:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:1:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:1:ad_j_id74'> | </span><a id='tabView:ad_j_id77:1:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='2' data-rk='319' class='ui-widget-content ui-datatable-even' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id42'>MAIZA</span><a id='tabView:ad_j_id77:2:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id46'>MAIZA</span><a id='tabView:ad_j_id77:2:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id50'></span><a id='tabView:ad_j_id77:2:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:2:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:2:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id58'>BMW - BMW-9999</span><a id='tabView:ad_j_id77:2:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id62'>TESTE123123</span><a id='tabView:ad_j_id77:2:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id66'>123.123.123-12</span><a id='tabView:ad_j_id77:2:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id70'>12.345,67</span><a id='tabView:ad_j_id77:2:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:2:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:2:ad_j_id74'> | </span><a id='tabView:ad_j_id77:2:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='3' data-rk='320' class='ui-widget-content ui-datatable-odd' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id42'>ELAINE</span><a id='tabView:ad_j_id77:3:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id46'>ELAINE</span><a id='tabView:ad_j_id77:3:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id50'>2013/08/22</span><a id='tabView:ad_j_id77:3:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:3:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:3:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id58'>JQV-4404 - GM</span><a id='tabView:ad_j_id77:3:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id62'></span><a id='tabView:ad_j_id77:3:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id66'></span><a id='tabView:ad_j_id77:3:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id70'></span><a id='tabView:ad_j_id77:3:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:3:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:3:ad_j_id74'> | </span><a id='tabView:ad_j_id77:3:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='4' data-rk='321' class='ui-widget-content ui-datatable-even' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id42'>CLEIDE2</span><a id='tabView:ad_j_id77:4:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id46'>CLEIDE DA SILVA</span><a id='tabView:ad_j_id77:4:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id50'>2013/08/19</span><a id='tabView:ad_j_id77:4:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:4:ad_j_id54' class=' ui-icon ui-icon-check ' style='display:inline-block;'>true</span><a id='tabView:ad_j_id77:4:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id58'>EEQEWEQE - QWEQ</span><a id='tabView:ad_j_id77:4:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id62'></span><a id='tabView:ad_j_id77:4:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id66'>123.123.123-12</span><a id='tabView:ad_j_id77:4:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id70'>456,70</span><a id='tabView:ad_j_id77:4:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:4:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:4:ad_j_id74'> | </span><a id='tabView:ad_j_id77:4:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='5' data-rk='322' class='ui-widget-content ui-datatable-odd' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id42'>GABRIELA</span><a id='tabView:ad_j_id77:5:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id46'>GABRIELA</span><a id='tabView:ad_j_id77:5:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id50'>2013/08/20</span><a id='tabView:ad_j_id77:5:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:5:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:5:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id58'></span><a id='tabView:ad_j_id77:5:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id62'></span><a id='tabView:ad_j_id77:5:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id66'></span><a id='tabView:ad_j_id77:5:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id70'></span><a id='tabView:ad_j_id77:5:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:5:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:5:ad_j_id74'> | </span><a id='tabView:ad_j_id77:5:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr>"
                + "</tbody></table></div></div>" + "</body></html>";

        //worker.parseXHtml(pdfWriter, document, new StringReader(str));

        response.setContentLength(baos.size());
        response.getOutputStream().write(baos.toByteArray(), 0, baos.size());
        //System.out.println(str);
        document.close();
        pdfWriter.close();
        baos.close();
        baos2.close();
        file.close();
        FacesContext.getCurrentInstance().responseComplete();
        //writePDFToResponse(context.getExternalContext(), baos, filename);
        //writePDFToResponseNew(context.getExternalContext(), baos, filename);

    } catch (IOException e) {
        throw new IOException(e.getMessage());
    } catch (Exception ex) {
        Logger.getLogger(PDFExporter2.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.algoboss.erp.util.report.PDFExporter2.java

License:Apache License

public void export2(FacesContext context, String htmltable, String filename) throws IOException {
    try {// w w w .j  ava 2  s  .  c o  m
        Document document = new Document(PageSize.A4);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ByteArrayOutputStream baos2 = new ByteArrayOutputStream(1000000);
        FileOutputStream file = new FileOutputStream("D://Documents//testeLink.pdf");
        PdfWriter pdfWriter = PdfWriter.getInstance(document, file);
        document.open();
        document.addAuthor("Algo Boss");
        document.addCreator("Real's HowTo");
        document.addSubject("Thanks for your support");
        document.addCreationDate();
        document.addTitle("Please read this");
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
        DataTableRenderer render = new DataTableRenderer();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.reset();
        ExternalContext externalContext = context.getExternalContext();
        //BufferedWriter writer = new BufferedWriter(baos2,true);
        OutputStreamWriter writer = new OutputStreamWriter(baos2, "iso-8859-1");

        context.setResponseWriter(context.getRenderKit().createResponseWriter(writer, null, "iso-8859-1"));
        //render.encodeEnd(context, table);
        //System.out.println(new String(baos2.toByteArray(), "utf-8"));
        /*writer.write(
         "<link href=\"/ERP/f/javax.faces.resource/theme.css?ln=primefaces-cupertino\" rel=\"stylesheet\" type=\"text/css\">\n"
         + "<link href=\"/ERP/f/javax.faces.resource/primefaces.css?ln=primefaces\" rel=\"stylesheet\" type=\"text/css\">\n"
         + "<link href=\"/ERP/f/javax.faces.resource/schedule/schedule.css?ln=primefaces\" rel=\"stylesheet\" type=\"text/css\">\n"
         + "<meta content=\"application/pdf; charset=UTF-8\" http-equiv=\"Content-Type\">\n"
         + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/ERP/resources/css/default.css\">\n"
         + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/ERP/resources/css/cssLayout.css\">\n"
         + "<title>Plataforma de Gerenciamento</title>");*/
        /*
         externalContext.setResponseHeader("Expires", "0");
         externalContext.setResponseHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
         externalContext.setResponseHeader("Pragma", "public");
         externalContext.setResponseHeader("Content-disposition", "inline;filename=" + filename + ".pdf");
         externalContext.setResponseContentType("application/pdf");
         externalContext.setResponseContentLength(baos.size());
         externalContext.addResponseCookie(Constants.DOWNLOAD_COOKIE, "true", new HashMap<String, Object>());
         OutputStream out = externalContext.getResponseOutputStream();
         baos.writeTo(out);
         externalContext.responseFlushBuffer();     
         */

        response.setContentType("application/pdf");
        response.setHeader("Content-Disposition", "inline;filename=\"" + filename + "\";");

        //String str = "<html><head></head><body>" + new String(baos2.toByteArray()) + "</body></html>";
        String str = "<html><head></head><body>"
                + "<link href=\"/ERP/f/javax.faces.resource/theme.css?ln=primefaces-cupertino\" rel=\"stylesheet\" type=\"text/css\"/>\n"
                + "<link href=\"/ERP/f/javax.faces.resource/primefaces.css?ln=primefaces\" rel=\"stylesheet\" type=\"text/css\"/>\n"
                + "<link href=\"/ERP/f/javax.faces.resource/schedule/schedule.css?ln=primefaces\" rel=\"stylesheet\" type=\"text/css\"/>\n"
                + "<meta content=\"application/pdf; charset=UTF-8\" http-equiv=\"Content-Type\"/>\n"
                + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/ERP/resources/css/default.css\"/>\n"
                + "<link type=\"text/css\" rel=\"stylesheet\" href=\"/ERP/resources/css/cssLayout.css\"/>\n"
                + "<title>Plataforma de Gerenciamento</title>"
                + "<div id='tabView:ad_j_id77' class='ui-datatable ui-widget ui-algo-element ui-algo-element-container data-list'><div class='ui-datatable-header ui-widget-header ui-corner-top'><div id='tabView:ad_j_id77:ad_j_id41' class='ui-panel ui-widget ui-widget-content ui-corner-all ui-algo-element ui-algo-element-container'><div id='tabView:ad_j_id77:ad_j_id41_content' class='ui-panel-content ui-widget-content'><label id='tabView:ad_j_id77:ad_j_id39' class='ui-outputlabel ui-algo-element ui-algo-element-value'>Listagem: FUNCION?RIO</label><label id='tabView:ad_j_id77:ad_j_id40' class='ui-outputlabel ui-algo-element ui-algo-element-value' style='float:right;top:-5px;position: relative;'>Pesquisar: <input id='tabView:ad_j_id77:globalFilter' name='tabView:ad_j_id77:globalFilter' type='text' value='' onkeyup='funcionarioDataTable.filter()' class='ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all ui-algo-element  ui-algo-element-value' /><script id='tabView:ad_j_id77:globalFilter_s' type='text/javascript'>PrimeFaces.cw('InputText','widget_tabView_ad_j_id77_globalFilter',{id:'tabView:ad_j_id77:globalFilter'});</script></label></div></div><script id='tabView:ad_j_id77:ad_j_id41_s' type='text/javascript'>PrimeFaces.cw('Panel','widget_tabView_ad_j_id77_ad_j_id41',{id:'tabView:ad_j_id77:ad_j_id41'});</script></div><div id='tabView:ad_j_id77_paginator_top' class='ui-paginator ui-paginator-top ui-widget-header'><span class='ui-paginator-first ui-state-default ui-corner-all ui-state-disabled'><span class='ui-icon ui-icon-seek-first'>p</span></span><span class='ui-paginator-prev ui-state-default ui-corner-all ui-state-disabled'><span class='ui-icon ui-icon-seek-prev'>p</span></span><span class='ui-paginator-pages'><span class='ui-paginator-page ui-state-default ui-state-active ui-corner-all'>1</span><span class='ui-paginator-page ui-state-default ui-corner-all'>2</span></span><span class='ui-paginator-next ui-state-default ui-corner-all'><span class='ui-icon ui-icon-seek-next'>p</span></span><span class='ui-paginator-last ui-state-default ui-corner-all'><span class='ui-icon ui-icon-seek-end'>p</span></span></div><div class='ui-datatable-tablewrapper'><table role='grid'><thead id='tabView:ad_j_id77_head'><tr role='row'><th id='tabView:ad_j_id77:ad_j_id44' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span>Nome</span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id44:filter' name='tabView:ad_j_id77:ad_j_id44:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id48' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id45'>Usurio</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id48:filter' name='tabView:ad_j_id77:ad_j_id48:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id52' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id49'>Admisso</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id52:filter' name='tabView:ad_j_id77:ad_j_id52:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id56' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader' style='text-align:center;'><span><span id='tabView:ad_j_id77:ad_j_id53'>Afastado</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id56:filter' name='tabView:ad_j_id77:ad_j_id56:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id60' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id57'>Veculo</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id60:filter' name='tabView:ad_j_id77:ad_j_id60:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id64' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id61'>MATR?CULA</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id64:filter' name='tabView:ad_j_id77:ad_j_id64:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id68' class='ui-state-default ui-sortable-column ui-filter-column' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id65'>CPF</span></span><span class='ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s'></span><input id='tabView:ad_j_id77:ad_j_id68:filter' name='tabView:ad_j_id77:ad_j_id68:filter' class='ui-column-filter ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all' value='' autocomplete='off' style='display:none;' /></th><th id='tabView:ad_j_id77:ad_j_id72' class='ui-state-default' role='columnheader'><span><span id='tabView:ad_j_id77:ad_j_id69'>SAL?RIO</span></span></th><th id='tabView:ad_j_id77:ad_j_id76' class='ui-state-default' role='columnheader' style='text-align:center;'><span>Ao</span></th></tr></thead><tfoot></tfoot><tbody id='tabView:ad_j_id77_data' class='ui-datatable-data ui-widget-content'><tr data-ri='0' data-rk='315' class='ui-widget-content ui-datatable-even' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id42'>MARCUS2</span><a id='tabView:ad_j_id77:0:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id46'>SDASA2</span><a id='tabView:ad_j_id77:0:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id50'>2013/08/15</span><a id='tabView:ad_j_id77:0:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:0:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:0:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id58'>JQV-4404 - GM</span><a id='tabView:ad_j_id77:0:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id62'>123124</span><a id='tabView:ad_j_id77:0:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id66'></span><a id='tabView:ad_j_id77:0:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:0:ad_j_id70'></span><a id='tabView:ad_j_id77:0:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:0:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:0:ad_j_id74'> | </span><a id='tabView:ad_j_id77:0:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:0:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='1' data-rk='318' class='ui-widget-content ui-datatable-odd' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id42'>PAULO</span><a id='tabView:ad_j_id77:1:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id46'>PAULO</span><a id='tabView:ad_j_id77:1:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id50'>2013/08/07</span><a id='tabView:ad_j_id77:1:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:1:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:1:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id58'></span><a id='tabView:ad_j_id77:1:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id62'></span><a id='tabView:ad_j_id77:1:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id66'></span><a id='tabView:ad_j_id77:1:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:1:ad_j_id70'></span><a id='tabView:ad_j_id77:1:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:1:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:1:ad_j_id74'> | </span><a id='tabView:ad_j_id77:1:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:1:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='2' data-rk='319' class='ui-widget-content ui-datatable-even' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id42'>MAIZA</span><a id='tabView:ad_j_id77:2:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id46'>MAIZA</span><a id='tabView:ad_j_id77:2:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id50'></span><a id='tabView:ad_j_id77:2:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:2:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:2:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id58'>BMW - BMW-9999</span><a id='tabView:ad_j_id77:2:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id62'>TESTE123123</span><a id='tabView:ad_j_id77:2:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id66'>123.123.123-12</span><a id='tabView:ad_j_id77:2:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:2:ad_j_id70'>12.345,67</span><a id='tabView:ad_j_id77:2:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:2:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:2:ad_j_id74'> | </span><a id='tabView:ad_j_id77:2:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:2:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='3' data-rk='320' class='ui-widget-content ui-datatable-odd' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id42'>ELAINE</span><a id='tabView:ad_j_id77:3:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id46'>ELAINE</span><a id='tabView:ad_j_id77:3:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id50'>2013/08/22</span><a id='tabView:ad_j_id77:3:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:3:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:3:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id58'>JQV-4404 - GM</span><a id='tabView:ad_j_id77:3:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id62'></span><a id='tabView:ad_j_id77:3:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id66'></span><a id='tabView:ad_j_id77:3:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:3:ad_j_id70'></span><a id='tabView:ad_j_id77:3:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:3:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:3:ad_j_id74'> | </span><a id='tabView:ad_j_id77:3:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:3:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='4' data-rk='321' class='ui-widget-content ui-datatable-even' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id42'>CLEIDE2</span><a id='tabView:ad_j_id77:4:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id46'>CLEIDE DA SILVA</span><a id='tabView:ad_j_id77:4:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id50'>2013/08/19</span><a id='tabView:ad_j_id77:4:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:4:ad_j_id54' class=' ui-icon ui-icon-check ' style='display:inline-block;'>true</span><a id='tabView:ad_j_id77:4:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id58'>EEQEWEQE - QWEQ</span><a id='tabView:ad_j_id77:4:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id62'></span><a id='tabView:ad_j_id77:4:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id66'>123.123.123-12</span><a id='tabView:ad_j_id77:4:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:4:ad_j_id70'>456,70</span><a id='tabView:ad_j_id77:4:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:4:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:4:ad_j_id74'> | </span><a id='tabView:ad_j_id77:4:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:4:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr><tr data-ri='5' data-rk='322' class='ui-widget-content ui-datatable-odd' role='row' aria-selected='false'><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id42'>GABRIELA</span><a id='tabView:ad_j_id77:5:ad_j_id43' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id43',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id46'>GABRIELA</span><a id='tabView:ad_j_id77:5:ad_j_id47' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id47',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id50'>2013/08/20</span><a id='tabView:ad_j_id77:5:ad_j_id51' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id51',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><span id='tabView:ad_j_id77:5:ad_j_id54' class=' ui-icon ui-icon-cancel ' style='display:inline-block;'>false</span><a id='tabView:ad_j_id77:5:ad_j_id55' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id55',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id58'></span><a id='tabView:ad_j_id77:5:ad_j_id59' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id59',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id62'></span><a id='tabView:ad_j_id77:5:ad_j_id63' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id63',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id66'></span><a id='tabView:ad_j_id77:5:ad_j_id67' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id67',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell'><span id='tabView:ad_j_id77:5:ad_j_id70'></span><a id='tabView:ad_j_id77:5:ad_j_id71' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id71',update:'tabView:j_idt233'});return false;'></a></td><td role='gridcell' style='text-align:center;'><a id='tabView:ad_j_id77:5:ad_j_id73' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id73',update:'tabView:j_idt233'});return false;'>Editar</a><span id='tabView:ad_j_id77:5:ad_j_id74'> | </span><a id='tabView:ad_j_id77:5:ad_j_id75' href='#' class='ui-commandlink ui-widget' onclick='PrimeFaces.ab({source:'tabView:ad_j_id77:5:ad_j_id75',update:'tabView:j_idt233'});return false;'>Excluir</a></td></tr>"
                + "</tbody></table></div></div>" + "</body></html>";
        ElementHandler eh = new ElementHandler() {
            public List<Writable> elements = new ArrayList<Writable>();

            @Override
            public void add(Writable wrtbl) {
                if (wrtbl instanceof WritableElement) {
                    elements.add(wrtbl);
                }
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        };
        //worker.parseXHtml(eh, new StringReader(htmltable));
        worker.parseXHtml(pdfWriter, document, new StringReader(htmltable));

        response.setContentLength(baos.size());
        response.getOutputStream().write(baos.toByteArray(), 0, baos.size());
        //System.out.println(str);
        document.close();
        pdfWriter.close();
        baos.close();
        baos2.close();
        file.close();
        FacesContext.getCurrentInstance().responseComplete();
        //writePDFToResponse(context.getExternalContext(), baos, filename);
        //writePDFToResponseNew(context.getExternalContext(), baos, filename);

    } catch (IOException e) {
        throw new IOException(e.getMessage());
    } catch (Exception ex) {
        Logger.getLogger(PDFExporter2.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.alokomkar.aliensonearth.report.AbstractPdfReport.java

/**
 * virtual method to add meta data for the page
 * @param document Document where meta data need to be added.
 *///from   w ww . j  a v  a  2s  . c  om
public void addPageMetaData(Document document) {

    String title = getPageTitle();
    String subjct = getPageSubject();

    if (title != null)
        document.addTitle(title);
    if (subjct != null)
        document.addSubject(subjct);

    document.addAuthor(ProjectMessages.REPORT_GENERATOR);
    document.addCreator(ProjectMessages.REPORT_CREATOR);
    document.addCreationDate();

    addLineSeperator(document);

}

From source file:com.auskeny.ems.print.PdfCreator.java

public static void addMetaData(Document document) {
    document.addTitle("My first PDF");
    document.addSubject("Using iText");
    document.addKeywords("Java, PDF, iText");
    document.addAuthor("Lars Vogel");
    document.addCreator("Lars Vogel");
}

From source file:com.automaster.autoview.server.servlet.PdfServlet.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {//from   w  w w. j av a  2  s.c  om
        this.dataAtual = new Date(System.currentTimeMillis());
        this.cnpjUn = null;

        String tempoDecorrido = " 0";
        int codVeiculo = Integer.parseInt(request.getParameter("cod"));
        String placa = request.getParameter("placa");
        Timestamp dataInicio = new Timestamp(Long.parseLong(request.getParameter("dataInicio")));
        Timestamp dataFim = new Timestamp(Long.parseLong(request.getParameter("dataFim")));

        TimeZone timeZonePadrao = TimeZone.getTimeZone(ZoneId.of("-3"));
        //System.out.println("Time zone : " + timeZonePadrao);

        ZzzPosPlacaVeiculoDAO zzzPosPlacaVeiculoDAO = new ZzzPosPlacaVeiculoDAO();
        VeiculoDAO veiculoDAO = new VeiculoDAO();
        TreeMap<String, String> veiculo = veiculoDAO.buscarVeiculoPorCodigo(codVeiculo);
        placa = veiculo.get("placa");
        //System.out.println("PLACA: "+veiculo.get("placa"));
        ArrayList<TreeMap<String, String>> posicoes = zzzPosPlacaVeiculoDAO
                .buscarPosicoesPorIntervaloData(placa, dataInicio, dataFim);
        int codCliente = Integer.parseInt(veiculo.get("clienteCodCliente"));
        //System.out.println("COD CLIENTE: "+codCliente);
        ClienteDAO clienteDAO = null;
        clienteDAO = new ClienteDAO();
        TreeMap<String, String> infoClienteUnidade = clienteDAO.buscarPorCodClienteSimplificado(codCliente);
        // Get the text that will be added to the PDF
        // step 1
        Document document = new Document();
        document.addHeader("Adriano", "AutoMaster");
        document.addCreator("Adriano Vale");
        document.addAuthor("Adriano Vale");
        document.addCreationDate();
        document.setPageSize(PageSize.A4.rotate());
        // step 2
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        TableHeader event = new TableHeader();
        writer.setPageEvent(event);
        // step 3
        document.open();
        // step 4
        //getServletContext().getRealPath("/")
        String url = getServletContext().getRealPath("/");
        //"D:\\Users\\Adriano\\Documents\\NetBeansProjects\\JRGWT\\web\\imagens\\logo.jpg"
        Image logo = Image.getInstance(url + "/imagens/logo.jpg");
        logo.setAlignment(Element.ALIGN_CENTER);

        Paragraph titulo = new Paragraph("Relatrio de Posies",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 20, Font.BOLD));
        titulo.setAlignment(Element.ALIGN_CENTER);

        Paragraph tituloPlaca = new Paragraph("Veculo: " + placa,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD));
        tituloPlaca.setAlignment(Element.ALIGN_CENTER);

        SimpleDateFormat dataFormatadaCabecalho = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        dataFormatadaCabecalho.setTimeZone(timeZonePadrao);

        Date dataHoraInicio0 = new Date(Long.parseLong(request.getParameter("dataInicio")));
        Date dataHoraFim0 = new Date(Long.parseLong(request.getParameter("dataFim")));
        Paragraph periodo = new Paragraph(
                "Perodo: De: " + dataFormatadaCabecalho.format(dataHoraInicio0) + " at: "
                        + dataFormatadaCabecalho.format(dataHoraFim0),
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD));
        periodo.setSpacingAfter(10.0f);
        periodo.setAlignment(Element.ALIGN_CENTER);
        //PdfPTable tabela = new PdfPTable(new float[]{0.11f, 0.095f, 0.06f, 0.065f, 0.085f, 0.06f, 0.04f, 0.065f, 0.055f, 0.06f, 0.24f, 0.065f});
        PdfPTable tabela = new PdfPTable(new float[] { 0.07f, 0.045f, 0.045f, 0.27f });
        tabela.setWidthPercentage(98.0f);
        tabela.setHorizontalAlignment(Element.ALIGN_CENTER);
        PdfPCell tituloData = new PdfPCell(Phrase.getInstance("Data e Hora"));
        tituloData.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(tituloData);
        //tabela.addCell("Data e hora");
        PdfPCell tituloVel = new PdfPCell(Phrase.getInstance("Velocidade"));
        tituloVel.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(tituloVel);
        PdfPCell tituloIgn = new PdfPCell(Phrase.getInstance("Ignio"));
        tituloIgn.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(tituloIgn);
        //tabela.addCell("Latitude");
        //tabela.addCell("Longitude");
        //tabela.addCell("Satlite");
        //tabela.addCell("GPS");
        //tabela.addCell("Entrada");
        //tabela.addCell("Sada");
        //tabela.addCell("Evento");
        PdfPCell tituloEnd = new PdfPCell(Phrase.getInstance("Endereo"));
        tituloEnd.setHorizontalAlignment(Element.ALIGN_CENTER);
        tabela.addCell(tituloEnd);
        //tabela.addCell("Direo");
        double latAnt = 0;
        double lonAnt = 0;
        double latAtual = 0;
        double lonAtual = 0;
        double distanciaTotal = 0;
        double distancia = 0;
        event.setHeader("AutoMaster");

        for (int i = 0; i < posicoes.size(); i++) {
            //for (int col = 0; col < posicoes.get(i).size(); col++) {
            if (i == 0) {
                distancia = 0;
                //System.out.println("linha 00 - PDF");
            } else {
                //System.out.println("linha 01 - PDF");
                latAnt = Double.parseDouble(posicoes.get(i - 1).get("lat"));
                lonAnt = Double.parseDouble(posicoes.get(i - 1).get("lon"));
                latAtual = Double.parseDouble(posicoes.get(i).get("lat"));
                lonAtual = Double.parseDouble(posicoes.get(i).get("lon"));
                //System.out.println("linha 02 - PDF");
                if (latAnt == latAtual && lonAnt == lonAtual) {
                    distancia = 0;
                } else {
                    distancia = caculaDistanciaEntreDoisPontos(latAnt, lonAnt, latAtual, lonAtual);
                    //System.out.println("linha 03 - PDF");
                }

            }
            distanciaTotal = distanciaTotal + distancia;
            //System.out.println("linha 04 - PDF");
            //TimeZone.setDefault(timeZoneMundial);
            Date dataHora0 = new Date(Long.parseLong(posicoes.get(i).get("dataHora")));
            //System.out.println("dataHora0 : "+dataHora0.toString());
            //TimeZone.setDefault(timeZoneCliente);
            //Date dataHora = new Date(dataHora0.getTime());
            SimpleDateFormat dataFormatada = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            dataFormatada.setTimeZone(timeZonePadrao);
            //System.out.println("dataFormatada : "+dataFormatada);
            PdfPCell celData = new PdfPCell(Phrase.getInstance(dataFormatada.format(dataHora0)));
            celData.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabela.addCell(celData);
            //tabela.addCell(dataFormatada);
            PdfPCell celVel = new PdfPCell(Phrase.getInstance(posicoes.get(i).get("vel")));
            celVel.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabela.addCell(celVel);
            PdfPCell celIgn = new PdfPCell(Phrase
                    .getInstance(posicoes.get(i).get("ign").equalsIgnoreCase("True") ? "Ligada" : "Desligada"));
            celIgn.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabela.addCell(celIgn);
            //tabela.addCell(posicoes.get(i).get("lat"));
            //tabela.addCell(posicoes.get(i).get("lon"));
            //tabela.addCell(posicoes.get(i).get("sat"));
            //tabela.addCell(posicoes.get(i).get("gps"));
            //tabela.addCell(posicoes.get(i).get("entrada"));
            //tabela.addCell(posicoes.get(i).get("saida"));
            //tabela.addCell(posicoes.get(i).get("evento"));
            PdfPCell celEnd = new PdfPCell(
                    Phrase.getInstance(posicoes.get(i).get("endereco") == null ? "Sem endereo"
                            : posicoes.get(i).get("endereco")));
            celEnd.setHorizontalAlignment(Element.ALIGN_CENTER);
            tabela.addCell(celEnd);
            //tabela.addCell(posicoes.get(i).get("direcao"));
            //}
        }
        //System.out.println("linha 05 - PDF");
        tempoDecorrido = calculaDatas(Long.parseLong(posicoes.get(0).get("dataHora")),
                Long.parseLong(posicoes.get(posicoes.size() - 1).get("dataHora")));
        //System.out.println("linha 06 - PDF");
        int index = 0;
        String kms = "0";
        String m = "";
        double metros = 0;
        //System.out.println("linha 07 - PDF");
        if (distanciaTotal > 0) {
            //System.out.println("linha 08 - PDF");
            BigDecimal decimalFormatado = new BigDecimal(distanciaTotal).setScale(2, RoundingMode.HALF_EVEN);
            //System.out.println("linha 09 - PDF");
            index = String.valueOf(decimalFormatado).indexOf(".");
            kms = String.valueOf(decimalFormatado).substring(0, index);
            m = "0" + (String.valueOf(decimalFormatado).substring(index));
            metros = Double.parseDouble(m) * 1000;
            //System.out.println("linha 10 - PDF");
        }
        /*document.add(new Paragraph(String.format(
         "You have submitted the following text using the %s method:",
         request.getMethod())));
         document.add(new Paragraph(text));*/
        //System.out.println("linha 11 - PDF");
        Paragraph kilometragem = new Paragraph(
                "Percorridos: " + kms + " KM e " + String.valueOf(metros) + " metros. Tempo: " + tempoDecorrido,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 16, Font.BOLD));
        //System.out.println("linha 12 - PDF");
        periodo.setSpacingAfter(10.0f);
        periodo.setAlignment(Element.ALIGN_CENTER);
        // step 5
        document.add(logo);
        document.add(titulo);
        document.add(tituloPlaca);
        document.add(periodo);
        document.add(tabela);
        document.add(kilometragem);
        String dia = new SimpleDateFormat("dd").format(dataAtual);
        String ano = new SimpleDateFormat("yyyy").format(dataAtual);
        int mes = dataAtual.getMonth();
        String mesEscrito = null;
        switch (mes) {
        case 0:
            mesEscrito = "janeiro";
            break;
        case 1:
            mesEscrito = "fevereiro";
            break;
        case 2:
            mesEscrito = "maro";
            break;
        case 3:
            mesEscrito = "abril";
            break;
        case 4:
            mesEscrito = "maio";
            break;
        case 5:
            mesEscrito = "junho";
            break;
        case 6:
            mesEscrito = "julho";
            break;
        case 7:
            mesEscrito = "agosto";
            break;
        case 8:
            mesEscrito = "setembro";
            break;
        case 9:
            mesEscrito = "outubro";
            break;
        case 10:
            mesEscrito = "novembro";
            break;
        case 11:
            mesEscrito = "dezembro";
            break;
        }
        String textRodape = infoClienteUnidade.get("cidadeUnidade") + " , "
                + infoClienteUnidade.get("estadoUnidade") + "    " + dia + "  de  " + mesEscrito + "  de  "
                + ano + ".";
        Paragraph localData = new Paragraph(textRodape,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.PLAIN));
        localData.setAlignment(Element.ALIGN_RIGHT);
        localData.setSpacingBefore(30.0f);
        localData.setSpacingAfter(10.0f);
        document.add(localData);
        Image assinatura = Image.getInstance(url + "/imagens/assinatura.png");
        assinatura.setAlignment(Element.ALIGN_CENTER);
        assinatura.scaleAbsolute(185, 91);
        document.add(assinatura);
        Paragraph infoEmpresa1 = new Paragraph("AUTO MASTER LTDA",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD));
        infoEmpresa1.setAlignment(Element.ALIGN_CENTER);
        infoEmpresa1.setSpacingAfter(1f);
        document.add(infoEmpresa1);
        Paragraph infoEmpresa2 = new Paragraph("___________________________",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD));
        infoEmpresa2.setAlignment(Element.ALIGN_CENTER);
        document.add(infoEmpresa2);
        String cnpjEmpresa = formataCNPJ(infoClienteUnidade.get("cnpjUnidade"));
        Paragraph infoEmpresa3 = new Paragraph(cnpjEmpresa,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 12, Font.BOLD));
        infoEmpresa3.setAlignment(Element.ALIGN_CENTER);
        document.add(infoEmpresa3);
        document.close();
        // setting some response headers
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        response.setHeader("Pragma", "public");
        // setting the content type
        response.setContentType("application/pdf");
        response.addHeader("Content-Disposition", "attachment; filename=Historico-" + placa + ".pdf");
        // the contentlength
        response.setContentLength(baos.size());
        // write ByteArrayOutputStream to the ServletOutputStream
        OutputStream os = response.getOutputStream();
        baos.writeTo(os);
        os.flush();
        os.close();
    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
    //        response.setContentType("text/html;charset=UTF-8");
    //        try (PrintWriter out = response.getWriter()) {
    //            /* TODO output your page here. You may use following sample code. */
    //            out.println("<!DOCTYPE html>");
    //            out.println("<html>");
    //            out.println("<head>");
    //            out.println("<title>Servlet PdfServlet</title>");            
    //            out.println("</head>");
    //            out.println("<body>");
    //            out.println("<h1>Servlet PdfServlet at " + request.getContextPath() + "</h1>");
    //            out.println("</body>");
    //            out.println("</html>");
    //        }
}

From source file:com.bdaum.zoom.email.internal.job.PdfJob.java

License:Open Source License

private Document createDocument() {
    Document document = new Document();
    document.addCreationDate();//ww  w.  j a va  2 s .  c  om
    document.addCreator(Constants.APPLICATION_NAME);
    document.addAuthor(System.getProperty("user.name")); //$NON-NLS-1$
    document.setPageSize(format);
    document.setMargins(Math.max(0, leftMargins - horizontalGap / 2),
            Math.max(0, rightMargins - horizontalGap / 2), topMargins, 0);
    document.setMarginMirroring(layout.getFacingPages());
    return document;
}

From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java

License:Open Source License

private static Document createDocument() {
    Document document = new Document();
    document.addCreationDate();// w  w  w. j  a v  a2s  .  c o m
    document.addCreator(Constants.APPLICATION_NAME);
    document.addAuthor(System.getProperty("user.name")); //$NON-NLS-1$
    document.setPageSize(PageSize.A4);
    document.setMargins(20, 10, 10, 10);
    return document;
}

From source file:com.debashubham.dumpy.ChainageCalcActivity.java

private void addMetaData(Document document) {
    document.addTitle("Report generated on:" + formattedDate);
    document.addSubject("Dumpy Level Report");
    document.addKeywords("Dumpy Level, PDF");
    document.addAuthor("Dumpy");
    document.addCreator("Dumpy");
}

From source file:com.dexter.fms.mbean.ReportsMBean.java

@SuppressWarnings("unchecked")
public void createPDF(int type, String filename, int pageType) {
    try {//  ww  w  .j ava 2  s.  co  m
        FacesContext context = FacesContext.getCurrentInstance();
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FMS");
        document.addCreationDate();
        document.addCreator("FMS");
        document.addSubject("Report");
        document.addTitle(getReport_title());

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("partner", dashBean.getUser().getPartner());
        GeneralDAO gDAO = new GeneralDAO();
        Object pSettingsObj = gDAO.search("PartnerSetting", params);
        PartnerSetting setting = null;
        if (pSettingsObj != null) {
            Vector<PartnerSetting> pSettingsList = (Vector<PartnerSetting>) pSettingsObj;
            for (PartnerSetting e : pSettingsList) {
                setting = e;
            }
        }
        gDAO.destroy();

        PdfPCell c = null;
        if (setting != null && setting.getLogo() != null) {
            Image logoImg = Image.getInstance(setting.getLogo());
            logoImg.scaleToFit(212, 51);
            c = new PdfPCell(logoImg);
        } else
            c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(getReport_title(), font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (getReport_start_dt() != null && getReport_end_dt() != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("From " + getReport_start_dt() + " to " + getReport_end_dt(), font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = exportPDFTable(type);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();
        String fileName = filename + ".pdf";

        writeFileToResponse(context.getExternalContext(), baos, fileName, "application/pdf");

        context.responseComplete();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dexter.fuelcard.mbean.UtilMBean.java

public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType,
        String chargeAmount, String total) {
    try {/*from w ww.ja va  2s  . c o m*/
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FUELCARD");
        document.addCreationDate();
        document.addCreator("FUELCARD");
        document.addSubject("Invoice");
        document.addTitle(title);

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        PdfPCell c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(title, font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (dateperiod != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("For " + dateperiod, font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = new PdfPTable(4);
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license
        pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting

        if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) {
            pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting
        } else {
            pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting
        }
        //pdfTable.addCell(new Paragraph("Description", font)); // the 
        pdfTable.addCell(new Paragraph("Amount Due", font));

        font = new Font(helvetica, 8, Font.NORMAL);
        pdfTable.addCell(new Paragraph(chargeType, font));
        pdfTable.addCell(new Paragraph(chargeAmount, font));
        pdfTable.addCell(new Paragraph(total, font));
        pdfTable.addCell(new Paragraph(amount, font));

        pdfTable.setWidthPercentage(100);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();

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