Example usage for com.itextpdf.text Document add

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

Introduction

In this page you can find the example usage for com.itextpdf.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.shashi.itext.write.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);//ww w  . j a  v a  2s  .co  m
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    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.shiyq.itext.PdfUtil.java

public static void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/*  w  ww  . ja  v a  2  s .c o m*/
    //?
    int fontsize = 10;
    FontSelector selector = getSelector(fontsize);
    String title = "20165??";
    //?
    int titleFontSize = 20;
    //
    addTile(document, title, titleFontSize);
    String describe = "--2016-5-4 12:23:23 ";
    //
    addDescribe(document, describe, selector);
    String[] head = { "??", "?", "?", "????", "??", "",
            "", "??", "??", "???", "????" };
    String[] code = { "card_no", "card_type", "plate", "owner_name", "blance", "start_time", "end_time",
            "month_money", "spread_time", "spread_emp_no", "spread_emp_name" };
    List<Map<String, Object>> list = setList();
    PdfPTable table = new PdfPTable(head.length + 1);
    //
    createTableHead(table, head, selector);
    //
    createTableContent(table, list, code, selector);
    document.add(table);
    document.close();
}

From source file:com.shiyq.itext.PdfUtil.java

private static void addTile(Document document, String title, int titleFontSize) throws DocumentException {
    FontSelector titleSelector = getSelector(titleFontSize);
    Paragraph titleP = new Paragraph(titleSelector.process(title));
    titleP.setAlignment(Element.ALIGN_CENTER);
    document.add(titleP);
    document.add(Chunk.NEWLINE);//  ww  w  . jav a2 s . com
}

From source file:com.shiyq.itext.PdfUtil.java

private static void addDescribe(Document document, String describe, FontSelector selector)
        throws DocumentException {
    Paragraph descP = new Paragraph(selector.process(describe));
    descP.setAlignment(Element.ALIGN_JUSTIFIED);
    descP.setIndentationLeft(document.getPageSize().getRight() * 3 / 7);
    document.add(descP);
    document.add(Chunk.NEWLINE);//ww w  . j  a  v  a 2  s  . c  om
}

From source file:com.skatettoo.reportes.Generador.java

public String generarPDF() throws Exception {
    try {//from ww  w.j  a va2s .c om
        String path = FacesContext.getCurrentInstance().getExternalContext().getRealPath("img");
        path = path.substring(0, path.indexOf("\\build"));
        path = path + "\\web\\img\\";
        Document doc = new Document(PageSize.A4, 36, 36, 10, 10);
        PdfPTable tabla = new PdfPTable(4);
        PdfWriter.getInstance(doc, new FileOutputStream(path + "\\archivo\\reporte.pdf\\"));
        doc.open();
        Image img = Image.getInstance(path + "Skatetoo4.png");
        img.scaleAbsolute(40, 40);
        img.setAlignment(Element.ALIGN_LEFT);
        doc.add(img);
        doc.addTitle(this.titulo);
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        doc.addAuthor("\n ");
        tabla.setWidthPercentage(100);
        tabla.setWidths(new float[] { 1.4f, 0.8f, 0.8f, 0.8f });
        Object font = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.WHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de tatuadores", (Font) font));
        cell.setColspan(4);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPaddingTop(0f);
        cell.setPaddingBottom(7f);
        cell.setBackgroundColor(new BaseColor(0, 0, 0));
        cell.setBorder(0);
        cell.setBorderWidthBottom(2f);
        tabla.addCell(cell);
        tabla.addCell("Tatuador");
        tabla.addCell("Cantidad de diseos");
        tabla.addCell("Citas realizadas");
        tabla.addCell("Noticias publicadas");
        for (Usuario u : this.getUsu()) {
            tabla.addCell(u.getNombre() + " " + u.getApellido());
            tabla.addCell(String.valueOf(u.getDisenioList().size()));
            tabla.addCell(String.valueOf(u.getCitaList1().size()));
            tabla.addCell(String.valueOf(u.getNoticiaList().size()));
        }
        doc.add(tabla);
        doc.bottomMargin();
        /* doc.add(new Paragraph("Tatuador mas solicitado"));
         for(Usuario u : this.getUs()){
        doc.add(new Paragraph(u.getNombre() + " " + u.getApellido()));
         }*/
        doc.close();
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext externalContext = context.getExternalContext();

        externalContext.responseReset();
        externalContext.setResponseContentType("application/pdf");
        externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\"");

        FileInputStream inputStream = new FileInputStream(new File(path + "\\archivo\\reporte.pdf\\"));
        OutputStream outputStream = externalContext.getResponseOutputStream();

        byte[] buffer = new byte[1024];
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, length);
        }

        inputStream.close();
        context.responseComplete();
    } catch (Exception e) {
        throw e;
    }
    return "";
}

