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:com.solidmaps.webapp.report.MapCivilPdfGenerator.java

License:Open Source License

private void createSignature(Document doc) throws DocumentException {

    Calendar currDate = Calendar.getInstance();

    StringBuilder sbSignature = new StringBuilder().append(company.getCity()).append(", ")
            .append(DateUtils.getDay(currDate.getTime())).append(" de ")
            .append(DateUtils.getMonthName(currDate)).append(" de ")
            .append(DateUtils.getYear(currDate.getTime()));

    StringBuilder sbUser = new StringBuilder().append("P.P_________________________________________________ \n")
            .append("Nome: ").append(company.getUserResponsable().getName()).append("\n")
            .append("RG: " + company.getUserResponsable().getRg());

    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);/*from  w w  w  .j  a  va  2s.  co  m*/
    table.setHeaderRows(0);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    insertCell(table, sbSignature.toString(), Element.ALIGN_LEFT, fontHeaderTable, false);
    insertCell(table, sbUser.toString(), Element.ALIGN_LEFT, fontHeaderTable, false);

    doc.add(Chunk.NEWLINE);
    doc.add(table);
}

From source file:com.solidmaps.webapp.report.MapCivilPdfGenerator.java

License:Open Source License

private void createParagraph(Document doc) throws DocumentException {

    float[] columnWidths = { 2f, 2f };
    PdfPTable table = new PdfPTable(columnWidths);
    table.setWidthPercentage(100f);/* ww  w.j  a v a  2  s. c om*/

    StringBuilder sbHeader = new StringBuilder()
            .append("SECRETARIA DE ESTADO DOS NEGCIOS DA SEGURANA PBLICA \n")
            .append("POL?CIA CIVIL DO ESTADO DE ").append(company.getState()).append("\n")
            .append("DEPARTAMENTO DE IDENTIFICAO E REGISTROS DIVERSOS \n")
            .append("DIVISO DE PRODUTOS CONTROLADOS \n");

    StringBuilder sbHeaderMonth = new StringBuilder().append("MAPA TRIMESTRAL DEMONSTRATIVO DO ESTOQUE \n")
            .append("DE COMPRAS, VENDAS E CONSUMO \n").append("REFERENTE AO ")
            .append(mapProduct.getNumTrimester()).append(" TRIMESTRE DO ANO DE ").append(mapProduct.getYear())
            .append(".");

    StringBuilder sbCompany = new StringBuilder().append("Empresa: ").append(company.getName().toUpperCase())
            .append(" estabelecida  ").append(company.getStreet().toUpperCase()).append(" Cidade: ")
            .append(company.getCity()).append(", Estado: ").append(company.getState()).append(", CEP: ")
            .append(company.getCep()).append(", Fone: (").append(company.getUserResponsable().getPhoneDDD())
            .append(") ").append(company.getUserResponsable().getPhoneNumber()).append(", Fax: (")
            .append(company.getUserResponsable().getPhoneDDD()).append(") ")
            .append(company.getUserResponsable().getNumFax());

    // insert column headings
    insertCell(table, sbHeader.toString(), Element.ALIGN_LEFT, fontParagraph);
    insertCell(table, sbHeaderMonth.toString(), Element.ALIGN_LEFT, fontText);

    Paragraph paragraphText = new Paragraph(sbCompany.toString());
    paragraphText.setFont(fontHeaderTable);

    doc.add(Chunk.NEWLINE);
    doc.add(table);
    doc.add(Chunk.NEWLINE);
    doc.add(paragraphText);
    doc.add(Chunk.NEWLINE);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCell(PdfPTable table, String text, Integer colSpan) {

    if (text == null) {
        text = "";
    }/*from  www .jav  a  2 s.c om*/

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), FONT_PARAGRAPH));
    // set the cell alignment
    // in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setColspan(colSpan);
    cell.setPadding(5f);

    // add the call to the table
    table.addCell(cell);
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCellProtocol(PdfPTable table, LicensePFEntity license) {

    PdfPTable tableProtocol = new PdfPTable(1);
    tableProtocol.setWidthPercentage(100f);

    Paragraph officialPhrase = new Paragraph("USO OFICIAL" + SEPARATOR, FONT_PARAGRAPH);
    officialPhrase.setAlignment(Element.ALIGN_LEFT);

    Paragraph protocolPhrase = new Paragraph("ETIQUETA PROTOCOLO" + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE
            + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR_DOUBLE + SEPARATOR, FONT_PROTOCOL);
    protocolPhrase.setAlignment(Element.ALIGN_LEFT);

    Paragraph obsPhrase = new Paragraph("Observao Importante!" + SEPARATOR, FONT_HEADER);

    Paragraph obsStringPhrase = new Paragraph(
            "Protocolar este Anexo somente quando no conjugado com a alterao efetiva ou a renovao da licena.",
            FONT_PARAGRAPH);//from   w ww . j av  a 2 s. c  om

    Paragraph fullPhrase = new Paragraph();
    fullPhrase.add(officialPhrase);
    fullPhrase.add(protocolPhrase);
    fullPhrase.add(obsPhrase);
    fullPhrase.add(obsStringPhrase);

    PdfPCell cell = new PdfPCell(fullPhrase);

    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(5f);

    tableProtocol.addCell(cell);

    PdfPCell cellProtocol = new PdfPCell(tableProtocol);
    cellProtocol.setColspan(2);

    table.addCell(cellProtocol);
    table.addCell(this.createCellEtiqueta(license));
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private void insertCellAlteracaoOption(PdfPTable table, String number, String text, Boolean selected) {

    String fullText = "";
    if (selected) {
        fullText += number + " |X|" + " " + text;
    } else {/*from  ww w .  j a v  a 2 s  . c  o m*/
        fullText += number + " |  |" + " " + text;
    }

    if (StringUtils.isBlank(number) && StringUtils.isBlank(text)) {
        fullText = "";
    }

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(fullText.trim(), FONT_PARAGRAPH));
    // set the cell alignment
    // in case there is no text and you wan to create an empty row
    if (fullText.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }

    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setColspan(2);
    cell.setBorder(Rectangle.RIGHT);
    cell.setPaddingTop(10f);
    cell.setPaddingBottom(10f);
    cell.setPaddingLeft(25f);
    cell.setPaddingRight(25f);

    // add the call to the table
    table.addCell(cell);
}

