Search in sources :

Example 26 with Paragraph

use of com.itextpdf.text.Paragraph in project trainning by fernandotomasio.

the class DOC002PDF method buildCover.

private void buildCover(Document document, CurriculoMinimoDTO curriculoMinimo) throws DocumentException {
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    Paragraph p1 = new Paragraph();
    p1.setAlignment(Element.ALIGN_CENTER);
    p1.add(new Phrase("MINISTÉRIO DA DEFESA", fontManager.getH1Font()));
    document.add(p1);
    Paragraph p2 = new Paragraph();
    p2.setAlignment(Element.ALIGN_CENTER);
    p2.add(new Phrase("COMANDO DA AERONÁUTICA", fontManager.getH1Font()));
    document.add(p2);
    Paragraph p3 = new Paragraph();
    p3.setAlignment(Element.ALIGN_CENTER);
    p3.add(new Phrase("DEPARTAMENTO DE CONTROLE DO ESPAÇO AÉREO", fontManager.getDefaultFont()));
    // document.add(p3);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    try {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        String path = classLoader.getResource("aer.png").getPath();
        Image image = Image.getInstance(path);
        image.setAlignment(Element.ALIGN_CENTER);
        image.scalePercent(18);
        document.add(image);
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(DOC001PDF.class.getName()).log(Level.SEVERE, null, ex);
    }
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    Paragraph p4 = new Paragraph();
    p4.setAlignment(Element.ALIGN_CENTER);
    p4.add(new Phrase("ENSINO", fontManager.getH1Font()));
    document.add(p4);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    PdfPTable t = new PdfPTable(1);
    PdfPCell unica = new PdfPCell();
    unica.setPadding(10);
    // Paragraph p5 = new Paragraph();
    // p5.setAlignment(Element.ALIGN_CENTER);
    // p5.add(new Phrase("ICA 56-3", fontManager.getDefaultFont()));
    // p5.add(Chunk.NEWLINE);
    Paragraph p6 = new Paragraph();
    p6.setAlignment(Element.ALIGN_CENTER);
    p6.add(new Phrase("PLANO DE UNIDADES DIDÁTICAS DO CURSO " + curriculoMinimo.getCurso().getDescricao(), fontManager.getDefaultFont()));
    Paragraph p7 = new Paragraph();
    p7.setAlignment(Element.ALIGN_CENTER);
    p7.add(new Phrase(curriculoMinimo.getCurso().getCodigo(), fontManager.getDefaultFont()));
    Paragraph p8 = new Paragraph();
    p8.setAlignment(Element.ALIGN_CENTER);
    p8.add(new Phrase(curriculoMinimo.getAnoPublicacaoPUD(), fontManager.getDefaultFont()));
    // unica.addElement(p5);
    unica.addElement(Chunk.NEWLINE);
    unica.addElement(p6);
    unica.addElement(p7);
    unica.addElement(Chunk.NEWLINE);
    unica.addElement(p8);
    unica.addElement(Chunk.NEWLINE);
    t.addCell(unica);
    document.add(t);
    // document.add(Chunk.NEXTPAGE);
    // 
    // document.add(buildPrefacio(curriculoMinimo));
    document.add(Chunk.NEXTPAGE);
    document.add(Chunk.NEXTPAGE);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) PdfPTable(com.itextpdf.text.pdf.PdfPTable) BadElementException(com.itextpdf.text.BadElementException) Phrase(com.itextpdf.text.Phrase) IOException(java.io.IOException) Image(com.itextpdf.text.Image) Paragraph(com.itextpdf.text.Paragraph)

Example 27 with Paragraph

use of com.itextpdf.text.Paragraph in project trainning by fernandotomasio.

the class DOC002PDF method makeReport.

