Package com.itextpdf.text

Examples of com.itextpdf.text.Document


      IOUtils.closeQuietly(out);
    }
  }

  private static Document initialPDF() {
    Document document = new Document();
    document.setMargins(0, 0, 0, 0);
    return document;
  }
View Full Code Here


  }

  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
      Document document = new Document();
      PdfWriter.getInstance(document, response.getOutputStream());

      document.addCreationDate();
      document.open();

      final String module;
      final long id;

      String values[] = request.getParameterValues("m");
      if (null != values && 1 == values.length) {
        module = values[0];
      } else {
        module = null;
      }
      values = request.getParameterValues("id");
      if (null != values && 1 == values.length) {
        id = Long.parseLong(values[0]);
      } else {
        id = -1;
      }
      response.setContentType("application/pdf");
      response.setHeader("Content-Disposition", "inline; filename=" + module + ".pdf"); // TODO add more information about the entity into the filename.

      final Dto dto = readService.get(module, id);
      final ModuleDto moduleDto = config.getModuleDtos().get(module);

      document.add(new Paragraph(moduleDto.getTitle(), new Font(FontFamily.HELVETICA, 20, Font.BOLD)));
     
      for (final Entry<String, Serializable> entry : dto.getAllData().entrySet()) {
        if ("id".equals(entry.getKey()) || entry.getKey().endsWith("_resolved")) {
          continue;
        }
        final String label = moduleDto.getFieldById(entry.getKey()).getLabel();
        final String value;
       
        if (dto.getAllData().containsKey(entry.getKey() + "_resolved")) {
          final Dto resolved = (Dto) dto.getAllData().get(entry.getKey() + "_resolved");
          value = String.valueOf(resolved.get("name"));
        } else {
          value = null == entry.getValue() ? "-" : String.valueOf(entry.getValue());
        }

        if (entry.getValue() instanceof List<?>) {
          if (!((List<?>)entry.getValue() ).isEmpty()) {
            final List<Dto> list = (List<Dto>) entry.getValue();
            final ModuleDto listModuleDto = config.getModuleDtos().get(list.get(0).getModule());
           
            PdfPTable table = new PdfPTable(listModuleDto.getListFieldIds().length);
            table.setHeaderRows(1);

            for (final String col: listModuleDto.getListFieldIds()) {
              final String colHeader = listModuleDto.getFieldById(col).getLabel();
              table.addCell(new Phrase(colHeader, new Font(FontFamily.HELVETICA, 12, Font.BOLD)));
            }
           
            for (int i = 0; i < list.size(); i++) {
              for (final String col: listModuleDto.getListFieldIds()) {
                final String colValue;
               
                if (list.get(i).getAllData().containsKey(col + "_resolved")) {
                  final Dto resolved = (Dto) list.get(i).get(col + "_resolved");
                  colValue = String.valueOf(resolved.get("name"));
                } else {
                  colValue = String.valueOf(list.get(i).get(col));
                }

                if ("true".equals(colValue) || "false".equals(colValue)) {
                  // final RadioCheckField r = new RadioCheckField(writer, new Rectangle(10, 10, 20, 20), "asd", "v1");
                  // r.setChecked("true".equals(colValue));
                  table.addCell(new Phrase("true".equals(colValue) ? "X" : ""));
                } else {
                  table.addCell(new Phrase(colValue));
                }
              }
            }
           
            document.add(new Chunk(label, new Font(FontFamily.HELVETICA, 12, Font.BOLD)));
            document.add(new Chunk(Chunk.NEWLINE));
            document.add(table);
            document.add(new Chunk(Chunk.NEWLINE));
          }
        } else {
          document.add(getAttributeParagraph(label, value));
        }
      }

      document.close();
    } catch (DocumentException ex) {
      ex.printStackTrace();
    }
  }
