Search in sources :

Example 6 with Chapter

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

the class DOC001PDF method buildChapter2.

private Chapter buildChapter2(CurriculoMinimoDTO curriculo) {
    Chapter ch = new Chapter(new Paragraph("CONCEPÇÃO ESTRUTURAL DO CURSO", fontManager.getBoldFont()), 2);
    IReportUtil.fillChapter(ch, curriculo.getConcepcaoEstrutural());
    return ch;
}
Also used : Chapter(com.itextpdf.text.Chapter) Paragraph(com.itextpdf.text.Paragraph)

Example 7 with Chapter

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

the class DOC001PDF method buildChapter1.

private Chapter buildChapter1(CurriculoMinimoDTO curriculo) {
    Chapter ch = new Chapter(new Paragraph("DISPOSIÇÕES PRELIMINARES", fontManager.getBoldFont()), 1);
    Section section1 = ch.addSection(new Paragraph("FINALIDADE", fontManager.getUnderlineFont()));
    IReportUtil.fillSection(section1, curriculo.getFinalidadeInstrucao());
    Section section2 = ch.addSection(new Paragraph("ÂMBITO", fontManager.getUnderlineFont()));
    IReportUtil.fillSection(section2, curriculo.getAmbito());
    Section section3 = ch.addSection(new Paragraph("DEFINIÇÕES", fontManager.getUnderlineFont()));
    IReportUtil.fillSection(section3, curriculo.getConceituacoes());
    return ch;
}
Also used : Chapter(com.itextpdf.text.Chapter) Section(com.itextpdf.text.Section) Paragraph(com.itextpdf.text.Paragraph)

Example 8 with Chapter

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

the class DOC003PDF method buildCapitulo.

private Chapter buildCapitulo(CapituloApostilaDTO capitulo, XMLParser p, Document document) throws IOException, DocumentException {
    UnidadeDidaticaDTO unidade = teachingDocumentsService.findUnidadeDidatica(capitulo.getUnidadeDidatica().getId());
    String capituloLabel = "UNIDADE " + unidade.getNumeroGeral() + ": " + capitulo.getUnidadeDidatica().getDescricao().toUpperCase();
    Paragraph capituloParagraph = new Paragraph(capituloLabel, fontManager.getH1Font());
    Chapter ch = new Chapter(capituloParagraph, capitulo.getUnidadeDidatica().getNumero());
    ch.setNumberDepth(0);
    buildFolhaRostoCapitulo(ch, capitulo);
    SecaoApostilaDTO[] secoes = teachingDocumentsService.findAllSecoesApostila(capitulo.getId());
    for (SecaoApostilaDTO secao : secoes) {
        if (secao.getContent() != null) {
            buildSection(ch, secao, p, document);
        }
    }
    return ch;
// fim do capitulo
}
Also used : SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) Chapter(com.itextpdf.text.Chapter) UnidadeDidaticaDTO(com.tomasio.projects.trainning.dto.UnidadeDidaticaDTO) ObjetivoUnidadeDidaticaDTO(com.tomasio.projects.trainning.dto.ObjetivoUnidadeDidaticaDTO) Paragraph(com.itextpdf.text.Paragraph)

Example 9 with Chapter

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

