Example usage for com.itextpdf.text Element ALIGN_LEFT

List of usage examples for com.itextpdf.text Element ALIGN_LEFT

Introduction

In this page you can find the example usage for com.itextpdf.text Element ALIGN_LEFT.

Prototype

int ALIGN_LEFT

To view the source code for com.itextpdf.text Element ALIGN_LEFT.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:naprawa.praca.PracaController.java

public PdfPCell getNewCell(String nazwa) {
    BaseFont bf = null;/*  w ww .jav  a 2 s  .co m*/
    try {
        bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    } catch (DocumentException ex) {
        Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex);
    }
    PdfPCell cell = new PdfPCell(new Paragraph(nazwa, new com.itextpdf.text.Font(bf, 10)));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setVerticalAlignment(Element.ALIGN_LEFT);
    cell.setBorder(PdfPCell.NO_BORDER);
    return cell;
}

From source file:net.ionescu.jhocr2pdf.Jhocr2pdf.java

License:Open Source License

public void addSpan(String coords, String text) {
    // parse the coordinates
    String[] coord = coords.split(" ");
    Rectangle rect = new Rectangle(Float.valueOf(coord[1]), Float.valueOf(coord[4]), Float.valueOf(coord[3]),
            Float.valueOf(coord[2]));

    canvas.saveState();//from  ww  w .  j  a  v a 2  s  .  c  om
    canvas.beginText();
    canvas.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
    canvas.setRGBColorFill(0xFF, 0, 0);
    canvas.setLineWidth(0);

    // calculate the font size
    float width = rect.getWidth() * xScaling;

    float tenWidth = bf.getWidthPointKerned(text, 10);
    float fontSize = 10 * width / tenWidth;

    canvas.setFontAndSize(bf, fontSize);
    canvas.showTextAlignedKerned(Element.ALIGN_LEFT, text, rect.getLeft() * xScaling,
            PageSize.A4.getHeight() - rect.getBottom() * yScaling - bf.getDescentPoint(text, fontSize), 0);
    canvas.endText();
    canvas.restoreState();

}

From source file:net.pickapack.util.TableHelper.java

License:Open Source License

private static void addRow(PdfPTable table, boolean header, List<String> values) {
    List<PdfPCell> cells = new ArrayList<PdfPCell>();

    for (Object value : values) {
        PdfPCell cell = new PdfPCell(new Phrase(value + "", header ? boldFont : normalFont));
        if (header) {
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        }//from w  w  w .ja v  a 2 s . co m

        cells.add(cell);
    }

    table.getRows().add(new PdfPRow(cells.toArray(new PdfPCell[cells.size()])));
}

From source file:net.viralpatel.pdf.FirstPdf.java

