Search in sources :

Example 31 with Phrase

use of com.itextpdf.text.Phrase in project summer-bean by cn-cerc.

the class ReportHeaderFooter method onEndPage.

public void onEndPage(PdfWriter writer, Document document) {
    Font f8 = null;
    try {
        if (bf == null)
            bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false);
        if (fontDetail == null)
            // 数据体字体
            fontDetail = new Font(bf, presentFontSize, Font.NORMAL);
        if (f8 == null)
            f8 = new Font(bf, 8);
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // 1.写入页眉
    Phrase phrase = new Phrase(header, f8);
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, phrase, document.right(), document.top() + 20, 0);
    // 2.写入前半部分的 第 X页/共
    int pageS = writer.getPageNumber();
    String foot1 = "第 " + pageS + " 页 /共";
    Phrase footer = new Phrase(foot1, fontDetail);
    // 3.计算前半部分的foot1的长度,后面好定位最后一部分的'Y页'这俩字的x轴坐标,字体长度也要计算进去 = len
    float len = bf.getWidthPoint(foot1, presentFontSize);
    // 4.拿到当前的PdfContentByte
    PdfContentByte cb = writer.getDirectContent();
    // 5.写入页脚1,x轴就是(右margin+左margin + right() -left()- len)/2.0F
    // 再给偏移20F适合人类视觉感受,否则肉眼看上去就太偏左了
    // ,y轴就是底边界-20,否则就贴边重叠到数据体里了就不是页脚了;注意Y轴是从下往上累加的,最上方的Top值是大于Bottom好几百开外的。
    ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer, (document.rightMargin() + document.right() + document.leftMargin() - document.left() - len) / 2.0F + 20F, document.bottom() - 20, 0);
    // 6.写入页脚2的模板(就是页脚的Y页这俩字)添加到文档中,计算模板的和Y轴,X=(右边界-左边界 - 前半部分的len值)/2.0F +
    // len , y 轴和之前的保持一致,底边界-20
    cb.addTemplate(total, (document.rightMargin() + document.right() + document.leftMargin() - document.left()) / 2.0F + 20F, // 调节模版显示的位置
    document.bottom() - 20);
}
Also used : DocumentException(com.itextpdf.text.DocumentException) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) IOException(java.io.IOException) Phrase(com.itextpdf.text.Phrase) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont)

Example 32 with Phrase

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

the class DOC001PDF method buildFrontispicio.

private void buildFrontispicio(Document document, CurriculoMinimoDTO curriculoMinimo) throws DocumentException {
    Paragraph spaceParagraph = new Paragraph();
    spaceParagraph.add(new Phrase("\n"));
    document.add(spaceParagraph);
    document.add(spaceParagraph);
    document.add(spaceParagraph);
    document.add(spaceParagraph);
    document.add(spaceParagraph);
    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);
    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.5f);
        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);
    Paragraph p4 = new Paragraph();
    p4.setAlignment(Element.ALIGN_CENTER);
    p4.add(new Phrase("ENSINO", fontManager.getH0Font()));
    document.add(p4);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
    PdfPTable t = new PdfPTable(1);
    t.setTotalWidth(286);
    t.setLockedWidth(true);
    PdfPCell unica = new PdfPCell();
    unica.setFixedHeight(140);
    unica.setPadding(10);
    unica.setVerticalAlignment(Element.ALIGN_MIDDLE);
    Paragraph p5 = new Paragraph();
    p5.setAlignment(Element.ALIGN_CENTER);
    p5.add(new Phrase(curriculoMinimo.getNumeroPublicacaoCM(), fontManager.getSmallXBoldFont()));
    Paragraph p6 = new Paragraph();
    p6.setAlignment(Element.ALIGN_CENTER);
    p6.add(new Phrase("CURRÍCULO MÍNIMO DO CURSO " + curriculoMinimo.getCurso().getDescricao(), fontManager.getSmallXBoldFont()));
    Paragraph p7 = new Paragraph();
    p7.setAlignment(Element.ALIGN_CENTER);
    p7.add(new Phrase(curriculoMinimo.getCurso().getCodigo(), fontManager.getSmallXBoldFont()));
    Paragraph p8 = new Paragraph();
    p8.setAlignment(Element.ALIGN_CENTER);
    p8.add(new Phrase(curriculoMinimo.getAnoPublicacaoCM(), fontManager.getSmallXBoldFont()));
    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);
}
Also used : 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 33 with Phrase

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

the class DOC002PDF method buildTableDisciplina.