View Full Code Here

   * Creates an instance of the concatenation class.
   * @param os  the OutputStream for the PDF document
   * @param smart  do we want PdfCopy to detect redundant content?
   */
  public PdfConcatenate(OutputStream os, boolean smart) throws DocumentException {
    document = new Document();
    if (smart)
      copy = new PdfSmartCopy(document, os);
    else
      copy = new PdfCopy(document, os)
  }
View Full Code Here

*
* @author Gustavo
*/
public class GerarRelatorioPDF {
    public void PDF(String ID, int tipo) throws Exception {
        Document doc = null;
        OutputStream os = null;
        try {
            doc = new Document(PageSize.A4, 72, 72, 72, 72); //cria o documento tamanho A4, margens de 2,54cm

            os = new FileOutputStream("Relatório iCards.pdf");//cria a stream de saída

            PdfWriter.getInstance(doc, os); //associa a stream de saída ao

            doc.open(); //abre o documento
            Font fonte2 = new Font(FontFamily.HELVETICA, 24,Font.BOLD);
            Font fonte = new Font(FontFamily.HELVETICA, 16,Font.BOLD);
            Paragraph title = new Paragraph("Relatório iCards",fonte2); //adiciona o texto ao PDF
            title.setAlignment(Element.ALIGN_CENTER);
            title.setSpacingAfter(5);
            Paragraph linha = new Paragraph("__________________________________________________",fonte);
            doc.add(linha);
            doc.add(title);
           
            GerenciarDB banco = new GerenciarDB();
           
            if (tipo==0) { //Usuario
                String[][] mtx = banco.getExtratoUsuario(ID);
                int i;
                PdfPTable table = new PdfPTable(3);
               
                Paragraph head = new Paragraph("Nome: "+banco.getUsername(ID) ,fonte);
                head.setSpacingAfter(20);
                doc.add(head);
               
                for (i=(mtx[0].length)-1;i>=0;i--){
                    table.addCell(mtx[0][i]);
                    table.addCell(mtx[1][i]);
                    table.addCell(mtx[2][i]);
               }
               doc.add(table);
               Paragraph fim = new Paragraph("Saldo total: R$ "+banco.getSaldoCartaoDB(ID) ,fonte);
               doc.add(fim);
             
            } else if (tipo==1) { //Estabelecimento
                String[][] mtx = banco.getExtratoEst(ID);
                int j;
                PdfPTable table = new PdfPTable(2);
               
                Paragraph head = new Paragraph("Nome: "+banco.getEstabelecimentoDB(ID) ,fonte);
                head.setSpacingAfter(20);
                doc.add(head);

                for (j=(mtx[0].length)-1;j>=0;j--){
                    table.addCell(mtx[0][j]);
                    table.addCell(mtx[2][j]);
                }
                doc.add(table);
                Paragraph fim = new Paragraph("Receita total: R$ "+banco.getVendaTotalEstabelecimentoDB(ID) ,fonte);
                doc.add(fim);
            } else {
                System.out.println("Relatório não gerado");
            }
            doc.add(linha);

        } finally {
            if (doc != null) {
                doc.close();
            }
            if (os != null) {
               os.close();
            }
        }
View Full Code Here

            int total = reader.getNumberOfPages();
            System.out.println("There are " + total + " pages in the original file.");
            Rectangle pageSize = reader.getPageSize(1);
            Rectangle newSize = new Rectangle(pageSize.getWidth()*2, pageSize.getHeight());
            // step 1: creation of a document-object
            Document document = new Document(newSize, 0, 0, 0, 0);
            // step 2: we create a writer that listens to the document
            ByteArrayOutputStream tmp = new ByteArrayOutputStream();
            PdfWriter writer = PdfWriter.getInstance(document, tmp);
            writer.setFullCompression();
            // step 3: we open the document
            document.open();
            // step 4: adding the content
            PdfContentByte cb = writer.getDirectContent();
            PdfImportedPage page;
            float offsetX;
            for (int p = 1; p <= total; p++) {
                offsetX = 0;
                if (p % 2 != 0) {
                    document.newPage();
                } else {
                    offsetX = pageSize.getWidth();
                }
                page = writer.getImportedPage(reader, p);
                cb.addTemplate(page, offsetX, 0);
            }
            // step 5: we close the document
            document.close();

            PdfReader reader2 = new PdfReader(new ByteArrayInputStream(tmp.toByteArray()));
            PdfStamper stamper = new PdfStamper(reader2, new FileOutputStream(dest));
            stamper.setMoreInfo(reader.getInfo());
            List<HashMap<String, Object>> outlines = SimpleBookmark.getBookmark(reader);
View Full Code Here

  }
  public void open(String filename, String pagesize, float left, float right, float top, float bottom) throws Exception {
    Rectangle psize = PageSize.A4;
    if ("A5".equals(pagesize)) psize = PageSize.A5;
    if ("A3".equals(pagesize)) psize = PageSize.A3;
    doc = new Document(psize);
    doc.setMargins(left, right, top, bottom); // left, right, top, bottom
    writer = PdfWriter.getInstance(doc, new FileOutputStream(filename));
    doc.open();
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);     
    cb = writer.getDirectContent();   
View Full Code Here