From source file:com.thelinh.gui.PreviewExam.java

private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed
    if (this.txtExamCode.getText().equals("")) {
        JOptionPane.showMessageDialog(this, "Hy nhp m ?");
    } else {/*  w  w  w .  jav  a2 s  .c  om*/
        JFileChooser fc = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("PDF files (*.pdf)", "pdf");
        fc.setFileFilter(filter);
        int rt = fc.showSaveDialog(this);
        if (rt == JFileChooser.APPROVE_OPTION) {
            String filepath = fc.getSelectedFile().getPath();
            if (filepath.indexOf(".") == -1) {
                filepath = filepath + ".pdf";
            }
            String dafilepath = (new StringBuffer(filepath)).insert(filepath.length() - 4, ".da").toString();
            try {
                Document document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream(filepath));
                document.open();

                // Add title
                Paragraph p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25);
                p.setAlignment(Element.ALIGN_CENTER);
                p.setSpacingAfter(5);
                document.add(p);

                p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25);
                p.setAlignment(Element.ALIGN_CENTER);
                p.setSpacingAfter(25);
                document.add(p);

                p = new Paragraph(
                        "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName()
                                + ", Ngy ra ?: "
                                + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())),
                        times_15);
                p.setAlignment(Element.ALIGN_LEFT);
                p.setSpacingAfter(5);
                document.add(p);

                p = new Paragraph("M ?: " + this.txtExamCode.getText() + "    Th?i gian lm bi: "
                        + spTime.getValue().toString() + " pht", timesBold_15);
                p.setSpacingAfter(25);
                document.add(p);

                for (int i = 0; i < this.questionList.size(); i++) {
                    Question question = this.questionList.get(i);
                    ArrayList<Answer> answerList = AnswerSql
                            .getAnswersByQuestionId(question.getQuestionId().trim());
                    Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15);
                    Phrase questionContent = new Phrase(question.getQuestion(), times_15);

                    Paragraph questionTitle = new Paragraph();
                    questionTitle.add(questionNumber);
                    questionTitle.add(questionContent);

                    document.add(questionTitle);
                    PdfPTable table = new PdfPTable(2);

                    for (int j = 0; j < answerList.size(); j++) {
                        Answer ans = answerList.get(j);
                        Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15);
                        Phrase answerContent = new Phrase(ans.getAnswer(), times_15);
                        Phrase elem = new Phrase();
                        elem.add(cap);
                        elem.add(answerContent);
                        PdfPCell cell = new PdfPCell();

                        cell.setBorder(Rectangle.NO_BORDER);
                        cell.setPhrase(elem);
                        cell.setFixedHeight(25);
                        table.addCell(cell);
                    }
                    document.add(table);
                }
                document.close();
                //                    if (Desktop.isDesktopSupported()) {
                //                        try {
                //                            File myFile = new File(filepath);
                //                            Desktop.getDesktop().open(myFile);
                //                        } catch (IOException ex) {
                //                            // no application registered for PDFs
                //                            System.out.println(ex.toString());
                //                        }
                //                    }

                document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream(dafilepath));
                document.open();

                // Add title
                p = new Paragraph("Tr?ng ?i h?c Bch Khoa H Ni", timesBold_25);
                p.setAlignment(Element.ALIGN_CENTER);
                p.setSpacingAfter(5);
                document.add(p);

                p = new Paragraph("?? thi mn " + this.lbSubject.getText(), timesBold_25);
                p.setAlignment(Element.ALIGN_CENTER);
                p.setSpacingAfter(25);
                document.add(p);

                p = new Paragraph(
                        "Ng?i ra ?: " + Controller.getCurrentAdmin().getAdminName()
                                + ", Ngy ra ?: "
                                + (new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime())),
                        times_15);
                p.setAlignment(Element.ALIGN_LEFT);
                p.setSpacingAfter(5);
                document.add(p);

                p = new Paragraph("M ?: " + this.txtExamCode.getText() + "    Th?i gian lm bi: "
                        + spTime.getValue().toString() + " pht", timesBold_15);
                p.setSpacingAfter(25);
                document.add(p);

                for (int i = 0; i < this.questionList.size(); i++) {
                    Question question = this.questionList.get(i);
                    ArrayList<Answer> answerList = AnswerSql
                            .getAnswersByQuestionId(question.getQuestionId().trim());
                    Phrase questionNumber = new Phrase("Cu " + (i + 1) + ": ", timesBold_15);
                    Phrase questionContent = new Phrase(question.getQuestion(), times_15);

                    Paragraph questionTitle = new Paragraph();
                    questionTitle.add(questionNumber);
                    questionTitle.add(questionContent);

                    document.add(questionTitle);
                    PdfPTable table = new PdfPTable(2);

                    for (int j = 0; j < answerList.size(); j++) {
                        Answer ans = answerList.get(j);
                        Phrase cap = new Phrase(Character.toString((char) (j + 65)) + ". ", timesBold_15);
                        Phrase answerContent = null;
                        if (ans.getYesNo()) {
                            answerContent = new Phrase(ans.getAnswer(), timesBold_15);
                        } else {
                            answerContent = new Phrase(ans.getAnswer(), times_15);
                        }
                        Phrase elem = new Phrase();
                        elem.add(cap);
                        elem.add(answerContent);
                        PdfPCell cell = new PdfPCell();

                        cell.setBorder(Rectangle.NO_BORDER);
                        cell.setPhrase(elem);
                        cell.setFixedHeight(25);
                        table.addCell(cell);
                    }
                    document.add(table);
                }
                document.close();

            } catch (FileNotFoundException | DocumentException ex) {
                Logger.getLogger(PreviewExam.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

From source file:com.vectorprint.report.itext.debug.DebugHelper.java

License:Open Source License

public static void debugBackground(PdfContentByte canvas, Rectangle rect, BaseColor color, String prefix,
        EnhancedMap settings, LayerManager layerAware) {
    canvas = canvas.getPdfWriter().getDirectContentUnder();
    int rgb = color.getRed() + color.getBlue() + color.getGreen();
    rect.setBackgroundColor(color);/*from  w w w  . j a  va 2 s  .c o  m*/
    canvas.rectangle(rect);
    layerAware.startLayerInGroup(DEBUG, canvas);
    debugFont(canvas, settings);
    BaseColor txtColor = (rgb < 150) ? color.brighter().brighter() : color.darker().darker();
    canvas.setColorFill(txtColor);
    canvas.setColorStroke(txtColor);
    canvas.beginText();
    canvas.showTextAligned(Element.ALIGN_LEFT, prefix + color.toString().replace(Color.class.getName(), ""),
            rect.getLeft() + rect.getWidth() / 2, rect.getTop() - rect.getHeight() / 2, 0);
    canvas.endText();
    canvas.endLayer();
}

From source file:com.vectorprint.report.itext.debug.DebugHelper.java

License:Open Source License

public static void styleLink(PdfContentByte canvas, String styleClass, String extraInfo, float x, float y,
        EnhancedMap settings, LayerManager layerAware) {
    if (styleClass == null) {
        log.warning("not showing link to styleClass because there is no styleClass");
        return;/*from w w w .java  2s .c  o  m*/
    }
    Font dbf = DebugHelper.debugFontLink(canvas, settings);
    layerAware.startLayerInGroup(DEBUG, canvas);

    PdfAction act = PdfAction.gotoLocalPage(styleClass, true);
    Chunk c = new Chunk(styleClass + extraInfo, dbf);
    float w = ItextHelper.getTextWidth(c);
    float h = ItextHelper.getTextHeight(c);
    float tan = (float) Math.tan(Math.toRadians(8));
    canvas.setAction(act, x, y, x + w, y + h + tan * w);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(c), x, y, 8);
    canvas.endLayer();
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * when failure information is appended to the report, a header on each page will be printed refering to this
 * information.//from  w  w  w.  j ava  2s . c o m
 *
 * @param template
 * @param x
 * @param y
 */
protected void printFailureHeader(PdfTemplate template, float x, float y) {
    Font f = DebugHelper.debugFontLink(template, getSettings());
    Chunk c = new Chunk(getSettings().getProperty("failures in report, see end of report", "failureheader"), f);
    ColumnText.showTextAligned(template, Element.ALIGN_LEFT, new Phrase(c), x, y, 0);
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * When the setting {@link ReportConstants#PRINTFOOTER} is true prints the total number of pages on each page when
 * the document is closed. Note that//from w w w  .j a  va 2s .  c  o  m
 *
 * @param template
 * @see #PAGEFOOTERSTYLEKEY
 * @param x
 * @param y
 */
protected void printTotalPages(PdfTemplate template, float x, float y)
        throws VectorPrintException, InstantiationException, IllegalAccessException {
    if (getSettings().getBooleanProperty(Boolean.FALSE, ReportConstants.PRINTFOOTER)) {
        Phrase p = elementProducer.createElement(String.valueOf(lastPage), Phrase.class,
                stylerFactory.getStylers(PAGEFOOTERSTYLEKEY));
        ColumnText.showTextAligned(template, Element.ALIGN_LEFT, p, x, y, 0);
    }
}