From source file:com.softwaremagico.tm.pdf.complete.CharacterSheet.java

License:Open Source License

@Override
protected void createCharacterPDF(Document document, CharacterPlayer characterPlayer) throws Exception {
    PdfPTable mainTable = CharacterBasicsCompleteTableFactory.getCharacterBasicsTable(characterPlayer);
    document.add(mainTable);
    PdfPTable characteristicsTable = CharacteristicsTableFactory.getCharacteristicsBasicsTable(characterPlayer);
    document.add(characteristicsTable);/*from   ww  w. ja v  a2s .c o  m*/
    PdfPTable skillsTable = MainSkillsTableFactory.getSkillsTable(characterPlayer, getLanguage());
    document.add(skillsTable);
    PdfPTable perksTable = MainPerksTableFactory.getPerksTable(characterPlayer);
    document.add(perksTable);
    document.newPage();
    if (characterPlayer == null || characterPlayer.getTotalSelectedPowers() < PSI_ROWS) {
        document.add(createRearTable());
    } else if (characterPlayer.getCybernetics().isEmpty()) {
        document.add(createRearTablePsiExtended());
    } else {
        document.add(createRearTable());
    }
    document.add(FightingManeuvers.getFightingManoeuvresTable(characterPlayer));
    document.add(WeaponsAndArmours.getWeaponsAndArmoursTable(characterPlayer));
}

From source file:com.softwaremagico.tm.pdf.small.SmallCharacterSheet.java

License:Open Source License

@Override
protected void createCharacterPDF(Document document, CharacterPlayer characterPlayer) throws Exception {
    document.add(createCharacterContent(characterPlayer));
}

From source file:com.softwaremagico.tm.pdf.small.SmallPartySheet.java

License:Open Source License

@Override
protected void createContent(Document document) throws Exception {
    initializeTableContent();/*from w ww . j a  v  a2  s  .  c om*/
    for (CharacterPlayer characterPlayer : party.getMembers()) {
        createCharacterPDF(document, characterPlayer);
    }
    if (party.getMembers().size() % 2 > 0) {
        mainTable.addCell(new PdfPCell());
    }
    document.add(mainTable);
}

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

private void createTable(Document doc, EnableRequerimentTypeFederalEnum type,
         EnableRequerimentSubjectFederalEnum subject, LicensePFEntity license, UserEntity user)
         throws DocumentException {

     // create PDF table with the given widths
     PdfPTable table = new PdfPTable(4);
     // set table width a percentage of the page width
     table.setWidthPercentage(100f);//  w w w .ja v a 2  s.  c  o  m

     // Alterao Cadastral
     this.createAlteracaoCadastral(table, type, subject);

     // Dados da Empresa
     this.createCompany(table, license);

     // Dados do Representante
     this.createRepresentant(table, user);

     // Deferimento
     this.createDeferiment(table, license.getCompany());

     // Uso Oficial
     this.insertCellProtocol(table, license);

     // Table pai
     PdfPTable tableFather = new PdfPTable(1);
     tableFather.setWidthPercentage(100f);
     PdfPCell cellFather = new PdfPCell(table);
     cellFather.setBorderWidth(2);
     tableFather.addCell(cellFather);

     doc.add(this.createHeader());
     doc.add(tableFather);
 }

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

License:Open Source License

