Example usage for com.lowagie.text Paragraph setAlignment

List of usage examples for com.lowagie.text Paragraph setAlignment

Introduction

In this page you can find the example usage for com.lowagie.text Paragraph setAlignment.

Prototype

public void setAlignment(String alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

From source file:util.ImprimirCIPDF.java

@Override
protected void gerarConteudo() throws Exception {

    ci = ComunicacaoInternaDAO.getInstance().selectFromId(ci.getId());

    Paragraph paragrafo = new Paragraph(ci.getTipoCI() + " - " + ci.getNumeroCI(), fonteH1);
    paragrafo.setAlignment(Element.ALIGN_CENTER);
    paragrafo.setSpacingBefore(10f);//from  w ww.j  a va 2s .  co m
    documento.add(paragrafo);
    documento.add(Chunk.NEWLINE);
    documento.add(Chunk.NEWLINE);

    //1- DADOS DO ATENDIMENTO
    //documento.add(new Phrase("De: " + ci.getUo().getNome() + "                     Nmero: " + ci.getNumeroCI(), fonteB));
    documento.add(new Phrase("De: " + ci.getUo().getNome(), fonteB));
    documento.add(Chunk.NEWLINE);

    //Tipo Atendimento:
    if (ci.getDespachoList().get(0).getPara() != null) {
        documento.add(new Phrase("Para: " + ci.getDespachoList().get(0).getPara().getNome(), fonteB));
        documento.add(Chunk.NEWLINE);
    }

    if (!ci.getDespachoList().get(0).getDespachoCopiaList().isEmpty()) {
        StringBuffer strBuffer = new StringBuffer();
        for (DespachoCopia dc : ci.getDespachoList().get(0).getDespachoCopiaList()) {
            strBuffer.append(TratamentoString.tratarEspacosEmBranco(dc.getUnidadeOrganizacional().getNome()));
            strBuffer.append(", ");

        }
        documento.add(new Phrase("CC: " + strBuffer.toString(), fonteB));
        documento.add(Chunk.NEWLINE);

    }
    documento.add(Chunk.NEWLINE);

    documento.add(new Phrase("Assunto: " + ci.getAssunto(), fonteB));
    documento.add(Chunk.NEWLINE);
    documento.add(new Phrase("        ", fonte));
    documento.add(Chunk.NEWLINE);

    gerarLinhaHR();

    documento.add(Chunk.NEWLINE);

    documento.add(Chunk.NEWLINE);

    StringReader strReader = new StringReader(ci.getDespachoList().get(0).getConteudo());
    ArrayList p = new ArrayList();
    p = HTMLWorker.parseToList(strReader, null);

    for (int i = 0; i < p.size(); i++) {

        documento.add(((Element) p.get(i)));
    }

    documento.add(Chunk.NEWLINE);
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

    documento.add(new Phrase("Em: " + formatter.format(ci.getData()), fonteB));

    if (ci.getDespachoList().size() > 1) {
        documento.add(Chunk.NEXTPAGE);
        documento.add(Chunk.NEWLINE);
        this.gerarCabecalho();
        documento.add(Chunk.NEWLINE);
        Paragraph despachos = new Paragraph("Despachos", fonteH1);
        despachos.setAlignment(Element.ALIGN_CENTER);
        despachos.setSpacingBefore(10f);
        documento.add(despachos);
        documento.add(Chunk.NEWLINE);
        for (int i = 1; i < ci.getDespachoList().size(); i++) {
            gerarLinhaHR();
            documento.add(Chunk.NEWLINE);
            documento.add(new Phrase(
                    TratamentoString.tratarEspacosEmBranco(ci.getDespachoList().get(i - 1).getPara().getNome())
                            + " "
                            + TratamentoString
                                    .tratarEspacosEmBranco(ci.getDespachoList().get(i).getStatusString()),
                    fonteB));
            documento.add(Chunk.NEWLINE);
            documento.add(new Phrase("Observao: ", fonteB));
            strReader = new StringReader(ci.getDespachoList().get(i).getConteudo());
            p = HTMLWorker.parseToList(strReader, null);
            for (int j = 0; j < p.size(); j++) {

                documento.add(((Element) p.get(j)));
            }
            gerarLinhaHR();
            documento.add(Chunk.NEWLINE);

        }
    }

}

From source file:util.PDFconverter.java

public static void createPDF(String[] header, String[][] data, String path, String tittle,
        float[] columnWidths) {
    try {/*from w w  w. j ava 2 s  .  c om*/
        Document doc = new Document();

        PdfWriter.getInstance(doc, new FileOutputStream(path));

        doc.open();
        doc.setPageSize(PageSize.A4);
        doc.setMargins(10, 10, 10, 10);
        Font litle = new Font(Font.COURIER, 7, Font.NORMAL);
        Font norm = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);
        Font normBold = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
        Font TitleFont = new Font(Font.TIMES_ROMAN, 12, Font.BOLD);

        doc.add(Chunk.NEWLINE);
        Paragraph judul = new Paragraph(tittle, TitleFont);
        judul.setAlignment(Element.ALIGN_CENTER);
        doc.add(judul);

        //          Paragraph tgl = new Paragraph("tanggal " + tanggal + "\n", TitleFont);            
        //          tgl.setAlignment(Element.ALIGN_CENTER);
        //          doc.add(tgl);
        doc.add(Chunk.NEWLINE);

        PdfPTable table = new PdfPTable(header.length);
        table.setWidthPercentage(100f);

        for (String head : header) {
            table.addCell(new PdfPCell(new Phrase(head, normBold)));
        }

        for (String[] obj : data) {
            for (int i = 0; i < header.length; i++) {
                table.addCell(new PdfPCell(new Phrase(obj[i], norm)));
            }

        }

        //float[] columnWidths = new float[] {10f, 20f, 30f, 10f};
        table.setWidths(columnWidths);

        doc.add(table);

        //            Paragraph stamp = new Paragraph(new Chunk("this report has generated with QCMS by " + System.getProperty("user.name") + " on " + new Date(), litle));
        //            stamp.setAlignment(Element.ALIGN_BOTTOM);
        //            stamp.setAlignment(Element.ALIGN_CENTER);
        //            doc.add(stamp);
        //
        //            Paragraph tanda = new Paragraph(new Chunk("Mengetahui,", norm));
        //            tanda.setSpacingBefore(100);
        //            tanda.setAlignment(Element.ALIGN_RIGHT);
        //            tanda.setAlignment(Element.ALIGN_BOTTOM);
        //            doc.add(tanda);
        //
        //            Paragraph nama = new Paragraph(new Chunk("MANAGER Dept.RnQ", norm));
        //            nama.setSpacingBefore(30);
        //            nama.setAlignment(Element.ALIGN_RIGHT);
        //            nama.setAlignment(Element.ALIGN_BOTTOM);
        //            doc.add(nama);
        doc.close();
    } catch (DocumentException | FileNotFoundException ex) {
        Logger.getLogger(PDFconverter.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:vistas.reportes.procesos.rptAsistenciaTotal.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario, boolean isSelectedComp, boolean isSelectedHoraM)
        throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4);
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();/*from  w  w  w.  j ava2 s . c  om*/
    Image cabecera = Image.getInstance("img/cabecera.png");
    cabecera.setAlignment(1);
    documento.add(cabecera);
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "DEPENDENCIA:      ";
    } else if (tipo == "G") {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    } else if (tipo == "P") {
        nombreGrupoOficina = "DEPENDENCIA:      ";
    }
    Font font = new Font(Font.HELVETICA, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONTROL DE ASISTENCIA",
            new Font(Font.HELVETICA, 12, Font.BOLD));
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelFechaInicio = new Chunk("FECHA INICIO:        ", font);
    Chunk labelFechaFin = new Chunk("       FECHA FIN: ", font);
    //Chunk labelUsuario = new Chunk("USUARIO: ",font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.HELVETICA, 10));
    Chunk nombreFechaInicio = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaInicio, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    Chunk nombreFechaFin = new Chunk(ReporteUtil.obtenerFechaFormateada(fechaFin, "/").toUpperCase(),
            new Font(Font.HELVETICA, 10));
    //Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.HELVETICA,10));

    Paragraph pNombreReporte = new Paragraph(nombreReporte);
    pNombreReporte.setAlignment(1);
    documento.add(pNombreReporte);
    documento.add(ReporteUtil.darEspaciado(25));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    if (tipo == "P") {
        Chunk labelDniEmpleado = new Chunk("DNI:                           ", font);
        Chunk labelNombreEmpleado = new Chunk("NOMBRE:                ", font);
        Empleado empleado = ec.buscarPorDni(dnis.get(0));
        Chunk nombreDni = new Chunk(empleado.getNroDocumento(), new Font(Font.HELVETICA, 10));
        Chunk nombreEmpleado = new Chunk(empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno()
                + " " + empleado.getNombre(), new Font(Font.HELVETICA, 10));
        documento.add(new Paragraph(ReporteUtil.unirChunks(labelNombreEmpleado, nombreEmpleado)));
        documento.add(ReporteUtil.darEspaciado(15));
        documento.add(new Paragraph(ReporteUtil.unirChunks(labelDniEmpleado, nombreDni)));
        documento.add(ReporteUtil.darEspaciado(15));
    }
    documento.add(new Paragraph(
            ReporteUtil.unirChunks(labelFechaInicio, nombreFechaInicio, labelFechaFin, nombreFechaFin)));
    documento.add(ReporteUtil.darEspaciado(15));

    //documento.add(new Paragraph(ReporteUtil.unirChunks(labelFechaFin,nombreFechaFin)));
    //documento.add(ReporteUtil.darEspaciado(15));
    //documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario,nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptAsistenciaTotal().crearTabla(dnis, fechaInicio, fechaFin, isSelectedComp,
            isSelectedHoraM, tipo);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:za.co.equalpay.web.utils.PDFExportUtility.java

