Example usage for com.itextpdf.text Paragraph Paragraph

List of usage examples for com.itextpdf.text Paragraph Paragraph

Introduction

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

Prototype

public Paragraph(Phrase phrase) 

Source Link

Document

Constructs a Paragraph with a certain Phrase.

Usage

From source file:com.mycompany.mavenproject2.ItemHistoryController.java

@FXML
public void OnPrintButtonAction(ActionEvent a) {
    Document document = new Document();
    //JavaPdfHelloWorld jp=new JavaPdfHelloWorld();

    try {//from  w  w w . ja va 2 s . co m
        PdfWriter.getInstance(document, new FileOutputStream("javaHello.pdf"));

        document.open();
        document.add(new Paragraph("A Hello World PDF document."));

        document.close();

        final File file = new File(
                "C:/Users/Third Ev/Documents/NetBeansProjects/FinalDemo/src/finaldemo/Controller/javaHello.pdf");

        f4.getHostServices().showDocument(file.toURI().toString());

        // no need to close PDFwriter?
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:com.mycompany.mavenproject2.JavaPdfHelloWorld.java

public static void main(String[] args) {
    Document document = new Document();
    try {/* www. j av  a2s. c  o  m*/
        PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));

        document.open();
        document.add(new Paragraph("A Hello World PDF document."));
        document.close(); // no need to close PDFwriter?

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.mycompany.mavenproject2.VirtualkeyController.java

private static void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph("\n"));

    }//from  www . j  a  v  a2 s.c o m
}

From source file:com.mycompany.peram_inclassexam.WritePDFFile.java

public void createPDF(AccountDetails account)
        throws DocumentException, FileNotFoundException, BadElementException, IOException {

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    PdfWriter write = PdfWriter.getInstance(document,
            new FileOutputStream(account.getLastName() + "_output.pdf"));

    document.open();/* w w w.  j  a va 2  s.c  o  m*/

    Image image = Image.getInstance("image.png");

    image.scaleToFit(450f, 1800f);

    document.add(image);
    document.add(new Paragraph(
            "--------------------------------------------------------------------------------------------------------------------------"));

    Paragraph welcomeParagraph = new Paragraph(
            "Welcome! " + account.getFirstName() + " " + account.getLastName() + "!");
    welcomeParagraph.setSpacingBefore(50);

    document.add(welcomeParagraph);

    String firstName = "First Name: " + account.getFirstName();
    String lastName = "Last Name: " + account.getLastName();
    String acctNumber = "Account Number: " + account.getAccountNo();
    String acctBalance = String.format("Account Balance: $%.1f", account.getAccountBalance());

    Paragraph detailsPara = new Paragraph("Below are your Account Details:\n" + firstName + "\n" + lastName
            + "\n" + acctNumber + "\n" + acctBalance);
    detailsPara.setIndentationLeft(30);
    detailsPara.setSpacingBefore(20);
    document.add(detailsPara);

    document.close();
    write.close();
}

From source file:com.pdf.GetPdf.java

public static void docConvert(Document document, String url, String type)
        throws IOException, DocumentException {
    WordExtractor we;/*w  w  w .ja va 2 s .c  om*/

    if (type.equals("doc")) {
        HWPFDocument wordDoc = new HWPFDocument(new URL(url).openStream());
        we = new WordExtractor(wordDoc);
        String[] paragraphs = we.getParagraphText();
        for (int i = 0; i < paragraphs.length; i++) {
            paragraphs[i] = paragraphs[i].replaceAll("\\cM?\r?\n", "");
            document.add(new Paragraph(paragraphs[i]));
        }
    } else {
        XWPFDocument wordDoc = new XWPFDocument(new URL(url).openStream());
        List<IBodyElement> contents = wordDoc.getBodyElements();

        for (IBodyElement content : contents) {
            if (content.getElementType() == BodyElementType.PARAGRAPH) {
                List<XWPFParagraph> paras = content.getBody().getParagraphs();
                for (XWPFParagraph para : paras) {
                    document.add(new Paragraph(para.getParagraphText()));
                }

            } else if (content.getElementType() == BodyElementType.TABLE) {
                List<XWPFTable> tables = content.getBody().getTables();
                for (XWPFTable table : tables) {
                    List<XWPFTableRow> rows = table.getRows();
                    for (XWPFTableRow row : rows) {
                        List<XWPFTableCell> tablecells = row.getTableCells();
                    }
                }
            }

        }
    }

}

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

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // Add a list
    //createList(subCatPart);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);//from w w w .j  a  va 2  s  .c o m
    subCatPart.add(paragraph);

    // Add a table
    createTable(subCatPart);

    // Now add all this to the document
    document.add(catPart);

    //      // Next section
    //      anchor = new Anchor("Second Chapter", catFont);
    //      anchor.setName("Second Chapter");
    //
    //      // Second parameter is the number of the chapter
    //      catPart = new Chapter(new Paragraph(anchor), 1);
    //
    //      subPara = new Paragraph("Subcategory", subFont);
    //      subCatPart = catPart.addSection(subPara);
    //      subCatPart.add(new Paragraph("This is a very important message"));
    //
    //      // Now add all this to the document
    //      document.add(catPart);

}

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

public static void main(String[] args) {

    try {/*from   ww  w  .  j  av  a 2s  .  c  om*/
        /*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.planfeed.services.MeetingServiceImpl.java

License:Apache License

public ByteArrayOutputStream getActa(String meetingId) throws Exception {
    Meeting meeting;//from w  w w. j  ava  2s  .  c  om
    try {
        meeting = this.getMeeting(meetingId);
    } catch (Exception e) {
        throw new MeetingNotFound();
    }

    Document document = new Document();
    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfWriter docWriter = null;
    HeaderFooter event = new HeaderFooter(meeting.getDate());
    docWriter = PdfWriter.getInstance(document, baosPDF);
    docWriter.setBoxSize("art", new Rectangle(36, 54, 559, 788));
    docWriter.setPageEvent(event);
    document.open();

    //metadata
    document.addTitle(meeting.getTitle() + " Acta");

    document.add(new Paragraph(" "));

    //Title
    Paragraph title = new Paragraph("Acta of " + meeting.getTitle(), titleFont);
    title.setAlignment(Element.ALIGN_CENTER);

    addEmptyLine(title, 1);

    document.add(title);

    //Description
    Paragraph descriptionPar = new Paragraph();
    descriptionPar.add(new Paragraph("Description", titlePointFont));
    descriptionPar.add(new Paragraph(meeting.getDescription(), textFont));
    addEmptyLine(descriptionPar, 1);
    document.add(descriptionPar);

    //Points
    int index = 1;
    for (PointOfAgenda point : meeting.getAgenda()) {
        Paragraph pointPar = new Paragraph();
        pointPar.add(new Paragraph(index + ". " + point.getName(), titlePointFont));
        pointPar.add(new Paragraph(point.getComment(), textFont));
        addEmptyLine(pointPar, 2);
        document.add(pointPar);
        index += 1;
    }

    document.close();

    return baosPDF;

}

From source file:com.planning.project.controller.CreatePDF.java

private static void creteEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }//from w  ww  .  jav  a 2  s. c  o  m
}

From source file:com.planning.project.controller.CreatePDF.java

private static void creteLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {

        paragraph.add(/*ww  w . ja v a2  s.  c om*/
                new Paragraph("_____________________________________________________________________________"));

    }
}