public static void main(String[] args) {
    try {//from  w  w w. jav  a 2 s .c o  m
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(FILE));
        document.open();
        // Left
        Paragraph paragraph = new Paragraph("This is right aligned text");
        paragraph.setAlignment(Element.ALIGN_RIGHT);
        document.add(paragraph);
        // Centered
        paragraph = new Paragraph("This is centered text");
        paragraph.setAlignment(Element.ALIGN_CENTER);
        document.add(paragraph);
        // Left
        paragraph = new Paragraph("This is left aligned text");
        paragraph.setAlignment(Element.ALIGN_LEFT);
        document.add(paragraph);
        // Left with indentation
        paragraph = new Paragraph("This is left aligned text with indentation");
        paragraph.setAlignment(Element.ALIGN_LEFT);
        paragraph.setIndentationLeft(50);
        document.add(paragraph);

        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:nl.avans.C3.BusinessLogic.InvoiceService.java

public void generateInvoice(String invoiceBSN, int[] behandelCode)
        throws DocumentException, FileNotFoundException, ClientNotFoundException, ParseException {
    Date date = new Date();
    String dt = new SimpleDateFormat("yyyy-MM-dd").format(date);
    String fileId = "invoice-" + dt + "-" + invoiceBSN;

    String companyName = companyService.getInsuranceCompany().getName();
    String companyAddress = companyService.getInsuranceCompany().getAddress();
    String companyPostalCode = companyService.getInsuranceCompany().getPostalCode();
    String companyCity = companyService.getInsuranceCompany().getCity();

    String companyKVK = Integer.toString(companyService.getInsuranceCompany().getKVK());
    String companyIBAN = "NL91ABNA0417164300";

    Client client = clientService.findClientByBSN(Integer.parseInt(invoiceBSN));
    String clientFirstName = client.getFirstName();
    String clientLastName = client.getLastName();
    String clientAddress = client.getAddress();
    String clientPostalCode = client.getPostalCode();
    String clientCity = client.getCity();
    boolean incasso = client.isIncasso();

    Date date2 = new Date();
    String dt2 = new SimpleDateFormat("dd-MM-yyyy").format(date2);
    String currentDate = dt2;/*  w w  w.  jav a 2 s .co  m*/
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    Calendar c = Calendar.getInstance();
    c.setTime(sdf.parse(dt2));
    c.add(Calendar.MONTH, 1);
    dt2 = sdf.format(c.getTime());
    String expirationDate = dt2;

    String invoiceNumber = dt + "-" + invoiceBSN;

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

    // Creating new file
    Document doc = new Document();

    // Trying to parse the data to a new PDF
    PdfWriter.getInstance(doc, new FileOutputStream("generatedfiles/invoice/" + fileId + ".pdf"));

    // Opening the file
    doc.open();

    // Parsing the order details to the PDF
    doc.add(new Paragraph(companyName + "\n" + companyAddress + "\n" + companyPostalCode + " " + companyCity
            + "\n\n" + "KVK: " + companyKVK + "\nIBAN: " + companyIBAN + "\n\n\n" + clientFirstName + " "
            + clientLastName + "\n" + clientAddress + "\n" + clientPostalCode + " " + clientCity + "\n\n"
            + "Factuurdatum: " + currentDate + "\nVerloopdatum: " + expirationDate + "\n\n\n"
            + "Factuurnummer: " + invoiceNumber + "\n\n\n\n"));

    float[] columnWidths = { 2f, 2f, 2f, 2f, 2f };
    PdfPTable table = new PdfPTable(columnWidths);
    table.setWidthPercentage(100f);

    insertCell(table, "Behandelcode", Element.ALIGN_LEFT, 1, bfBold12);
    insertCell(table, "Behandelingnaam", Element.ALIGN_LEFT, 1, bfBold12);
    insertCell(table, "Aantal sessies", Element.ALIGN_LEFT, 1, bfBold12);
    insertCell(table, "Sessieduur", Element.ALIGN_LEFT, 1, bfBold12);
    insertCell(table, "Tarief", Element.ALIGN_LEFT, 1, bfBold12);
    table.setHeaderRows(1);

    List<Treatment> treatments = getTreatments(behandelCode);

    for (int i = 0; i < treatments.size(); i++) {
        insertCell(table, "" + treatments.get(i).getBehandelCode(), Element.ALIGN_LEFT, 1, bf12);
        insertCell(table, "" + treatments.get(i).getBehandelingNaam(), Element.ALIGN_LEFT, 1, bf12);
        insertCell(table, "" + treatments.get(i).getAantalSessies(), Element.ALIGN_LEFT, 1, bf12);
        insertCell(table, "" + treatments.get(i).getSessieDuur(), Element.ALIGN_LEFT, 1, bf12);
        insertCell(table, "" + treatments.get(i).getTariefBehandeling(), Element.ALIGN_RIGHT, 1, bf12);
    }

    //totaalbedrag zonder eigen risico
    double totaalBedrag = getTotaalBedrag(behandelCode);
    insertCell(table, "Totaalbedrag: ", Element.ALIGN_RIGHT, 4, bfBold12);
    insertCell(table, "" + totaalBedrag, Element.ALIGN_RIGHT, 1, bfBold12);

    //lege row
    insertCell(table, "", Element.ALIGN_RIGHT, 5, bf12);

    //huidig eigen risico
    double excess = insuranceContractService.getInsuranceContractByBSN(Integer.parseInt(invoiceBSN))
            .getExcess();
    insertCell(table, "Huidig eigen risico: ", Element.ALIGN_RIGHT, 4, bf12);
    insertCell(table, "" + excess, Element.ALIGN_RIGHT, 1, bf12);

    //totaal te betalen bedrag
    double teBetalenBedrag;
    double newExcess = excess - totaalBedrag;
    insertCell(table, "Te betalen bedrag: ", Element.ALIGN_RIGHT, 4, bfBold12);
    if (excess > 0) {
        if (excess > totaalBedrag) {
            insuranceContractService.updateInsuranceContractExcess(newExcess, insuranceContractService
                    .getInsuranceContractByBSN(Integer.parseInt(invoiceBSN)).getInsuranceContractID());
            insertCell(table, "" + totaalBedrag, Element.ALIGN_RIGHT, 1, bfBold12);
            teBetalenBedrag = totaalBedrag;
        } else {
            insuranceContractService.updateInsuranceContractExcess(0.00, insuranceContractService
                    .getInsuranceContractByBSN(Integer.parseInt(invoiceBSN)).getInsuranceContractID());
            insertCell(table, "" + excess, Element.ALIGN_RIGHT, 1, bfBold12);
            teBetalenBedrag = excess;
        }
    } else {
        insertCell(table, "0.0", Element.ALIGN_RIGHT, 1, bfBold12);
        teBetalenBedrag = 0.00;
    }

    Paragraph paragraph = new Paragraph("");
    paragraph.add(table);
    doc.add(paragraph);

    doc.add(new Paragraph("\n\n"));

    if (newExcess > 0) {
        doc.add(new Paragraph("U heeft nog " + newExcess + " eigen risico over."));
    } else {
        doc.add(new Paragraph("U heeft nog 0.0 eigen risico over."));
    }

    doc.add(new Paragraph("\n\n"));
    if (incasso == false) {
        if (teBetalenBedrag > 0) {
            doc.add(new Paragraph("We verzoeken u vriendelijk het bovenstaande bedrag van " + teBetalenBedrag
                    + " voor " + expirationDate
                    + " te voldoen op onze bankrekening onder vermelding van het factuurnummer " + invoiceNumber
                    + ". Voor vragen kunt u contact opnemen per e-mail."));
        } else {
            doc.add(new Paragraph(
                    "Omdat uw eigen risico op is worden er geen kosten in rekening gebracht voor de bovenstaande behandelingen."));
        }
    } else {
        doc.add(new Paragraph(
                "Het geld zal binnen 10 werkdagen van uw rekening afgeschreven worden door middel van een automatische incasso."));
    }

    // Closing the file
    doc.close();
}

From source file:nwk.com.br.documents.ClienteMaisComprouPdf.java

private PdfPTable getCliente() throws Exception {
    PdfPTable clienteMaisComprou = new PdfPTable(new float[] { 0.1f/*id*/, 0.65f/*nome*/, 0.25f/*soma*/ });
    clienteMaisComprou.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento
    clienteMaisComprou.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    clienteMaisComprou.getDefaultCell().setBorder(0);

    //Adiciona os nomes das colunas
    PdfPCell idCliente = new PdfPCell(new Paragraph("Id"));
    PdfPCell nomeCliente = new PdfPCell(new Paragraph("Nome"));
    PdfPCell valorCliente = new PdfPCell(new Paragraph("Valor"));

    clienteMaisComprou.addCell(idCliente);
    clienteMaisComprou.addCell(nomeCliente);
    clienteMaisComprou.addCell(valorCliente);

    //Adiciona as informaes do cliente na tabela
    int qtdCli = 0;
    for (Cliente cliente : clientedao.getClienteMaisComprou()) {
        clienteMaisComprou.addCell(Integer.toString(cliente.getId()));
        clienteMaisComprou.addCell(cliente.getNome());
        clienteMaisComprou.addCell("R$ " + cliente.getTotalCompra());

        if (qtdCli == 19) {
            break;
        } else {//ww w. jav a  2 s. c om
            qtdCli++;
        }
    }

    return clienteMaisComprou;
}

From source file:nwk.com.br.documents.OrcamentoPdf.java

private PdfPTable dadosCliente(Orcamento orcamento) throws Exception {
    cliente = clientedao.select(orcamento.getIdCliente());

    PdfPTable dadosCliente = new PdfPTable(new float[] { 0.35f, 0.35f, 0.3f });
    dadosCliente.setWidthPercentage(90.0f);//seta o tamanho da tabela em relaao ao documento
    dadosCliente.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);//alinha os dados a esquerda
    dadosCliente.getDefaultCell().setBorder(0);//retira a borda

    //Cria uma cedula da tabela que pegara tres colunas
    PdfPCell nomeCli = new PdfPCell(new Paragraph("Nome: " + cliente.getNome(), f));
    nomeCli.setColspan(3);/*from  w  ww  .  ja  va 2  s  . c o m*/
    nomeCli.setHorizontalAlignment(Element.ALIGN_LEFT);
    nomeCli.setBorder(0);
    dadosCliente.addCell(nomeCli);

    //formatao do celular e do telefone
    String celular = new String();
    String telefone = new String();
    celular = "(" + cliente.getCelular().substring(0, 2) + ") " + cliente.getCelular().substring(2);
    telefone = "(" + cliente.getTelefone().substring(0, 2) + ") " + cliente.getCelular().substring(2);

    //adciona os demais dados do cliente a tabela
    dadosCliente.addCell("E-mail: " + cliente.getEmail());
    dadosCliente.addCell("Telefone: " + telefone);
    dadosCliente.addCell("Celular: " + celular);
    dadosCliente.addCell("Rua: " + cliente.getRua() + ", " + cliente.getNumero());
    dadosCliente.addCell("Bairro: " + cliente.getBairro());
    dadosCliente.addCell("Complemento: " + cliente.getComplemento());
    dadosCliente.addCell(cliente.getCidade() + "/" + cliente.getEstado());
    dadosCliente.addCell(cliente.getCep());

    return dadosCliente;
}