public void postProcess() throws MalformedURLException, IOException, DocumentException {
    // document.open();
    ////from w  ww  . j  a  v  a  2  s  .c  o  m
    // ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // PdfWriter writer = PdfWriter.getInstance(document, baos);
    //
    // writer.open();
    // PdfContentByte cb = writer.getDirectContent();
    // cb.addImage(image);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();

    String fontPath = LogoPathFinder.getFontPath(servletContext, "Tahoma");
    BaseFont bf = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, true);
    Font tahoma = new Font(bf, 16, Font.BOLDITALIC);
    tahoma.setColor(Color.GRAY);

    Font boldFont8 = new Font(bf, 8, Font.BOLD, Color.GRAY);
    Font normalFont8 = new Font(bf, 8, Font.NORMAL, Color.GRAY);

    Font boldFont10 = new Font(bf, 10, Font.BOLDITALIC, Color.GRAY);
    Font normalFont10 = new Font(bf, 10, Font.ITALIC, Color.GRAY);

    phrase = new Phrase();
    phrase.add(new Phrase("Exclusive Distributors of ", normalFont10));
    phrase.add(new Phrase("SAM Medical, CONTERRA, TACMED Solutions ", boldFont10));
    phrase.add(new Phrase("and ", normalFont10));
    phrase.add(new Phrase("NARP ", boldFont10));
    phrase.add(new Phrase("in South Africa.", normalFont10));

    Paragraph paragraph = new Paragraph(phrase);
    paragraph.setAlignment(Paragraph.ALIGN_CENTER);

    document.add(paragraph);

    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100);

    // Terms & Conditions
    phrase = new Phrase();
    phrase.add(new Phrase("\n\n\n"));
    phrase.add(new Phrase("Terms and Conditions: ", boldFont8));
    phrase.add(new Phrase("\n"));
    phrase.add(new Phrase(
            "\n1.    Full Payment in Advance, unless arranged otherwise. Orders will only be processed once payment reflects in our Bank Account.",
            normalFont8));
    phrase.add(new Phrase("\n2.    Prices are net.", normalFont8));
    phrase.add(new Phrase("\n3.    Delivery will be ex stock, alternatively 4  6 weeks from date of order.",
            normalFont8));
    phrase.add(
            new Phrase("\n4.    Shipping Lead Time will depend on clients mode of Transport.", normalFont8));
    phrase.add(new Phrase("\n5.    Prices and Supply of Goods are Subject to availability of stock.",
            normalFont8));
    phrase.add(new Phrase("\n6.    Prices are subject to exchange rate and brand.", normalFont8));
    phrase.add(new Phrase("\n7.    Quotation is valid for 30 Days", boldFont8));
    phrase.add(new Phrase(
            "\n8.    All capital equipment carries a one year guarantee against defective material and workmanship",
            normalFont8));
    phrase.add(new Phrase("\n9.    E & OA accepted.", normalFont8));
    phrase.add(new Phrase("\n10.  Excluding Postage, Packaging or Freight Forwarding to relevant Country.",
            normalFont8));

    PdfPCell cell = new PdfPCell(phrase);
    cell.setBorder(0);
    table.addCell(cell);

    document.add(table);
}