private void createParagraph(Document doc, LicensePCEntity license, String type,
        List<LicensePCProductEntity> listProducts) throws DocumentException {

    StringBuilder sbParagraph = new StringBuilder().append("A sociedade empresria ")
            .append(license.getCompany().getName()).append(", estabelecida em ")
            .append(license.getCompany().getStreet()).append(", com ramo de ")
            .append(license.getCompany().getCodCnae()).append(", telefone ")
            .append(license.getCompany().getPhoneNumber()).append(", fax ")
            .append(license.getCompany().getFaxNumber()).append(", e-mail: ")
            .append(license.getCompany().getUserResponsable().getEmail()).append(" e CEP ")
            .append(license.getCompany().getCep()).append(", com CNPJ N")
            .append(license.getCompany().getCnpjFormatted()).append("e inscrio Estadual N")
            .append(license.getCompany().getNumInscription()).append(", atravs de seu ")
            .append(license.getCompany().getUserResponsable().getOffice()).append(", Sr. ")
            .append(license.getCompany().getUserResponsable().getName())
            .append(", vem respeitosamente requerer de V. Ex. a ALTERAO de seu:")
            .append(WINDOWS_LINE_SEPARATOR)
            .append("Certificado de Vistoria para Produtos Controlados, fixando-se sua capacidade nos seguintes limites mximos ")
            .append("de estoque: (Conforme relao em Anexo)").append(WINDOWS_LINE_SEPARATOR)
            .append("De acordo com o Decreto No 6.911 de 10 de Janeiro de 1935.");

    StringBuilder sbTerms = new StringBuilder().append("Nestes termos").append(WINDOWS_LINE_SEPARATOR)
            .append(" Pede deferimento.");

    StringBuilder sbDate = new StringBuilder().append(license.getCompany().getCity()).append("/")
            .append(license.getCompany().getState()).append(", ")
            .append(DateUtils.format(Calendar.getInstance()));

    StringBuilder sbSignature = new StringBuilder().append("____________________________________________")
            .append(WINDOWS_LINE_SEPARATOR).append("Nome: ")
            .append(license.getCompany().getUserResponsable().getName()).append(WINDOWS_LINE_SEPARATOR)
            .append("Cargo: ").append(license.getCompany().getUserResponsable().getOffice())
            .append(WINDOWS_LINE_SEPARATOR).append("RG: ")
            .append(license.getCompany().getUserResponsable().getRg()).append(WINDOWS_LINE_SEPARATOR)
            .append("CPF: ").append(license.getCompany().getUserResponsable().getCpf());

    // Header/*from  w  ww. j  a v a 2 s.c  o  m*/
    Paragraph paragraphHeader = new Paragraph("DEPARTAMENTO DE IDENTIFICAO E REGISTROS DIVERSOS  DIRD "
            + "DIVISO DE PRODUTOS CONTROLADOS  DPC");
    paragraphHeader.setFont(FONT_HEADER);
    paragraphHeader.setAlignment(Element.ALIGN_CENTER);

    // Texto da Empresa
    Paragraph paragraphCompany = new Paragraph(sbParagraph.toString());
    paragraphCompany.setFont(FONT_PARAGRAPH);

    Paragraph paragraphTerms = new Paragraph(sbTerms.toString());
    paragraphTerms.setFont(FONT_PARAGRAPH);
    paragraphTerms.setAlignment(Element.ALIGN_CENTER);

    Paragraph paragraphDate = new Paragraph(sbDate.toString());
    paragraphDate.setFont(FONT_PARAGRAPH);

    Paragraph paragraphSignature = new Paragraph(sbSignature.toString());
    paragraphSignature.setFont(FONT_PARAGRAPH);
    paragraphSignature.setAlignment(Element.ALIGN_CENTER);

    doc.add(paragraphHeader);
    doc.add(Chunk.NEWLINE);
    doc.add(Chunk.NEWLINE);
    doc.add(paragraphCompany);
    doc.add(Chunk.NEWLINE);
    doc.add(paragraphTerms);
    doc.add(Chunk.NEWLINE);
    doc.add(paragraphDate);
    doc.add(Chunk.NEWLINE);
    doc.add(paragraphSignature);
    doc.add(Chunk.NEWLINE);

    this.generateProducts(doc, listProducts);

}