From source file:nwk.com.br.documents.OrcamentoPdf.java

private PdfPTable dadosProdutos(Orcamento orcamento) throws Exception {
    PdfPTable produtosOrc = new PdfPTable(new float[] { 0.1f/*cod*/, 0.45f/*descri*/, 0.1f/*qtd*/,
            0.2f/*valuni*/, 0.15f/*descon*/, 0.2f/*total*/ });
    produtosOrc.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento
    produtosOrc.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    produtosOrc.getDefaultCell().setBorder(0);

    //Adiciona os nomes das colunas
    PdfPCell codProd = new PdfPCell(new Paragraph("Cod"));
    PdfPCell descProd = new PdfPCell(new Paragraph("Descrio"));
    PdfPCell qtdProd = new PdfPCell(new Paragraph("Qtd"));
    PdfPCell valProd = new PdfPCell(new Paragraph("Valor Unitario"));
    PdfPCell desProd = new PdfPCell(new Paragraph("Desconto"));
    PdfPCell totalProd = new PdfPCell(new Paragraph("Total"));

    produtosOrc.addCell(codProd);//from  www . j a  v a 2  s.c  o m
    produtosOrc.addCell(descProd);
    produtosOrc.addCell(qtdProd);
    produtosOrc.addCell(valProd);
    produtosOrc.addCell(desProd);
    produtosOrc.addCell(totalProd);

    //Adiciona as informaes dos produtos na tabela
    for (Produto produto : orcamentodao.getTodosProdutosOrcamento(orcamento)) {
        produtosOrc.addCell(produto.getId());
        produtosOrc.addCell(produto.getDescricao());
        produtosOrc.addCell(produto.getQuantidade());
        produtosOrc.addCell("R$ " + produto.getValorVenda());
        produtosOrc.addCell("R$ " + produto.getDesconto());
        produtosOrc.addCell("R$ " + produto.getTotal());
    }

    return produtosOrc;
}