  public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {
    try {

      PdfPTable tabla = null;
      Document document = new Document();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      PdfWriter.getInstance(document, baos);

      document.open();

      List<BitacoraLN> bitacoraList = BitacoraLNDAO
          .obtenerNovedadesAyer();

      if (!bitacoraList.isEmpty()) {

        Iterator<BitacoraLN> iteNovedades = bitacoraList.iterator();

        String[] headers = new String[] { "Fecha", "Equipo",
            "Comentario" };
        tabla = new PdfPTable(headers.length);
        for (int i = 0; i < headers.length; i++) {
          String header = headers[i];
          PdfPCell cell = new PdfPCell();
          cell.setGrayFill(0.9f);
          cell.setPhrase(new Phrase(header.toUpperCase(), new Font(
              FontFamily.HELVETICA, 10, Font.BOLD)));
          tabla.addCell(cell);
        }
        tabla.completeRow();

        while (iteNovedades.hasNext()) {
          BitacoraLN falla = iteNovedades.next();
          PdfPCell cell0 = new PdfPCell();
          PdfPCell cell1 = new PdfPCell();
          PdfPCell cell2 = new PdfPCell();

          SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
          String fecha = sdf.format(falla.getFecha());
          cell0.setPhrase(new Phrase(fecha, new Font(
              FontFamily.HELVETICA, 10, Font.NORMAL)));
          cell1.setPhrase(new Phrase(falla.getEquipoNombre(),
              new Font(FontFamily.HELVETICA, 10, Font.NORMAL)));
          cell2.setPhrase(new Phrase(falla.getComentario().getValue(), new Font(
              FontFamily.HELVETICA, 10, Font.NORMAL)));
          tabla.addCell(cell0);
          tabla.addCell(cell1);
          tabla.addCell(cell2);
          tabla.completeRow();
        }

        document.add(tabla);

        document.close();
        byte[] pdf = baos.toByteArray();

        DatastoreService datastore = DatastoreServiceFactory
            .getDatastoreService();
View Full Code Here

        String txtNegocio = negocio.getNombre();
        bitacoraList = BitacoraLNDAO.obtenerNovedadesParaCorreo(idNegocio);

        if (!bitacoraList.isEmpty()) {

          Document document = new Document();

          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PdfWriter writer = PdfWriter.getInstance(document, baos);

          Cabecera event = new Cabecera(txtNegocio);
          writer.setPageEvent(event);

          document.open();

          Iterator<BitacoraLN> iteNovedadesfallas = bitacoraList
              .iterator();

          String[] headers = new String[] { "Fecha", "Usuario",
              "Turno", "Equipo", "Novedad" };
          tabla = new PdfPTable(headers.length);
          tabla.setWidthPercentage(100);

          float[] widths = new float[] { 2f, 2f, 1f, 2f, 5f };

          tabla.setWidths(widths);

          for (int i = 0; i < headers.length; i++) {
            String header = headers[i];
            PdfPCell cell = new PdfPCell();
            cell.setGrayFill(0.9f);
            cell.setPhrase(new Phrase(header.toUpperCase(),
                new Font(FontFamily.HELVETICA, 10, Font.BOLD)));
            tabla.addCell(cell);
          }
          tabla.completeRow();
          while (iteNovedadesfallas.hasNext()) {

            BitacoraLN bitacora = iteNovedadesfallas.next();
            PdfPCell cell0 = new PdfPCell();
            PdfPCell cell1 = new PdfPCell();
            PdfPCell cell2 = new PdfPCell();
            PdfPCell cell3 = new PdfPCell();
            PdfPCell cell4 = new PdfPCell();
            SimpleDateFormat sdf = new SimpleDateFormat(
                "dd/MM/yyyy");
            String fecha = sdf.format(bitacora.getFecha());
            cell0.setPhrase(new Phrase(fecha, new Font(
                FontFamily.HELVETICA, 8, Font.NORMAL)));
            if (bitacora.getUsuarioNombre() != null) {
              cell1.setPhrase(new Phrase(bitacora
                  .getUsuarioNombre(), new Font(
                  FontFamily.HELVETICA, 8, Font.NORMAL)));
            } else {
              cell1.setPhrase(new Phrase("", new Font(
                  FontFamily.HELVETICA, 8, Font.NORMAL)));
            }
            cell2.setPhrase(new Phrase(bitacora.getTurnoNombre(),
                new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
            cell3.setPhrase(new Phrase(bitacora.getEquipoNombre(),
                new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
            cell4.setPhrase(new Phrase(bitacora.getComentario().getValue(),
                new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
            tabla.addCell(cell0);
            tabla.addCell(cell1);
            tabla.addCell(cell2);
            tabla.addCell(cell3);
            tabla.addCell(cell4);
            tabla.completeRow();
          }

          document.add(tabla);

          document.close();

          byte[] pdf = baos.toByteArray();
          Properties props = new Properties();
          Session session = Session.getDefaultInstance(props, null);
View Full Code Here

  public String reporteFallasPDF() {
    try {

      PdfPTable tabla = null;
      Document document = new Document();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      PdfWriter writer = PdfWriter.getInstance(document, baos);
      Map<String, Object> session = ActionContext.getContext().getSession();

      HeaderFooter event = new HeaderFooter((String)session.get("txtNegocio"));
      writer.setPageEvent(event);

      document.open();

      if (tipo.equals("0")) {// falla
        if (texto.trim().length() > 0) {
          fallaList = ReporteLNBO.reporteFallas(fechaini, fechater,
              texto, idEquipo);
        } else {
          fallaList = ReporteLNBO.reporteFallasSinTexto(fechaini,
              fechater, idEquipo);
        }
        Iterator<FallaLN> iteFallas = fallaList.iterator();
        String[] headers = new String[] { "Fecha", "Equipo", "Problema" };
        tabla = new PdfPTable(headers.length);
        tabla.setWidthPercentage(100);
       
        float[] widths = new float[] { 1f, 3f, 4f };
       
        tabla.setWidths(widths);
       
        for (int i = 0; i < headers.length; i++) {
          String header = headers[i];
          PdfPCell cell = new PdfPCell();
          cell.setGrayFill(0.9f);
          cell.setPhrase(new Phrase(header.toUpperCase(), new Font(
              FontFamily.HELVETICA, 10, Font.BOLD)));
          tabla.addCell(cell);
        }
        tabla.completeRow();

        while (iteFallas.hasNext()) {
          FallaLN falla = iteFallas.next();
          PdfPCell cell0 = new PdfPCell();
          PdfPCell cell1 = new PdfPCell();
          PdfPCell cell2 = new PdfPCell();

          SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
          String fecha = sdf.format(falla.getFecha());
          cell0.setPhrase(new Phrase(fecha, new Font(
              FontFamily.HELVETICA, 8, Font.NORMAL)));
          cell1.setPhrase(new Phrase(falla.getEquipoNombre(),
              new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
          cell2.setPhrase(new Phrase(falla.getProblema(), new Font(
              FontFamily.HELVETICA, 8, Font.NORMAL)));
          tabla.addCell(cell0);
          tabla.addCell(cell1);
          tabla.addCell(cell2);
          tabla.completeRow();
        }
      } else if (tipo.equals("1")) {// novedad
        if (texto.trim().length() > 0) {
          novedadList = ReporteLNBO.reporteNovedades(fechaini,
              fechater, texto, idEquipo);
        } else {
          novedadList = ReporteLNBO.reporteNovedadesSinTexto(
              fechaini, fechater, idEquipo);
        }
        Iterator<BitacoraLN> iteNovedadesfallas = novedadList
            .iterator();
        String[] headers = new String[] { "Fecha", "Usuario", "Turno",
            "Equipo", "Novedad" };
        tabla = new PdfPTable(headers.length);
        tabla.setWidthPercentage(100);
       
       
        float[] widths = new float[] { 2f, 2f, 1f,2f, 5f };
       
        tabla.setWidths(widths);
       
        for (int i = 0; i < headers.length; i++) {
          String header = headers[i];
          PdfPCell cell = new PdfPCell();
          cell.setGrayFill(0.9f);
          cell.setPhrase(new Phrase(header.toUpperCase(), new Font(
              FontFamily.HELVETICA, 10, Font.BOLD)));
          tabla.addCell(cell);
        }
        tabla.completeRow();
        while (iteNovedadesfallas.hasNext()) {

          BitacoraLN bitacora = iteNovedadesfallas.next();
          PdfPCell cell0 = new PdfPCell();
          PdfPCell cell1 = new PdfPCell();
          PdfPCell cell2 = new PdfPCell();
          PdfPCell cell3 = new PdfPCell();
          PdfPCell cell4 = new PdfPCell();
          SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
          String fecha = sdf.format(bitacora.getFecha());
          cell0.setPhrase(new Phrase(fecha, new Font(
              FontFamily.HELVETICA, 8, Font.NORMAL)));
          if (bitacora.getUsuarioNombre() != null) {
            cell1.setPhrase(new Phrase(bitacora.getUsuarioNombre(),
                new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
          } else {
            cell1.setPhrase(new Phrase("", new Font(
                FontFamily.HELVETICA, 8, Font.NORMAL)));
          }
          cell2.setPhrase(new Phrase(bitacora.getTurnoNombre(),
              new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
          cell3.setPhrase(new Phrase(bitacora.getEquipoNombre(),
              new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
          cell4.setPhrase(new Phrase(bitacora.getComentario().getValue(),
              new Font(FontFamily.HELVETICA, 8, Font.NORMAL)));
          tabla.addCell(cell0);
          tabla.addCell(cell1);
          tabla.addCell(cell2);
          tabla.addCell(cell3);
          tabla.addCell(cell4);
          tabla.completeRow();
        }
      }

      document.add(tabla);

      document.close();
      inputStream = new ByteArrayInputStream(baos.toByteArray());

    } catch (Exception e) {
      log.error(e);
    }
View Full Code Here

    PdfCopyFieldsImp(OutputStream os, char pdfVersion) throws DocumentException {
        super(new PdfDocument(), os);
        pdf.addWriter(this);
        if (pdfVersion != 0)
            super.setPdfVersion(pdfVersion);
        nd = new Document();
        nd.addDocListener(pdf);
    }
View Full Code Here

TOP

Related Classes of com.itextpdf.text.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.