Example usage for com.lowagie.text Document add

List of usage examples for com.lowagie.text Document add

Introduction

In this page you can find the example usage for com.lowagie.text Document add.

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:com.infinity.controller.PDFView.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document dcmnt, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {

    List words = (List) map.get("wordList");
    for (Object word : words) {
        dcmnt.add(new Paragraph((String) word));
    }//from  w w  w. ja va 2 s .  c  o  m
}

From source file:com.isdemu.controller.DepreciacionController.java

@RequestMapping(value = "/ExcelReporteInvPersona2", method = RequestMethod.GET)
@ResponseBody// w w  w  .  j  a  va 2 s.  c  o  m

public void getRptAsig2(HttpServletResponse response)
        throws JRException, IOException, SQLException, ClassNotFoundException {
    Document document = new Document();
    try {
        response.setContentType("application/pdf");
        PdfWriter.getInstance(document, response.getOutputStream());
        document.open();
        document.add(new Paragraph("howtodoinjava.com"));
        document.add(new Paragraph(new Date().toString()));
        //Add more content here
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("response :" + response);
    document.close();
}

From source file:com.isdemu.controller.TBS_UsuarioController.java

@RequestMapping(value = "/codigo_barra", method = RequestMethod.POST)
@ResponseBody//from w w w.  jav  a2 s  . c  o m
public String codigo(@RequestBody String codigos) throws FileNotFoundException, DocumentException {

    JSONObject array = new JSONObject(codigos);

    Document document = new Document();

    File file = new File(this.getClass().getResource("/codigoBarraIsdemu.pdf").getFile());

    String absolutePath = file.getAbsolutePath();

    absolutePath = absolutePath.replaceAll("%20", " ");

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(absolutePath));

    Rectangle one = new Rectangle(76, 35);
    document.setPageSize(one);
    document.setMargins(2, 2, 2, 2);

    document.open();

    Barcode128 code128 = new Barcode128();
    code128.setGenerateChecksum(true);

    JSONArray object = array.getJSONArray("Inventario");
    for (int i = 0; i < object.length(); i++) {
        JSONObject object2 = object.getJSONObject(i);

        //JSONArray object = array.getJSONArray("Inventario");
        String id = object2.getString("idInv");

        code128.setCode(id);
        document.add(code128.createImageWithBarcode(writer.getDirectContent(), null, null));

        document.newPage();

    }

    document.close();

    return "Almacenado";

}

From source file:com.itext.test.FirstPdf.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // ?/*from   w ww  .ja va 2  s  .co m*/
    addEmptyLine(preface, 1);
    // 
    preface.add(new Paragraph("Title of the document", catFont));
    //?
    addEmptyLine(preface, 1);
    // ?: Report generated by: _name, _date
    preface.add(new Paragraph(
            "Report generated by: " + System.getProperty("user.name") + ", " + new java.util.Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));
    //?8
    addEmptyLine(preface, 8);
    //??
    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
            redFont));
    //?document
    document.add(preface);
    //
    document.newPage();
}

From source file:com.itext.test.FirstPdf.java

private static void addContent(Document document) throws DocumentException {
    ///*from   w  ww  .j av a2s  .c  o m*/
    //   Anchor anchor = new Anchor();
    //
    //anchor.setName("First Chapter");
    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(), 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"));

    //List
    createList(subCatPart);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // Table
    createTable(subCatPart);

    // document
    document.add(catPart);

    // Next section

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph("a"), 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.itn.excelDao.PdfView.java

@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    //Users user = (Users) model.get("user");
    List<Users> userlist = (List<Users>) model.get("allUsers");

    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setBackgroundColor(Color.lightGray);

    table.addCell("ID");
    table.addCell("First Name");
    table.addCell("Last Name");
    table.addCell("Email");

    for (Users users : userlist) {
        table.addCell(users.getId().toString());
        table.addCell(users.getFirstName());
        table.addCell(users.getLastName());
        table.addCell(users.getEmail());
    }//from  w ww  . ja  v a2s  .co m

    document.add(table);

}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeTitle(Document document, String title) throws Exception {
    Paragraph titleParagraph = new Paragraph(title, titleFont);
    titleParagraph.setAlignment(Element.ALIGN_LEFT);
    titleParagraph.setLeading(30);//from  w  ww  .  jav a 2 s  .c  o m
    titleParagraph.setSpacingAfter(2);
    document.add(titleParagraph);
}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeSubTitle(Document document, String title) throws Exception {
    Paragraph titleParagraph = new Paragraph(title, subTitleFont);
    titleParagraph.setAlignment(Element.ALIGN_LEFT);
    titleParagraph.setLeading(20);/*w w  w  . jav a  2  s .  c  o m*/
    titleParagraph.setSpacingAfter(2);
    document.add(titleParagraph);
}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeEntry(Document document, String label, String value) throws Exception {
    Paragraph questionParagraph = new Paragraph();
    questionParagraph.setLeading(14, 0);
    questionParagraph.setIndentationLeft(18);
    questionParagraph.add(new Chunk(label.trim() + ": ", boldedFont));
    questionParagraph.add(new Chunk(value == null ? "" : value.trim(), normalFont));
    document.add(questionParagraph);
}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeEntry(Document document, String label) throws Exception {
    Paragraph questionParagraph = new Paragraph();
    questionParagraph.setLeading(14, 0);
    questionParagraph.setIndentationLeft(18);
    questionParagraph.add(new Chunk(label.trim(), boldedFont));
    document.add(questionParagraph);
}