Example usage for com.itextpdf.text Element ALIGN_CENTER

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

Introduction

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

Prototype

int ALIGN_CENTER

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

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:com.pdg.ticket.utils.FirstPdf.java

private static void createTable(Section subCatPart) throws BadElementException {
    PdfPTable table = new PdfPTable(3);

    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.RED);
    table.addCell(c1);//from  w ww .jav a2 s.  c  o  m

    c1 = new PdfPCell(new Phrase("Table Header 2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Table Header 3"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    table.addCell("1.0");
    table.addCell("1.1");
    table.addCell("1.2");
    table.addCell("2.1");
    table.addCell("2.2");
    table.addCell("2.3");

    subCatPart.add(table);

}

From source file:com.pearson.controller.PdfGentrate.java

public static void main(String[] args) {

    try {/*from  w  ww.  j av  a  2s  .co  m*/
        /*Document document = new Document(PageSize.
        A4, 50, 50, 50, 50);
        PdfWriter writer = PdfWriter.getInstance
        (document, new FileOutputStream("C:\\my.pdf"));
        document.open();               
        // create a chunk object using chunk class  of itext library.
        Chunk underlined = new Chunk("Welcome to Pearson Q-Service Portal : ");   
        // set the distance between text and line.
        underlined.setTextRise(8.0f);      
        // set the width of the line, 'y' position,  color and design of the line
        underlined.setUnderline(new Color(0x00, 0x00, 0xFF),0.0f, 0.2f, 3.0f, 0.0f, PdfContentByte.LINE_CAP_PROJECTING_SQUARE);      // finally add object to the document.
        document.add(underlined);
        document.add(new Paragraph("Hi username",
        FontFactory.getFont(FontFactory.COURIER, 14, 
        Font.BOLD, new Color(255, 150, 200))));;
                 
                
             document.add(new Paragraph("Tiltle",catFont));
             document.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
               smallBold));
             document.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
               redFont));
                     
             PdfPTable table = new PdfPTable(3); // 3 columns.   
            table.setWidthPercentage(100); //Width 100%     
            table.setSpacingBefore(10f); //Space before table    
             table.setSpacingAfter(10f); //Space after table         //Set Column widths     
            float[] columnWidths = {1f, 1f, 1f};     
            table.setWidths(columnWidths);    
            PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1"));     
            cell1.setBorderColor(BaseColor.BLUE);     
            cell1.setPaddingLeft(10);     
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);     
            cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);    
            PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2"));    
          cell2.setBorderColor(BaseColor.GREEN);    
          cell2.setPaddingLeft(10);    
          cell2.setHorizontalAlignment(Element.ALIGN_CENTER);      
            cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);      
            PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3"));   
            cell3.setBorderColor(BaseColor.RED);      
            cell3.setPaddingLeft(10);      
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);    
          cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);   
            //To avoid having the cell border and the content overlap, if you are having thick cell borders     
            //cell1.setUserBorderPadding(true);     
            //cell2.setUserBorderPadding(true);   
            //cell3.setUserBorderPadding(true);   
            table.addCell(cell1);   
          table.addCell(cell2);   
          table.addCell(cell3);     
             document.add(table);     
             document.close();     
             writer.close();
                    
                  
                
        document.close();
        } 
        catch (Exception e2) {
        System.out.println(e2.getMessage());
        }
        }*/

        Document document = new Document();

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddTableExample.pdf"));
        document.open();
        PdfPTable table = new PdfPTable(3); // 3 columns.      
        table.setWidthPercentage(100); //Width 100%       
        table.setSpacingBefore(10f); //Space before table    
        table.setSpacingAfter(10f); //Space after table         //Set Column widths     
        float[] columnWidths = { 1f, 1f, 1f };
        table.setWidths(columnWidths);
        PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1"));
        cell1.setBorderColor(BaseColor.BLUE);
        cell1.setPaddingLeft(10);
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
        PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2"));
        cell2.setBorderColor(BaseColor.GREEN);
        cell2.setPaddingLeft(10);
        cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
        PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3"));
        cell3.setBorderColor(BaseColor.RED);
        cell3.setPaddingLeft(10);
        cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
        //To avoid having the cell border and the content overlap, if you are having thick cell borders        //cell1.setUserBorderPadding(true);        //cell2.setUserBorderPadding(true);   
        //cell3.setUserBorderPadding(true);    
        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        document.add(table);
        document.close();
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Adds title section.//from  ww w .  ja va2s  . c o m
 * @param info the project info object
 * @return PDF input stream
 * @throws PhrescoException 
 */
public static InputStream getTitleSection(ApplicationInfo info) throws PhrescoException {
    if (isDebugEnabled) {
        S_LOGGER.debug(" Entering Method DocumentUtil.getTitleSection(ProjectInfo info)");
    }
    if (isDebugEnabled) {
        S_LOGGER.debug("getTitleSection() projectCode=" + info.getCode());
    }
    try {
        //create output stream
        com.itextpdf.text.Document docu = new com.itextpdf.text.Document();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PdfWriter.getInstance(docu, os);
        docu.open();

        //add standard title section with supplied info object
        Paragraph paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.setFont(DocConstants.TITLE_FONT);
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        paragraph.add(info.getName());
        addBlankLines(paragraph, MAGICNUMBER.BLANKLINESFOUR);
        docu.add(paragraph);

        paragraph = new Paragraph();
        paragraph.setAlignment(Element.ALIGN_CENTER);
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        String techName = info.getTechInfo().getName();
        if (StringUtils.isNotEmpty(info.getTechInfo().getVersion())) {
            paragraph.add(techName + " - " + info.getTechInfo().getVersion());
        } else {
            paragraph.add(techName);
        }
        docu.add(paragraph);

        paragraph = new Paragraph();
        addBlankLines(paragraph, MAGICNUMBER.DOCLINES);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        paragraph.add(DocumentMessages.getString("Documents.version.name") + getVersion(info)); //$NON-NLS-1$
        addBlankLines(paragraph, MAGICNUMBER.BLANKLINESSEVEN);
        docu.add(paragraph);

        if (StringUtils.isNotEmpty(info.getDescription())) {
            paragraph = new Paragraph();
            paragraph.setAlignment(Element.ALIGN_RIGHT);
            paragraph.setFont(DocConstants.DESC_FONT);
            paragraph.setFirstLineIndent(MAGICNUMBER.BLANKLINESEIGHT);
            docu.add(paragraph);

        }

        docu.close();

        //Create an inputstream to return.
        return new ByteArrayInputStream(os.toByteArray());
    } catch (DocumentException e) {
        e.printStackTrace();
        throw new PhrescoException(e);
    }

}

From source file:com.photon.phresco.framework.docs.impl.DocumentUtil.java

License:Apache License

private static void updateDoc(List<ArtifactGroup> modules, com.itextpdf.text.Document docu, PdfWriter writer,
        String moduleName) throws PhrescoException {
    try {//from  w w w  .j av  a 2  s . c  om
        Paragraph para = new Paragraph();
        para.setAlignment(Element.ALIGN_CENTER);
        para.setFont(DocConstants.BODY_FONT);
        para.setFont(DocConstants.CATEGORY_FONT);
        para.add(moduleName);
        addBlankLines(para, MAGICNUMBER.BLANKLINESTWO);
        docu.add(para);

        for (ArtifactGroup artifactGroup : modules) {
            para = new Paragraph();
            para.setFont(DocConstants.CATEGORY_FONT);
            para.add(artifactGroup.getName());
            docu.add(para);

            if (StringUtils.isNotEmpty(artifactGroup.getDescription())) {
                para = new Paragraph();
                para.setFont(DocConstants.BODY_FONT);
                para.add(artifactGroup.getDescription());
                addBlankLines(para, 2);
                docu.add(para);
            }
            //          Documentation document = tupleBean.getDoc(DocumentationType.DESCRIPTION);
            //          if (document != null) {
            //              if(!StringUtils.isEmpty(document.getUrl())){
            //                  PdfInput convertToPdf = DocConvertor.convertToPdf(document.getUrl());
            //                  if(convertToPdf != null) {
            //                      DocumentUtil.addPages(convertToPdf.getInputStream(), writer, docu);
            //                  }
            //              } else {
            //                  para = new Paragraph();
            //                  para.setFont(DocConstants.BODY_FONT);
            //                  para.add(document.getContent());
            //                  addBlankLines(para, 2);
            //                  docu.add(para);
            //              }
            //          }
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        throw new PhrescoException(e);
    }
}

From source file:com.photon.phresco.service.docs.impl.DocumentUtil.java

License:Apache License

/**
 * Adds title section./*from  w w  w  . j  ava2  s .c om*/
 * @param info the project info object
 * @return PDF input stream
 * @throws DocumentException
 */
public static InputStream getTitleSection(ProjectInfo info) throws DocumentException {
    if (isDebugEnabled) {
        S_LOGGER.debug(" Entering Method DocumentUtil.getTitleSection(ProjectInfo info)");
    }
    if (isDebugEnabled) {
        S_LOGGER.debug("getTitleSection() projectCode=" + info.getCode());
    }
    //create output stream
    com.itextpdf.text.Document docu = new com.itextpdf.text.Document();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PdfWriter.getInstance(docu, os);
    docu.open();

    //add standard title section with supplied info object
    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setFont(DocConstants.TITLE_FONT);
    addBlankLines(paragraph, 10);
    paragraph.add(info.getName());
    addBlankLines(paragraph, 4);
    docu.add(paragraph);

    paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_CENTER);
    addBlankLines(paragraph, 10);
    String techName = info.getTechnology().getName();
    if (info.getTechnology().getVersions() != null) {
        paragraph.add(techName + " - " + info.getTechnology().getVersions().get(0));
    } else {
        paragraph.add(techName);
    }
    docu.add(paragraph);

    paragraph = new Paragraph();
    addBlankLines(paragraph, 10);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.add(DocumentMessages.getString("Documents.version.name") + getVersion(info)); //$NON-NLS-1$
    addBlankLines(paragraph, 7);
    docu.add(paragraph);
    paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_RIGHT);
    paragraph.setFont(DocConstants.DESC_FONT);
    paragraph.setFirstLineIndent(8);
    paragraph.add(info.getDescription());
    docu.add(paragraph);

    docu.close();

    //Create an inputstream to return.
    return new ByteArrayInputStream(os.toByteArray());

}

From source file:com.photon.phresco.service.docs.impl.DocumentUtil.java

License:Apache License

private static void updateDoc(List<ModuleGroup> modules, com.itextpdf.text.Document docu, PdfWriter writer,
        String moduleName) throws DocumentException, PhrescoException, IOException {
    Paragraph para = new Paragraph();
    para.setAlignment(Element.ALIGN_CENTER);
    para.setFont(DocConstants.BODY_FONT);
    para.setFont(DocConstants.CATEGORY_FONT);
    para.add(moduleName);//from   www.ja  va2s  .co  m
    addBlankLines(para, 2);
    docu.add(para);

    for (ModuleGroup tupleBean : modules) {
        para = new Paragraph();
        para.setFont(DocConstants.CATEGORY_FONT);
        para.add(tupleBean.getName());
        docu.add(para);
        Documentation document = tupleBean.getDoc(DocumentationType.DESCRIPTION);
        if (document != null) {
            if (!StringUtils.isEmpty(document.getUrl())) {
                PdfInput convertToPdf = DocConvertor.convertToPdf(document.getUrl());
                if (convertToPdf != null) {
                    DocumentUtil.addPages(convertToPdf.getInputStream(), writer, docu);
                }
            } else {
                para = new Paragraph();
                para.setFont(DocConstants.BODY_FONT);
                para.add(document.getContent());
                addBlankLines(para, 2);
                docu.add(para);
            }
        }
    }
}

From source file:com.photoshop.misc.Factuurgenerator.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);/*  w  w  w  . j  a  v a2s  .co  m*/

    Image Logo = null;
    try {
        Logo = Image.getInstance(env.getProperty("logo") + "Photoshop_black.png");
        Logo.scaleAbsolute(200, 100);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, null, ex);
    }
    SimpleDateFormat simpledatafo = new SimpleDateFormat("dd/MM/yyyy");
    preface.add(Logo);
    Paragraph datum = new Paragraph(this.Getspringmessage("Date") + ": " + simpledatafo.format(new Date()),
            smallBold);
    datum.setAlignment(Element.ALIGN_RIGHT);
    preface.add(datum);
    Paragraph Factuurnummer = new Paragraph(this.Getspringmessage("invoicenumber") + ": " + order.getId(),
            smallBold);
    Factuurnummer.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Factuurnummer);
    addEmptyLine(preface, 1);

    //Aanmaken van de bedrijfs gegevens
    preface.add(new Paragraph(this.Getspringmessage("company"), subtitel));
    preface.add(new Paragraph("Rachelsmolen 1", subFont));
    preface.add(new Paragraph("5612MA Eindhoven", subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(this.Getspringmessage("accountNumber") + ": 165947888", subFont));
    preface.add(new Paragraph("Bank: Paypal", subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de bestellende persoons gegevens
    preface.add(new Paragraph(this.Getspringmessage("reciver") + ":", subtitel));
    preface.add(new Paragraph(order.getInvoiceaddress().getKlantnaam(), subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(order.getInvoiceaddress().getAdres(), subFont));
    preface.add(new Paragraph(
            order.getInvoiceaddress().getPostcode() + " " + order.getInvoiceaddress().getWoonplaats(),
            subFont));
    preface.add(new Paragraph(order.getInvoiceaddress().getTelefoonnummer(), subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de start zin 
    preface.add(new Paragraph(
            this.Getspringmessage("dear") + " " + order.getInvoiceaddress().getKlantnaam() + ",", subtitel));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(this.Getspringmessage("paymentvieuw"), subFont));
    addEmptyLine(preface, 1);
    //Aanmaken van de betaal tabel
    createTable(preface);
    //Overzicht bwt bedrag
    addEmptyLine(preface, 1);
    Paragraph btw = new Paragraph(this.Getspringmessage("taxamount") + ": " + " "
            + String.format("%.2f", (this.totaalprijs / 100) * 19), subFont);
    btw.setAlignment(Element.ALIGN_RIGHT);
    preface.add(btw);
    //Overzicht Totaalbedrag
    Paragraph Totaalbedrag = new Paragraph(
            this.Getspringmessage("totalamount") + ": " + " " + String.format("%.2f", this.totaalprijs),
            subtitel);
    Totaalbedrag.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Totaalbedrag);
    addEmptyLine(preface, 1);

    //Toevoegen footerzin
    Paragraph footer = new Paragraph(this.Getspringmessage("invoicend"), subFont);
    footer.setAlignment(Element.ALIGN_CENTER);
    preface.add(footer);
    document.add(preface);
    Mailgenerator mail = new Mailgenerator();
    mail.Sendmail("willem1995@hotmail.com", order, env, filename);
}

From source file:com.photoshop.misc.Factuurgenerator.java

private void creatCell(String cellnaam, PdfPTable table, boolean header) {
    if (header == true) {
        Font font = new Font(FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.WHITE);
        PdfPCell c1 = new PdfPCell(new Phrase(cellnaam, font));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setBackgroundColor(new BaseColor(0, 121, 182));
        c1.setMinimumHeight(20);// w w  w .  jav a 2 s.  c o m
        table.addCell(c1);
    }
    if (header == false) {
        PdfPCell c1 = new PdfPCell(new Phrase(cellnaam));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }
}

From source file:com.photoshop.misc.Indexkaartgenerator.java

private void addTitlePage(Document document) throws DocumentException {
    document.newPage();/*from   w  ww . ja  v  a 2 s. c  o  m*/
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);

    Image Logo = null;
    try {
        Logo = Image.getInstance(env.getProperty("logo") + "Photoshop_black.png");
        Logo.scaleAbsolute(200, 100);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(OrderController.class.getName()).log(Level.SEVERE, null, ex);
    }
    SimpleDateFormat simpledatafo = new SimpleDateFormat("dd/MM/yyyy");
    preface.add(Logo);
    Paragraph datum = new Paragraph(Getspringmessage("Date") + " " + simpledatafo.format(new Date()),
            smallBold);
    datum.setAlignment(Element.ALIGN_RIGHT);
    preface.add(datum);
    Paragraph Factuurnummer = new Paragraph(this.Getspringmessage("invoicenumber") + " " + order.getId(),
            smallBold);
    Factuurnummer.setAlignment(Element.ALIGN_RIGHT);
    preface.add(Factuurnummer);
    addEmptyLine(preface, 1);

    //Aanmaken van de bedrijfs gegevens
    preface.add(new Paragraph(this.Getspringmessage("company"), subtitel));
    preface.add(new Paragraph("Rachelsmolen 1", subFont));
    preface.add(new Paragraph("5612MA Eindhoven", subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(this.Getspringmessage("accountNumber") + ": 165947888", subFont));
    preface.add(new Paragraph("Bank: Paypal", subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de bestellende persoons gegevens
    preface.add(new Paragraph(this.Getspringmessage("reciver") + ": ", subtitel));
    preface.add(new Paragraph(order.getInvoiceaddress().getKlantnaam(), subFont)); //order nummer ingelezen worde
    preface.add(new Paragraph(order.getInvoiceaddress().getAdres(), subFont));
    preface.add(new Paragraph(
            order.getInvoiceaddress().getPostcode() + " " + order.getInvoiceaddress().getWoonplaats(),
            subFont));
    preface.add(new Paragraph(order.getInvoiceaddress().getTelefoonnummer(), subFont));
    addEmptyLine(preface, 1);

    //Aanmaken van de start zin 
    preface.add(new Paragraph(this.Getspringmessage("dear") + " " + order.getInvoiceaddress().getKlantnaam(),
            subtitel));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(
            this.Getspringmessage("allordersby") + " " + order.getInvoiceaddress().getKlantnaam(), subFont));
    addEmptyLine(preface, 1);
    //Aanmaken van de betaal tabel
    createTable(preface);

    //Toevoegen footerzin
    Paragraph footer = new Paragraph(this.Getspringmessage("thanksforordering"), subFont);
    footer.setAlignment(Element.ALIGN_CENTER);
    preface.add(footer);

    document.add(preface);

}

From source file:com.photoshop.misc.Indexkaartgenerator.java

private void creatCell(String cellnaam, PdfPTable table, boolean header) {
    if (header == true) {
        Font font = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD, BaseColor.WHITE);
        PdfPCell c1 = new PdfPCell(new Phrase(cellnaam, font));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setBackgroundColor(new BaseColor(0, 121, 182));
        c1.setMinimumHeight(20);//from ww  w  . j a v a  2s . com
        table.addCell(c1);
    }
    if (header == false) {
        PdfPCell c1 = new PdfPCell(new Phrase(cellnaam));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }
}