private PdfPTable buildTableDisciplina(DisciplinaDTO disciplina) throws DocumentException {
    PdfPTable table = new PdfPTable(6);
    table.setWidthPercentage(100);
    // table.setWidths(new int[]{2, 1, 1});
    PdfPCell cellCampo;
    Phrase phraseCampo = new Phrase();
    phraseCampo.add(new Chunk("CAMPO: ", fontManager.getBoldFont()));
    phraseCampo.add(new Chunk("TÉCNICO-ESPECIALIZADO", fontManager.getDefaultFont()));
    cellCampo = new PdfPCell(phraseCampo);
    cellCampo.setColspan(3);
    cellCampo.setPadding(10);
    table.addCell(cellCampo);
    PdfPCell cellArea;
    Phrase phraseArea = new Phrase();
    phraseArea.add(new Chunk("ÁREA: ", fontManager.getBoldFont()));
    phraseArea.add(new Chunk("SISTEMAS AEROESPACIAIS", fontManager.getDefaultFont()));
    cellArea = new PdfPCell(phraseArea);
    cellArea.setColspan(3);
    cellArea.setPadding(10);
    table.addCell(cellArea);
    PdfPCell cellDescricao;
    Phrase phraseDescricao = new Phrase();
    phraseDescricao.add(new Chunk("DISCIPLINA " + disciplina.getNumeroDisciplina() + ": ", fontManager.getBoldFont()));
    phraseDescricao.add(new Chunk(disciplina.getDescricao().toUpperCase(), fontManager.getDefaultFont()));
    cellDescricao = new PdfPCell(phraseDescricao);
    cellDescricao.setColspan(6);
    cellDescricao.setPadding(10);
    table.addCell(cellDescricao);
    PdfPCell cellCHInstrucao;
    Phrase phraseCHInstrucao = new Phrase();
    phraseCHInstrucao.add(new Chunk("CH INSTRUÇÃO: ", fontManager.getBoldFont()));
    phraseCHInstrucao.add(new Chunk(disciplina.getQuantidadeTemposAula() + " tempo(s)", fontManager.getDefaultFont()));
    cellCHInstrucao = new PdfPCell(phraseCHInstrucao);
    cellCHInstrucao.setColspan(2);
    cellCHInstrucao.setPadding(10);
    table.addCell(cellCHInstrucao);
    PdfPCell cellCHAvaliacao;
    Phrase phraseCHAvaliacao = new Phrase();
    phraseCHAvaliacao.add(new Chunk("CH AVALIAÇÃO: ", fontManager.getBoldFont()));
    phraseCHAvaliacao.add(new Chunk(disciplina.getQuantidadeTemposAvaliacao() + " tempo(s)", fontManager.getDefaultFont()));
    cellCHAvaliacao = new PdfPCell(phraseCHAvaliacao);
    cellCHAvaliacao.setColspan(2);
    cellCHAvaliacao.setPadding(10);
    table.addCell(cellCHAvaliacao);
    PdfPCell cellCHTotal;
    Phrase phraseCHTotal = new Phrase();
    int quantidadeTempoTotal = disciplina.getQuantidadeTemposAula() + disciplina.getQuantidadeTemposAvaliacao();
    phraseCHTotal.add(new Chunk("CH TOTAL: ", fontManager.getBoldFont()));
    phraseCHTotal.add(new Chunk(quantidadeTempoTotal + " tempo(s)", fontManager.getDefaultFont()));
    cellCHTotal = new PdfPCell(phraseCHTotal);
    cellCHTotal.setColspan(2);
    cellCHTotal.setPadding(10);
    table.addCell(cellCHTotal);
    PdfPCell cellObjetivos;
    Paragraph objetivosHead = new Paragraph("OBJETIVOS ESPECÍFICOS: ", fontManager.getBoldFont());
    ObjetivoDisciplinaDTO[] objetivosDisciplina = teachingDocumentsService.findAllObjetivosDisciplinas(disciplina.getId());
    // Paragraph objetivos = new Paragraph("asdfasdfasdfasdf", fontManager.getDefaultFont());
    cellObjetivos = new PdfPCell();
    cellObjetivos.addElement(objetivosHead);
    List objetivosList = new List(List.ORDERED, List.ALPHABETICAL);
    objetivosList.setLowercase(true);
    for (ObjetivoDisciplinaDTO objetivoDisciplina : objetivosDisciplina) {
        ListItem item = new ListItem(objetivoDisciplina.getDescricao() + " (" + objetivoDisciplina.getNivelAprendizagem().getCodigo() + ")", fontManager.getDefaultFont());
        objetivosList.add(item);
    }
    cellObjetivos.addElement(objetivosList);
    cellObjetivos.setColspan(6);
    cellObjetivos.setPadding(10);
    table.addCell(cellObjetivos);
    return table;
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) PdfPTable(com.itextpdf.text.pdf.PdfPTable) List(com.itextpdf.text.List) ArrayList(java.util.ArrayList) Phrase(com.itextpdf.text.Phrase) ListItem(com.itextpdf.text.ListItem) Chunk(com.itextpdf.text.Chunk) Paragraph(com.itextpdf.text.Paragraph) ObjetivoDisciplinaDTO(com.tomasio.projects.trainning.dto.ObjetivoDisciplinaDTO)

