Search in sources :

Example 16 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable in project trainning by fernandotomasio.

the class DOC002PDF method buildAtividadesAdministrativasTable.

private PdfPTable buildAtividadesAdministrativasTable(CurriculoMinimoDTO curriculo) throws DocumentException {
    PdfPTable table = new PdfPTable(3);
    table.setWidths(new int[] { 4, 1, 1 });
    table.setWidthPercentage(100);
    PdfPCell cellHeader;
    cellHeader = new PdfPCell(new Phrase("ATIVIDADES ADMINISTRATIVAS", fontManager.getBoldFont()));
    cellHeader.setPadding(10);
    cellHeader.setColspan(3);
    table.addCell(cellHeader);
    AtividadeAdministrativaDTO[] atividades = teachingDocumentsService.findAllAtividadesAdministrativasByPUD(curriculo.getId());
    for (AtividadeAdministrativaDTO atividade : atividades) {
        PdfPCell cellAdministracao;
        cellAdministracao = new PdfPCell(new Phrase(atividade.getDescricao(), fontManager.getDefaultFont()));
        cellAdministracao.setPadding(10);
        table.addCell(cellAdministracao);
        PdfPCell cellCHAtividade;
        cellCHAtividade = new PdfPCell(new Phrase(String.valueOf(atividade.getQuantidadeTemposAula()), fontManager.getDefaultFont()));
        cellCHAtividade.setPadding(10);
        table.addCell(cellCHAtividade);
        PdfPCell cellTecnica;
        cellTecnica = new PdfPCell(new Phrase("CH", fontManager.getDefaultFont()));
        cellTecnica.setPadding(10);
        table.addCell(cellTecnica);
    }
    return table;
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) AtividadeAdministrativaDTO(com.tomasio.projects.trainning.dto.AtividadeAdministrativaDTO) PdfPTable(com.itextpdf.text.pdf.PdfPTable) Phrase(com.itextpdf.text.Phrase)

Example 17 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable 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 18 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable in project trainning by fernandotomasio.

the class DOC002PDF method buildComplamentacaoInstrucaoTable.

private PdfPTable buildComplamentacaoInstrucaoTable(CurriculoMinimoDTO curriculo) throws DocumentException {
    PdfPTable table = new PdfPTable(3);
    table.setWidths(new int[] { 4, 1, 1 });
    table.setWidthPercentage(100);
    PdfPCell cellHeader;
    cellHeader = new PdfPCell(new Phrase("COMPLEMENTAÇÃO DA INSTRUÇÃO", fontManager.getBoldFont()));
    cellHeader.setPadding(10);
    cellHeader.setColspan(3);
    table.addCell(cellHeader);
    ComplementacaoInstrucaoDTO[] complementacoes = teachingDocumentsService.findAllComplementacoesInstrucaoByPUD(curriculo.getId());
    for (ComplementacaoInstrucaoDTO complementacao : complementacoes) {
        PdfPCell cellAdministracao;
        cellAdministracao = new PdfPCell(new Phrase(complementacao.getDescricao(), fontManager.getDefaultFont()));
        cellAdministracao.setPadding(10);
        table.addCell(cellAdministracao);
        PdfPCell cellCHAtividade;
        cellCHAtividade = new PdfPCell(new Phrase(String.valueOf(complementacao.getQuantidadeTemposAula()), fontManager.getDefaultFont()));
        cellCHAtividade.setPadding(10);
        table.addCell(cellCHAtividade);
        PdfPCell cellTecnica;
        cellTecnica = new PdfPCell(new Phrase("AE", fontManager.getDefaultFont()));
        cellTecnica.setPadding(10);
        table.addCell(cellTecnica);
    }
    return table;
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) PdfPTable(com.itextpdf.text.pdf.PdfPTable) ComplementacaoInstrucaoDTO(com.tomasio.projects.trainning.dto.ComplementacaoInstrucaoDTO) Phrase(com.itextpdf.text.Phrase)

Example 19 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable 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 20 with PdfPTable

use of com.itextpdf.text.pdf.PdfPTable in project trainning by fernandotomasio.

the class TCATrainningDocument method createPrincipal.

private void createPrincipal(String file) {
    try {
        PdfReader reader = new PdfReader(file);
        PdfPTable t1 = new PdfPTable(2);
        int n = reader.getNumberOfPages();
        PdfImportedPage page;
        for (int i = 1; i <= n; i++) {
            page = writer.getImportedPage(reader, i);
            // Image imagePage = Image.getInstance(page);
            // imagePage.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
            PdfContentByte cb = writer.getDirectContent();
            cb.addTemplate(page, 0, 0);
            document.newPage();
        // document.add(imagePage);
        }
    } catch (IOException ex) {
        Logger.getLogger(TCATrainningDocument.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : PdfImportedPage(com.itextpdf.text.pdf.PdfImportedPage) PdfPTable(com.itextpdf.text.pdf.PdfPTable) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) PdfReader(com.itextpdf.text.pdf.PdfReader) IOException(java.io.IOException)

Aggregations

PdfPTable (com.itextpdf.text.pdf.PdfPTable)44 PdfPCell (com.itextpdf.text.pdf.PdfPCell)24 Paragraph (com.itextpdf.text.Paragraph)18 Phrase (com.itextpdf.text.Phrase)17 DocumentException (com.itextpdf.text.DocumentException)12 Font (com.itextpdf.text.Font)8 IOException (java.io.IOException)8 ExceptionConverter (com.itextpdf.text.ExceptionConverter)6 Document (com.itextpdf.text.Document)5 BadElementException (com.itextpdf.text.BadElementException)4 BaseFont (com.itextpdf.text.pdf.BaseFont)4 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)4 PdfWriter (com.itextpdf.text.pdf.PdfWriter)4 FileOutputStream (java.io.FileOutputStream)4 BaseColor (com.itextpdf.text.BaseColor)3 Chapter (com.itextpdf.text.Chapter)3 Chunk (com.itextpdf.text.Chunk)3 Image (com.itextpdf.text.Image)3 ListItem (com.itextpdf.text.ListItem)3 PdfReader (com.itextpdf.text.pdf.PdfReader)3