From source file:nwk.com.br.documents.OrcamentoPdf.java

private PdfPTable dadosPagamento(Orcamento orcamento) throws Exception {
    Font fontTotal = new Font(Font.FontFamily.TIMES_ROMAN, 16);

    PdfPTable dPagamento = new PdfPTable(new float[] { 0.5f, 0.2f, 0.3f });
    dPagamento.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento
    dPagamento.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    dPagamento.getDefaultCell().setBorder(0);

    //celula com espao em branco e com o Total
    PdfPCell spc = new PdfPCell(new Paragraph(" "));
    PdfPCell total = new PdfPCell(new Paragraph("TOTAL: R$" + orcamento.getTotal(), fontTotal));

    //alinha a celula total a esquerda
    total.setHorizontalAlignment(Element.ALIGN_RIGHT);

    spc.setColspan(3);//from ww  w  .  j av a 2s  .com

    total.setBorder(0);
    spc.setBorder(0);

    if (orcamento.getFormaPagamento().equals("0")) {
        dPagamento.addCell(new Paragraph("Forma de Pagamento: A vista - Dinheiro", f));
    } else if (orcamento.getFormaPagamento().equals("1")) {
        dPagamento.addCell(new Paragraph("Forma de Pagamento: A vista - Carto", f));
    } else if (orcamento.getFormaPagamento().equals("2")) {
        dPagamento.addCell(new Paragraph("Forma de Pagamento: Parcelado", f));
    }

    dPagamento.addCell(new Paragraph("Desconto: R$" + orcamento.getDesconto(), f));
    dPagamento.addCell(total);

    return dPagamento;
}