Example 34 with Phrase

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

the class DOC002PDF method buildTablePerfisRelacionamento.

private PdfPTable buildTablePerfisRelacionamento(DisciplinaDTO disciplina) {
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100);
    PdfPCell cellHeader;
    cellHeader = new PdfPCell(new Phrase("PERFIL DE RELACIONAMENTO", fontManager.getBoldFont()));
    cellHeader.setPadding(10);
    table.addCell(cellHeader);
    PdfPCell cellContent;
    cellContent = new PdfPCell();
    PerfilRelacionamentoDTO[] perfis = teachingDocumentsService.findAllPerfisRelacionamentoByDisciplina(disciplina.getId());
    for (PerfilRelacionamentoDTO perfilRelacionamento : perfis) {
        Paragraph perfil = new Paragraph(perfilRelacionamento.getTexto(), fontManager.getDefaultFont());
        cellContent.addElement(perfil);
    }
    cellContent.setPadding(10);
    table.addCell(cellContent);
    return table;
}
Also used : PerfilRelacionamentoDTO(com.tomasio.projects.trainning.dto.PerfilRelacionamentoDTO) PdfPCell(com.itextpdf.text.pdf.PdfPCell) PdfPTable(com.itextpdf.text.pdf.PdfPTable) Phrase(com.itextpdf.text.Phrase) Paragraph(com.itextpdf.text.Paragraph)

Example 35 with Phrase

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

the class DOC002PDF method buildFlexibilidadeTable.

private PdfPTable buildFlexibilidadeTable(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("FLEXIBILIDADE DA PROGRAMAÇÃO", fontManager.getBoldFont()));
    cellHeader.setPadding(10);
    cellHeader.setColspan(3);
    table.addCell(cellHeader);
    FlexibilidadeProgramacaoDTO[] flexibilidades = teachingDocumentsService.findAllFlexibilidadesProgramacaoByPUD(curriculo.getId());
    for (FlexibilidadeProgramacaoDTO flexibilidade : flexibilidades) {
        PdfPCell cellAdministracao;
        cellAdministracao = new PdfPCell(new Phrase(flexibilidade.getDescricao(), fontManager.getDefaultFont()));
        cellAdministracao.setPadding(10);
        table.addCell(cellAdministracao);
        PdfPCell cellCHAtividade;
        cellCHAtividade = new PdfPCell(new Phrase(String.valueOf(flexibilidade.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) PdfPTable(com.itextpdf.text.pdf.PdfPTable) Phrase(com.itextpdf.text.Phrase) FlexibilidadeProgramacaoDTO(com.tomasio.projects.trainning.dto.FlexibilidadeProgramacaoDTO)

Aggregations

Phrase (com.itextpdf.text.Phrase)50 PdfPCell (com.itextpdf.text.pdf.PdfPCell)42 PdfPTable (com.itextpdf.text.pdf.PdfPTable)17 Paragraph (com.itextpdf.text.Paragraph)14 Image (com.itextpdf.text.Image)7 IOException (java.io.IOException)7 Chunk (com.itextpdf.text.Chunk)6 Font (com.itextpdf.text.Font)6 BadElementException (com.itextpdf.text.BadElementException)5 DocumentException (com.itextpdf.text.DocumentException)5 ArrayList (java.util.ArrayList)5 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)4 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)4 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)4 ObjetivoDisciplinaDTO (com.tomasio.projects.trainning.dto.ObjetivoDisciplinaDTO)4 BaseColor (com.itextpdf.text.BaseColor)3 List (com.itextpdf.text.List)3 ListItem (com.itextpdf.text.ListItem)3 BaseFont (com.itextpdf.text.pdf.BaseFont)3 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)3