@Override
public void makeReport() {
    teachingDocumentsService = (TeachingDocumentsService) services.get("teachingDocumentsService");
    document = documentManager.getDocumentPortrait();
    os = documentManager.prepareDocument(document);
    writer = documentManager.getWritter();
    ChapterSectionTOC eventHandler = new ChapterSectionTOC();
    writer.setPageEvent(eventHandler);
    document.open();
    try {
        String curriculoMinimoIdParam = (String) params.get("curriculoMinimoId");
        Long curriculoMinimoId = Long.parseLong(curriculoMinimoIdParam);
        CurriculoMinimoDTO curriculoMinimo = teachingDocumentsService.findCurriculoMinimo(curriculoMinimoId);
        buildCover(document, curriculoMinimo);
        buildFrontispicio(document, curriculoMinimo);
        document.add(buildPrefacio(curriculoMinimo));
        document.add(Chunk.NEXTPAGE);
        document.add(buildAbreviaturas(curriculoMinimo));
        document.add(Chunk.NEXTPAGE);
        document.add(buildDisposicoesPreliminares(curriculoMinimo));
        document.add(Chunk.NEXTPAGE);
        document.add(buildAtividadesComplementares(curriculoMinimo));
        document.add(Chunk.NEXTPAGE);
        document.add(buildComplementacaoInstrucao(curriculoMinimo));
        document.add(Chunk.NEXTPAGE);
        // PdfPTable tableAtividadesAvaliativas = buildAtividadesAvaliativasTable(curriculoMinimo);
        // document.add(tableAtividadesAvaliativas);
        Paragraph p12 = new Paragraph();
        p12.add(new Phrase("4 DETALHAMENTO DAS UNIDADES DIDÁTICAS", fontManager.getBoldFont()));
        document.add(p12);
        document.add(Chunk.NEWLINE);
        DisciplinaDTO[] disciplinas = teachingDocumentsService.findAllDisciplinasByCurriculoMinimo(curriculoMinimo.getId());
        for (DisciplinaDTO disciplina : disciplinas) {
            PdfPTable tableDisciplina = buildTableDisciplina(disciplina);
            document.add(tableDisciplina);
            document.add(Chunk.NEWLINE);
            UnidadeDidaticaDTO[] unidades = teachingDocumentsService.findAllUnidadesDidaticas(disciplina.getId());
            PdfPTable unidadesHeaderTable = new PdfPTable(1);
            unidadesHeaderTable.setWidthPercentage(100);
            PdfPCell p20 = new PdfPCell(new Phrase("UNIDADES DIDÁTICAS", fontManager.getBoldFont()));
            unidadesHeaderTable.addCell(p20);
            unidadesHeaderTable.setHorizontalAlignment(Element.ALIGN_CENTER);
            document.add(unidadesHeaderTable);
            document.add(Chunk.NEWLINE);
            for (UnidadeDidaticaDTO unidade : unidades) {
                PdfPTable tableUnidade = buildTableUnidade(unidade);
                document.add(tableUnidade);
                document.add(Chunk.NEWLINE);
            }
            PdfPTable tableRecomendacoes = buildTableRecomendacoesMetodologicas(disciplina);
            document.add(tableRecomendacoes);
            document.add(Chunk.NEWLINE);
            PdfPTable perfisTable = buildTablePerfisRelacionamento(disciplina);
            document.add(perfisTable);
            document.add(Chunk.NEWLINE);
            PdfPTable referenciasTable = buildTableReferencias(disciplina);
            document.add(referenciasTable);
            document.add(Chunk.NEXTPAGE);
        }
        document.add(Chunk.NEXTPAGE);
        document.add(buildDisposicoesFinais(curriculoMinimo));
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
        document.add(buildAssinatura());
        document.add(Chunk.NEXTPAGE);
        document.add(buildSumario(eventHandler.titles));
    } catch (DocumentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
        throw new CoreException(e.getMessage());
    } finally {
        document.close();
    }
    try {
        PdfReader reader = new PdfReader(os.toByteArray());
        int n = reader.getNumberOfPages();
        String pagesInterval = String.format("1-4,%d, 5-%d", n, n - 1);
        reader.selectPages(pagesInterval);
        os = new ByteArrayOutputStream();
        PdfStamper stamper = new PdfStamper(reader, os);
        stamper.close();
        reader.close();
    } catch (IOException ex) {
        Logger.getLogger(DOC002PDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(DOC002PDF.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        PdfReader reader = new PdfReader(os.toByteArray());
        os = new ByteArrayOutputStream();
        PdfStamper stamper = new PdfStamper(reader, os);
        int total = reader.getNumberOfPages();
        PdfContentByte over = null;
        int total_pages = total - 1;
        for (int i = 1; i < total; i++) {
            int actual_page = i - 1;
            if (i > 5) {
                over = stamper.getOverContent(i);
                System.out.println(over);
                over.beginText();
                BaseFont baseFont = BaseFont.createFont(BaseFont.TIMES_ROMAN, "UTF-8", false);
                over.setFontAndSize(baseFont, 12);
                if ((i % 2) == 0) {
                    over.showTextAligned(PdfContentByte.ALIGN_RIGHT, actual_page + "/" + total_pages, 538, 803, 0);
                } else {
                    over.showTextAligned(PdfContentByte.ALIGN_LEFT, actual_page + "/" + total_pages, 58, 803, 0);
                }
                over.endText();
            }
        }
        // PdfContentByte content = stamper.getOverContent(1);
        // ColumnText ct = new ColumnText( content );
        // ct.setSimpleColumn(50,50,50,50);
        // ct.setText(new Phrase("TESTANDO"));
        // ct.go();
        stamper.close();
        reader.close();
    } catch (IOException ex) {
    // Logger.getLogger(DOC001PDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(DOC001PDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) Phrase(com.itextpdf.text.Phrase) PdfReader(com.itextpdf.text.pdf.PdfReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UnidadeDidaticaDTO(com.tomasio.projects.trainning.dto.UnidadeDidaticaDTO) ObjetivoUnidadeDidaticaDTO(com.tomasio.projects.trainning.dto.ObjetivoUnidadeDidaticaDTO) Paragraph(com.itextpdf.text.Paragraph) PdfPTable(com.itextpdf.text.pdf.PdfPTable) CoreException(com.tomasio.projects.trainning.exeption.CoreException) PdfStamper(com.itextpdf.text.pdf.PdfStamper) DocumentException(com.itextpdf.text.DocumentException) DisciplinaDTO(com.tomasio.projects.trainning.dto.DisciplinaDTO) ObjetivoDisciplinaDTO(com.tomasio.projects.trainning.dto.ObjetivoDisciplinaDTO) BaseFont(com.itextpdf.text.pdf.BaseFont) CurriculoMinimoDTO(com.tomasio.projects.trainning.dto.CurriculoMinimoDTO) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte)

Example 28 with Paragraph

use of com.itextpdf.text.Paragraph in project trainning by fernandotomasio.

the class DOC004PDF method makeReport.

@Override
public void makeReport() {
    teachingDocumentsService = (TeachingDocumentsService) services.get("teachingDocumentsService");
    document = documentManager.getDocumentPortrait();
    os = documentManager.prepareDocument(document);
    writer = documentManager.getWritter();
    document.open();
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
    htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
    CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
    Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));
    XMLWorker worker = new XMLWorker(pipeline, true);
    XMLParser p = new XMLParser(worker);
    try {
        String capituloIdParam = (String) params.get("capituloId");
        Long capituloId = Long.parseLong(capituloIdParam);
        CapituloApostilaDTO capitulo = teachingDocumentsService.findCapituloApostila(capituloId);
        // Paragraph prefacioParagraph = new Paragraph(new Phrase("APOSTILA" + apostila.getDisciplina().getDescricao(), fontManager.getBoldFont()));
        // prefacioParagraph.setAlignment(Element.ALIGN_CENTER);
        // document.add(prefacioParagraph);
        SecaoApostilaDTO[] secoes = teachingDocumentsService.findAllSecoesApostila(capitulo.getId());
        for (SecaoApostilaDTO secao : secoes) {
            if (secao.getContent() != null) {
                Paragraph secaoParagraph = new Paragraph(secao.getContent());
                p.parse(new StringReader(secao.getContent()));
                document.add(Chunk.NEXTPAGE);
            }
        }
    } catch (DocumentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
        throw new CoreException(e.getMessage());
    } catch (IOException ex) {
        Logger.getLogger(DOC004PDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
}
Also used : HtmlPipeline(com.itextpdf.tool.xml.pipeline.html.HtmlPipeline) IOException(java.io.IOException) CssResolverPipeline(com.itextpdf.tool.xml.pipeline.css.CssResolverPipeline) Paragraph(com.itextpdf.text.Paragraph) SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) XMLWorker(com.itextpdf.tool.xml.XMLWorker) CoreException(com.tomasio.projects.trainning.exeption.CoreException) CSSResolver(com.itextpdf.tool.xml.pipeline.css.CSSResolver) PdfWriterPipeline(com.itextpdf.tool.xml.pipeline.end.PdfWriterPipeline) DocumentException(com.itextpdf.text.DocumentException) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) StringReader(java.io.StringReader) HtmlPipelineContext(com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext) XMLParser(com.itextpdf.tool.xml.parser.XMLParser)

Example 29 with Paragraph

use of com.itextpdf.text.Paragraph in project trainning by fernandotomasio.

the class TCATrainningDocument method createAnexo1.

private void createAnexo1(Map<Long, CursoDTO> cursosMap) {
    // ReportUtil.getCursos(cursosMap);
    List<CursoDTO> cursos = null;
    try {
        PdfPTable t = new PdfPTable(2);
        t.setWidthPercentage(100);
        t.setWidths(new int[] { 35, 200 });
        for (CursoDTO curso : cursos) {
            if (curso == null) {
                continue;
            }
            PdfPCell cell = tableManager.getPhraseCellLeft(curso.getCodigo());
            cell.setPadding(5);
            cell.setBorder(Rectangle.NO_BORDER);
            t.addCell(cell);
            PdfPCell cell2 = tableManager.getPhraseCellLeft(curso.getDescricao());
            cell2.setPadding(5);
            cell2.setBorder(Rectangle.NO_BORDER);
            t.addCell(cell2);
            Paragraph p = null;
            p = new Paragraph(ReportUtil.convertEncode(curso.getCodigo()) + " - " + ReportUtil.convertEncode(curso.getDescricao()), fontManager.getDefaultFont());
            p.setAlignment(Element.ALIGN_LEFT);
        // document.add(p);
        }
        document.add(t);
        document.newPage();
    } catch (DocumentException ex) {
        Logger.getLogger(TCATrainningDocument.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) PdfPTable(com.itextpdf.text.pdf.PdfPTable) DocumentException(com.itextpdf.text.DocumentException) CursoDTO(com.tomasio.projects.trainning.dto.CursoDTO) Paragraph(com.itextpdf.text.Paragraph)

Example 30 with Paragraph

use of com.itextpdf.text.Paragraph in project digilib by robcast.

the class PDFTitlePage method getPageContents.

/**
 * generate iText-PDF-Contents for the title page
 *
 * @return
 * @throws ImageOpException
 * @throws IOException
 */
public Element getPageContents() throws IOException, ImageOpException {
    Paragraph content = new Paragraph();
    content.setAlignment(Element.ALIGN_CENTER);
    // add vertical whitespace
    for (int i = 0; i < 8; i++) {
        content.add(Chunk.NEWLINE);
    }
    // add logo
    content.add(getLogo());
    content.add(Chunk.NEWLINE);
    content.add(Chunk.NEWLINE);
    // add title
    Anchor title = new Anchor(new Paragraph(getTitle(), FontFactory.getFont(FontFactory.HELVETICA, 16)));
    String burl = job_info.getImageJobInformation().getAsString("base.url");
    title.setReference(burl + "digilib.html?fn=" + job_info.getImageJobInformation().getAsString("fn"));
    content.add(title);
    content.add(Chunk.NEWLINE);
    // add author
    if (getDate() != " ")
        content.add(new Paragraph(getAuthor() + " (" + getDate() + ")", FontFactory.getFont(FontFactory.HELVETICA, 14)));
    else
        content.add(new Paragraph(getAuthor(), FontFactory.getFont(FontFactory.HELVETICA, 14)));
    content.add(Chunk.NEWLINE);
    // add page numbers
    content.add(new Paragraph(getPages(), FontFactory.getFont(FontFactory.HELVETICA, 12)));
    content.add(Chunk.NEWLINE);
    content.add(Chunk.NEWLINE);
    content.add(Chunk.NEWLINE);
    // add digilib version
    content.add(new Paragraph(getDigilibVersion(), FontFactory.getFont(FontFactory.HELVETICA, 10)));
    for (int i = 0; i < 8; i++) {
        content.add(Chunk.NEWLINE);
    }
    Anchor address = new Anchor(new Paragraph(burl + "digilib.html?fn=" + job_info.getImageJobInformation().getAsString("fn"), FontFactory.getFont(FontFactory.COURIER, 9)));
    address.setReference(burl + "digilib.html?fn=" + job_info.getImageJobInformation().getAsString("fn"));
    content.add(address);
    return content;
}
Also used : Anchor(com.itextpdf.text.Anchor) Paragraph(com.itextpdf.text.Paragraph)

Aggregations

Paragraph (com.itextpdf.text.Paragraph)67 Chapter (com.itextpdf.text.Chapter)25 PdfPTable (com.itextpdf.text.pdf.PdfPTable)18 Phrase (com.itextpdf.text.Phrase)14 PdfPCell (com.itextpdf.text.pdf.PdfPCell)13 Font (com.itextpdf.text.Font)11 IOException (java.io.IOException)11 DocumentException (com.itextpdf.text.DocumentException)10 Section (com.itextpdf.text.Section)10 Document (com.itextpdf.text.Document)8 ArrayList (java.util.ArrayList)8 ListItem (com.itextpdf.text.ListItem)7 BaseFont (com.itextpdf.text.pdf.BaseFont)7 FileOutputStream (java.io.FileOutputStream)7 List (com.itextpdf.text.List)6 Chunk (com.itextpdf.text.Chunk)5 Image (com.itextpdf.text.Image)5 PdfWriter (com.itextpdf.text.pdf.PdfWriter)5 ObjetivoDisciplinaDTO (com.tomasio.projects.trainning.dto.ObjetivoDisciplinaDTO)5 SubunidadeDidaticaDTO (com.tomasio.projects.trainning.dto.SubunidadeDidaticaDTO)5