From source file:nwk.com.br.documents.OrcamentoPdf.java

private PdfPTable dadosRodape(Orcamento orcamento) throws Exception {
    //tabela que pega com 100% do tamanho do arquivo, alinhada no centro com tres colunas e sem bordas
    PdfPTable rodape = new PdfPTable(new float[] { 0.5f, 0.2f, 0.3f });
    rodape.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento
    rodape.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    rodape.getDefaultCell().setBorder(0);

    PdfPCell obs = new PdfPCell(new Paragraph("\n\n Observaes:\n" + orcamento.getObservacoes(), f));
    PdfPCell ass = new PdfPCell(new Paragraph("\n\n_________________________\nAssinatura", f));

    Font fonteAviso = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLDITALIC);

    PdfPCell spc = new PdfPCell(new Paragraph(" "));
    PdfPCell aviso = new PdfPCell(new Paragraph(
            "AGRADEEMOS A PREFERNCIA\nORAMENTO VALIDO SOMENTE PARA O DIA DE SUA CRIAO!", fonteAviso));

    aviso.setHorizontalAlignment(Element.ALIGN_CENTER);
    obs.setHorizontalAlignment(Element.ALIGN_LEFT);
    ass.setHorizontalAlignment(Element.ALIGN_CENTER);

    obs.setBorder(0);//w w w.  j a va 2s . c  o  m
    ass.setBorder(0);
    spc.setBorder(0);
    aviso.setBorder(0);

    spc.setColspan(3);
    aviso.setColspan(3);

    rodape.addCell(obs);
    rodape.addCell(new Paragraph(" "));
    rodape.addCell(ass);
    rodape.addCell(spc);
    rodape.addCell(spc);
    rodape.addCell(spc);
    rodape.addCell(spc);
    rodape.addCell(aviso);
    //rodape.setExtendLastRow(true);

    //cria uma nova celula que recebe a tabela anterior
    PdfPCell otherCell = new PdfPCell(rodape);
    otherCell.setBorder(0);
    otherCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    otherCell.setHorizontalAlignment(Element.ALIGN_CENTER);

    //cria uma nova tabela que recebe a celula otherCell
    PdfPTable rodape2 = new PdfPTable(new float[] { 1.0f });
    rodape2.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento

    rodape2.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    rodape2.getDefaultCell().setBorder(0);

    //estende a tabela at o fim da pagina, como o alinhamento horizontal dela  bottom, ela fica toda no rodape
    rodape2.addCell(otherCell);
    rodape2.setExtendLastRow(true);

    return rodape2;
}