the class DOC003PDF 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();
    CSSResolver cssResolver = new StyleAttrCSSResolver();
    CssFile cssFile = null;
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    String cssStylePath = classLoader.getResource("doc3-styles.css").getPath();
    cssFile = XMLWorkerHelper.getCSS(classLoader.getResourceAsStream("doc3-styles.css"));
    cssResolver.addCss(cssFile);
    XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
    String fontFilePath = classLoader.getResource("MyriadPro-Regular.otf").getPath();
    // fontProvider.register(fontFilePath);
    CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
    htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
    PdfWriterPipeline pdf = new PdfWriterPipeline(document, writer);
    HtmlPipeline html = new HtmlPipeline(htmlContext, pdf);
    CssResolverPipeline css = new CssResolverPipeline(cssResolver, html);
    XMLWorker worker = new XMLWorker(css, true);
    p = new XMLParser(worker);
    try {
        String apostilaIdParam = (String) params.get("apostilaId");
        Long apostilaId = Long.parseLong(apostilaIdParam);
        ApostilaDTO apostila = teachingDocumentsService.findApostila(apostilaId);
        CurriculoMinimoDTO curriculo = teachingDocumentsService.findCurriculoMinimo(apostila.getDisciplina().getCurriculoMinimo().getId());
        buildCover(document, curriculo, apostila);
        CapituloApostilaDTO[] capitulos = teachingDocumentsService.findAllCapitulosApostila(apostilaId);
        for (CapituloApostilaDTO capitulo : capitulos) {
            Chapter ch = buildCapitulo(capitulo, p, document);
            document.add(ch);
        }
        document.add(buildReferencias(apostilaId));
        document.add(buildSumario(eventHandler.titles));
    } catch (DocumentException e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e);
        throw new CoreException(e.getMessage());
    } catch (IOException ex) {
        Logger.getLogger(DOC003PDF.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        document.close();
    }
    try {
        PdfReader reader = new PdfReader(os.toByteArray());
        int n = reader.getNumberOfPages();
        String pagesInterval = String.format("1-2,%d, 3-%d", n, n - 1);
        reader.selectPages(pagesInterval);
        os = new ByteArrayOutputStream();
        PdfStamper stamper = new PdfStamper(reader, os);
        stamper.close();
        reader.close();
    } catch (IOException | DocumentException ex) {
        Logger.getLogger(DOC003PDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : StyleAttrCSSResolver(com.itextpdf.tool.xml.css.StyleAttrCSSResolver) CssFile(com.itextpdf.tool.xml.css.CssFile) PdfReader(com.itextpdf.text.pdf.PdfReader) CssAppliersImpl(com.itextpdf.tool.xml.html.CssAppliersImpl) CSSResolver(com.itextpdf.tool.xml.pipeline.css.CSSResolver) StyleAttrCSSResolver(com.itextpdf.tool.xml.css.StyleAttrCSSResolver) DocumentException(com.itextpdf.text.DocumentException) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) CurriculoMinimoDTO(com.tomasio.projects.trainning.dto.CurriculoMinimoDTO) XMLParser(com.itextpdf.tool.xml.parser.XMLParser) HtmlPipeline(com.itextpdf.tool.xml.pipeline.html.HtmlPipeline) SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) ApostilaDTO(com.tomasio.projects.trainning.dto.ApostilaDTO) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) Chapter(com.itextpdf.text.Chapter) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CssResolverPipeline(com.itextpdf.tool.xml.pipeline.css.CssResolverPipeline) XMLWorkerFontProvider(com.itextpdf.tool.xml.XMLWorkerFontProvider) XMLWorker(com.itextpdf.tool.xml.XMLWorker) CoreException(com.tomasio.projects.trainning.exeption.CoreException) CssAppliers(com.itextpdf.tool.xml.html.CssAppliers) PdfWriterPipeline(com.itextpdf.tool.xml.pipeline.end.PdfWriterPipeline) PdfStamper(com.itextpdf.text.pdf.PdfStamper) HtmlPipelineContext(com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext)

Example 10 with Chapter

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

the class DOC003PDF method buildReferencias.

private Chapter buildReferencias(Long apostilaId) {
    ApostilaDTO apostila = teachingDocumentsService.findApostila(apostilaId);
    ReferenciaDTO[] referencias = teachingDocumentsService.findAllReferenciasByDisciplina(apostila.getDisciplina().getId());
    String referenciasLabel = "REFERÊNCIAS";
    Paragraph referenciasChapter = new Paragraph(referenciasLabel, fontManager.getBoldFont());
    referenciasChapter.setAlignment(Element.ALIGN_CENTER);
    Chapter ch = new Chapter(referenciasChapter, 0);
    ch.setNumberDepth(0);
    ch.add(Chunk.NEWLINE);
    for (ReferenciaDTO referencia : referencias) {
        ch.add(new Paragraph(referencia.getTexto(), fontManager.getDefaultFont()));
    }
    return ch;
}
Also used : ReferenciaDTO(com.tomasio.projects.trainning.dto.ReferenciaDTO) SecaoApostilaDTO(com.tomasio.projects.trainning.dto.SecaoApostilaDTO) ApostilaDTO(com.tomasio.projects.trainning.dto.ApostilaDTO) CapituloApostilaDTO(com.tomasio.projects.trainning.dto.CapituloApostilaDTO) Chapter(com.itextpdf.text.Chapter) Paragraph(com.itextpdf.text.Paragraph)

Aggregations

Chapter (com.itextpdf.text.Chapter)27 Paragraph (com.itextpdf.text.Paragraph)25 Section (com.itextpdf.text.Section)8 IOException (java.io.IOException)6 DocumentException (com.itextpdf.text.DocumentException)5 Document (com.itextpdf.text.Document)4 Font (com.itextpdf.text.Font)4 SecaoApostilaDTO (com.tomasio.projects.trainning.dto.SecaoApostilaDTO)4 FileOutputStream (java.io.FileOutputStream)4 PdfPTable (com.itextpdf.text.pdf.PdfPTable)3 PdfWriter (com.itextpdf.text.pdf.PdfWriter)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 ModelPDFRodape (model.bean.ModelPDFRodape)3 Projeto (model.bean.Projeto)3 Requisito (model.bean.Requisito)3 ProjetoDAO (model.dao.ProjetoDAO)3