Search in sources :

Example 56 with Paragraph

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

the class TCATrainningDocument method createAnexo2.

private void createAnexo2(List<TurmaPlanejadaDTO> turmasPlanejadas, Map<Long, CursoDTO> cursosMap) {
    Map<Long, List<TurmaDTO>> turmasMap = // ReportUtil.buildTurmasMapByCurso(turmasPlanejadas);
    null;
    Map<Long, AnotacaoDTO[]> anotacoesMap = new HashMap<Long, AnotacaoDTO[]>();
    // ReportUtil.arrangeAnotacoesMapByTurmas(turmasPlanejadas, anotacoesMap);
    // ReportUtil.getCursos(cursosMap);
    List<CursoDTO> cursos = null;
    try {
        for (CursoDTO curso : cursos) {
            if (curso == null) {
                continue;
            }
            List<String> listaEspecial = new ArrayList<String>();
            listaEspecial.add("ATM021");
            listaEspecial.add("CTP001");
            listaEspecial.add("OPM004");
            listaEspecial.add("RAD013");
            listaEspecial.add("RAD021");
            listaEspecial.add("RAD022");
            listaEspecial.add("RAD024");
            listaEspecial.add("RAD033");
            listaEspecial.add("SAR003");
            listaEspecial.add("SIV520");
            listaEspecial.add("SIV538");
            listaEspecial.add("SIV556");
            listaEspecial.add("SIV560");
            listaEspecial.add("TEL022");
            listaEspecial.add("TEL025");
            if (!listaEspecial.contains(curso.getCodigo())) {
                document.newPage();
            }
            Paragraph p = null;
            p = new Paragraph(ReportUtil.convertEncode(curso.getCodigo()) + " - " + ReportUtil.convertEncode(curso.getDescricao()), fontManager.getH1Font());
            p.setAlignment(Element.ALIGN_LEFT);
            document.add(p);
            List<TurmaDTO> turmas = turmasMap.get(curso.getId());
            document.add(Chunk.NEWLINE);
            if (turmas.size() == 0) {
                Paragraph pCod = null;
                pCod = new Paragraph(ReportUtil.convertEncode("Não há turmas"), fontManager.getH2Font());
                document.add(pCod);
            }
            FolhaRostoDTO folha = planningService.findFolhaRosto(curso.getCodigo());
            if (folha == null) {
                System.out.println("folha nula" + curso.getCodigo());
            } else {
                Paragraph folhasTitle = new Paragraph(ReportUtil.convertEncode("FOLHA DE ROSTO:"), fontManager.getBoldFont());
                document.add(folhasTitle);
                PdfPTable t = new PdfPTable(1);
                t.setSpacingBefore(10f);
                t.setSpacingAfter(20f);
                // t.setTotalWidth(130);
                t.setHorizontalAlignment(Element.ALIGN_LEFT);
                t.setWidthPercentage(100);
                // table.setWidths(new int[]{50, 30});
                // t.addCell(tableManager.getPhraseCellCenterBold(curso.getCodigo() + " - " + curso.getDescricao()));
                t.addCell(tableManager.getPhraseCellLeft("OBJETIVO:  \n" + folha.getObjetivo()));
                t.addCell(tableManager.getPhraseCellLeft("NVEL: " + folha.getNivel()));
                String numero = "";
                if (curso.getDuracao() == 1) {
                    numero = "dia útil";
                } else {
                    numero = "dias úteis";
                }
                t.addCell(tableManager.getPhraseCellLeft("DURAO: " + NumberConverterHelper.convert(curso.getDuracao()) + " " + numero));
                t.addCell(tableManager.getPhraseCellLeft("PR-REQUISITOS: \n" + folha.getPreRequisitos()));
                t.addCell(tableManager.getPhraseCellLeft("DISCIPLINAS:\n" + folha.getDisciplinas()));
                document.add(t);
            }
            Paragraph turmasTitle = new Paragraph(ReportUtil.convertEncode("TURMAS PLANEJADAS:"), fontManager.getBoldFont());
            document.add(turmasTitle);
            if (turmas != null) {
                for (TurmaDTO turma : turmas) {
                    com.itextpdf.text.List turmaDetails = new com.itextpdf.text.List();
                    turmaDetails.setListSymbol("");
                    TurmaPlanejadaDTO turmaPlanejada = (TurmaPlanejadaDTO) turma;
                    String textTurma = "";
                    if (turmaPlanejada.getNumeroTurma() < 10) {
                        textTurma = " - TU 0";
                    } else {
                        textTurma = " - TU ";
                    }
                    Paragraph numeroTurmaParagraph = new Paragraph(ReportUtil.convertEncode("" + curso.getCodigo() + textTurma + String.valueOf(turmaPlanejada.getNumeroTurma())), fontManager.getH2Font());
                    ListItem itemNumeroTurma = new ListItem(numeroTurmaParagraph);
                    turmaDetails.add(itemNumeroTurma);
                    // document.add(numeroTurmaParagraph);
                    Paragraph localTurmaParagraph = new Paragraph(ReportUtil.convertEncode("Local de Realização: " + turmaPlanejada.getLocal()), fontManager.getDefaultFont());
                    ListItem itemLocalTurma = new ListItem(localTurmaParagraph);
                    turmaDetails.add(itemLocalTurma);
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(turma.getDataInicio());
                    calendar.add(Calendar.DAY_OF_MONTH, -30);
                    Paragraph prazoTurmaParagraph = new Paragraph(ReportUtil.convertEncode("Prazo para Indicação: " + df.format(calendar.getTime())), fontManager.getDefaultFont());
                    ListItem prazoLocalTurma = new ListItem(prazoTurmaParagraph);
                    turmaDetails.add(prazoLocalTurma);
                    // document.add(localTurmaParagraph);
                    Paragraph vagasParagraph = new Paragraph(ReportUtil.convertEncode("Vagas: " + String.valueOf(turma.getQuantidadeVagas())), fontManager.getDefaultFont());
                    ListItem itemVagas = new ListItem(vagasParagraph);
                    turmaDetails.add(itemVagas);
                    // document.add(vagasParagraph);
                    document.add(turmaDetails);
                    Paragraph fasesParagraph = new Paragraph(ReportUtil.convertEncode("Período: "), fontManager.getDefaultFont());
                    document.add(fasesParagraph);
                    FaseDTO[] fases = turmaPlanejada.getFases();
                    PdfPTable tableFases = new PdfPTable(4);
                    tableFases.setSpacingBefore(10f);
                    tableFases.setSpacingAfter(10f);
                    // table.setTotalWidth(130);
                    tableFases.setHorizontalAlignment(Element.ALIGN_LEFT);
                    tableFases.setWidthPercentage(80);
                    // table.setWidths(new int[]{50, 30});
                    tableFases.addCell(tableManager.getHeaderCell("Modalidade"));
                    tableFases.addCell(tableManager.getHeaderCell("Local"));
                    tableFases.addCell(tableManager.getHeaderCell("Início"));
                    tableFases.addCell(tableManager.getHeaderCell("Término"));
                    tableFases.getDefaultCell().setBackgroundColor(null);
                    tableFases.setHeaderRows(1);
                    for (FaseDTO faseDTO : fases) {
                        String local = "A DEFINIR";
                        if (faseDTO.getLocal() != null) {
                            local = faseDTO.getLocal().getSigla();
                        }
                        String dataInicio = "A DEFINIR";
                        if (faseDTO.getDataInicio() != null) {
                            dataInicio = df.format(faseDTO.getDataInicio());
                        }
                        String dataTermino = "A DEFINIR";
                        if (faseDTO.getDataTermino() != null) {
                            dataTermino = df.format(faseDTO.getDataTermino());
                        }
                        tableFases.addCell(tableManager.getPhraseCellLeft(faseDTO.getDescricao()));
                        tableFases.addCell(tableManager.getPhraseCellCenter(local));
                        tableFases.addCell(tableManager.getPhraseCellCenter(dataInicio));
                        tableFases.addCell(tableManager.getPhraseCellCenter(dataTermino));
                    }
                    document.add(tableFases);
                    Paragraph distribuicaoParagraph = new Paragraph(ReportUtil.convertEncode("Distribuição de Vagas: "), fontManager.getDefaultFont());
                    document.add(distribuicaoParagraph);
                    PdfPTable table = new PdfPTable(2);
                    table.setSpacingBefore(10f);
                    table.setSpacingAfter(10f);
                    // table.setTotalWidth(130);
                    table.setHorizontalAlignment(Element.ALIGN_LEFT);
                    table.setWidthPercentage(80);
                    // table.setWidths(new int[]{50, 30});
                    table.addCell(tableManager.getHeaderCell("Unidade"));
                    table.addCell(tableManager.getHeaderCell("Vagas"));
                    table.getDefaultCell().setBackgroundColor(null);
                    table.setHeaderRows(1);
                    TreinamentoPlanejadoDTO[] treinamentosPlanejados = null;
                    // turmaPlanejada.getTreinamentosPlanejados();
                    Arrays.sort(treinamentosPlanejados, new Comparator<TreinamentoPlanejadoDTO>() {

                        @Override
                        public int compare(TreinamentoPlanejadoDTO o1, TreinamentoPlanejadoDTO o2) {
                            return o1.getOrganizacao().getSigla().compareTo(o2.getOrganizacao().getSigla());
                        }
                    });
                    for (TreinamentoPlanejadoDTO treinamentoDTO : treinamentosPlanejados) {
                        table.addCell(tableManager.getPhraseCellLeft(treinamentoDTO.getOrganizacao().getSigla()));
                        table.addCell(tableManager.getPhraseCellCenter(String.valueOf(treinamentoDTO.getQuantidade())));
                    }
                    document.add(table);
                    AnotacaoDTO[] listAnotacoes = anotacoesMap.get(turma.getId());
                    String anotacao = "";
                    if (anotacoesMap.get(turma.getId()) != null) {
                        for (AnotacaoDTO anotacaoDTO : listAnotacoes) {
                            if (!anotacaoDTO.isVisibleInTca()) {
                                anotacao += anotacaoDTO.getTexto() + "\n";
                            }
                        }
                    }
                    if (listAnotacoes != null && listAnotacoes.length > 0) {
                        Paragraph anotacoesParagraph = new Paragraph(ReportUtil.convertEncode("Observações: " + anotacao), fontManager.getDefaultFont());
                        document.add(anotacoesParagraph);
                    }
                    document.add(Chunk.NEWLINE);
                }
                document.add(Chunk.NEWLINE);
            }
        }
    } catch (DocumentException ex) {
        Logger.getLogger(TCATrainningDocument.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TurmaDTO(com.tomasio.projects.trainning.dto.TurmaDTO) FaseDTO(com.tomasio.projects.trainning.dto.FaseDTO) PdfPTable(com.itextpdf.text.pdf.PdfPTable) DocumentException(com.itextpdf.text.DocumentException) ArrayList(java.util.ArrayList) List(java.util.List) TreinamentoPlanejadoDTO(com.tomasio.projects.trainning.dto.TreinamentoPlanejadoDTO) TurmaPlanejadaDTO(com.tomasio.projects.trainning.dto.TurmaPlanejadaDTO) Calendar(java.util.Calendar) FolhaRostoDTO(com.tomasio.projects.trainning.dto.FolhaRostoDTO) Paragraph(com.itextpdf.text.Paragraph) AnotacaoDTO(com.tomasio.projects.trainning.dto.AnotacaoDTO) CursoDTO(com.tomasio.projects.trainning.dto.CursoDTO) ListItem(com.itextpdf.text.ListItem)

Example 57 with Paragraph

use of com.itextpdf.text.Paragraph in project ASCIIGenome by dariober.

the class Pdf method ansiFileToPdfParagraphs.

/**
 * Read ansi formatted file line by lone and convert each line to
 * a iText paragraph.
 * @throws IOException
 * @throws InvalidColourException
 */
private List<Paragraph> ansiFileToPdfParagraphs(float fontSize) throws IOException, InvalidColourException {
    List<Paragraph> paraList = new ArrayList<Paragraph>();
    // Files.readAllBytes(Paths.get(this.ansiInput.toURI()));
    byte[] encoded = this.ansiInput.getBytes();
    String str = new String(encoded);
    // Each string in this list is a sequence of a characters sharing the same formatting.
    List<String> ansiList = Splitter.on("\033").splitToList(str);
    Paragraph pdfLine = new Paragraph();
    int nChars = 0;
    int currentMax = 0;
    for (String xv : ansiList) {
        // if(xv.equals("[48;5;231m")){
        // continue;
        // }
        BaseColor fgBaseCol = new BaseColor(this.xterm256ToColor(xv, false).getRGB());
        BaseColor bgBaseCol = new BaseColor(this.xterm256ToColor(xv, true).getRGB());
        if (this.extractAnsiCodes(xv).size() != 0) {
            // This string begins with ansi sequence and the color has been extracted.
            // So remove the ansi sequence at the beginnig and the end, we don't need them anymore
            xv = xv.replaceAll("^.+?m", "");
        }
        for (int i = 0; i < xv.length(); i++) {
            char c = xv.charAt(i);
            nChars += 1;
            Chunk chunk = new Chunk(c, new Font(Font.FontFamily.COURIER, fontSize, Font.NORMAL, fgBaseCol));
            chunk.setBackground(bgBaseCol);
            pdfLine.add(chunk);
            if (c == '\n') {
                // Newline found: Start a new parapgrah
                paraList.add(pdfLine);
                if (nChars > currentMax) {
                    currentMax = nChars;
                }
                nChars = 0;
                pdfLine = new Paragraph();
            }
        }
    }
    Font f = new Font(Font.FontFamily.COURIER, fontSize);
    Chunk chunk = new Chunk("X", f);
    this.setMaxWidth((int) ((currentMax) * chunk.getWidthPoint()));
    for (Paragraph p : paraList) {
        p.setSpacingBefore(-3);
        p.setSpacingAfter(-3);
    }
    this.setMaxHeight((int) Math.rint((paraList.size() + 1) * fontSize));
    return paraList;
}
Also used : BaseColor(com.itextpdf.text.BaseColor) ArrayList(java.util.ArrayList) Chunk(com.itextpdf.text.Chunk) Font(com.itextpdf.text.Font) Paragraph(com.itextpdf.text.Paragraph)

Example 58 with Paragraph

use of com.itextpdf.text.Paragraph in project opentheso by miledrousset.

the class itextPdf method start_test.

@Test
public void start_test() throws DocumentException, FileNotFoundException {
    try {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream("test-itext.pdf"));
        // step 3
        document.open();
        String FONT = "fonts/FreeSans.ttf";
        BaseFont bf1 = BaseFont.createFont(FONT, BaseFont.WINANSI, BaseFont.EMBEDDED);
        Font french = new Font(bf1, 12);
        BaseFont bf2 = BaseFont.createFont(FONT, BaseFont.CP1250, BaseFont.EMBEDDED);
        Font czech = new Font(bf2, 12);
        BaseFont bf3 = BaseFont.createFont(FONT, "Cp1251", BaseFont.EMBEDDED);
        Font russian = new Font(bf3, 12);
        document.add(new Paragraph("Vous \u00eates d'o\u00f9?", french));
        document.add(new Paragraph("\u00c0 tout \u00e0 l'heure. \u00c0 bient\u00f4t.", french));
        document.add(new Paragraph("Je me pr\u00e9sente.", french));
        document.add(new Paragraph("C'est un \u00e9tudiant.", french));
        document.add(new Paragraph("\u00c7a va?", french));
        document.add(new Paragraph("Il est ing\u00e9nieur. Elle est m\u00e9decin.", french));
        document.add(new Paragraph("C'est une fen\u00eatre.", french));
        document.add(new Paragraph("R\u00e9p\u00e9tez, s'il vous pla\u00eet.", french));
        document.add(new Paragraph("Odkud jste?", czech));
        document.add(new Paragraph("Uvid\u00edme se za chvilku. M\u011bj se.", czech));
        document.add(new Paragraph("Dovolte, abych se p\u0159edstavil.", czech));
        document.add(new Paragraph("To je studentka.", czech));
        document.add(new Paragraph("V\u0161echno v po\u0159\u00e1dku?", czech));
        document.add(new Paragraph("On je in\u017een\u00fdr. Ona je l\u00e9ka\u0159.", czech));
        document.add(new Paragraph("Toto je okno.", czech));
        document.add(new Paragraph("Zopakujte to pros\u00edm.", czech));
        document.add(new Paragraph("\u041e\u0442\u043a\u0443\u0434\u0430 \u0442\u044b?", russian));
        document.add(new Paragraph("\u0423\u0432\u0438\u0434\u0438\u043c\u0441\u044f \u0432 \u043d\u0435\u043c\u043d\u043e\u0433\u043e. \u0423\u0432\u0438\u0434\u0438\u043c\u0441\u044f.", russian));
        document.add(new Paragraph("\u041f\u043e\u0437\u0432\u043e\u043b\u044c\u0442\u0435 \u043c\u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c\u0441\u044f.", russian));
        document.add(new Paragraph("\u042d\u0442\u043e \u0441\u0442\u0443\u0434\u0435\u043d\u0442.", russian));
        document.add(new Paragraph("\u0425\u043e\u0440\u043e\u0448\u043e?", russian));
        document.add(new Paragraph("\u041e\u043d \u0438\u043d\u0436\u0435\u043d\u0435\u0440. \u041e\u043d\u0430 \u0434\u043e\u043a\u0442\u043e\u0440.", russian));
        document.add(new Paragraph("\u042d\u0442\u043e \u043e\u043a\u043d\u043e.", russian));
        document.add(new Paragraph("\u041f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u0435, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.", russian));
        Font catFont = new Font(Font.FontFamily.TIMES_ROMAN, 30, Font.BOLD);
        document.add(new Paragraph("Title of the document", catFont));
        // step 4
        document.add(new Paragraph("Hello World!\n test \n                  test"));
        Chunk chunk = new Chunk("Go to Contact information");
        chunk.setLocalGoto("contact");
        document.add(new Paragraph(chunk));
        document.newPage();
        document.add(new Paragraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut consectetur, nisi non commodo interdum, nunc massa sodales velit, vel elementum ipsum odio id ligula. Aliquam sed sapien eget nibh varius varius id ac quam. Aliquam id arcu enim. Curabitur sollicitudin placerat dui, nec venenatis ipsum consectetur ut. Fusce sem nibh, semper et nibh sed, varius mattis ipsum. Duis tristique mauris velit. Nam eleifend sapien tempus, sollicitudin risus sit amet, dignissim nisl. Aliquam tincidunt rutrum auctor. Integer sollicitudin lectus faucibus ipsum facilisis imperdiet. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aliquam erat volutpat. Etiam eu commodo massa, ac venenatis est. Sed venenatis mattis vehicula. Duis eleifend lacus nec purus convallis, non mollis justo commodo. Aenean et arcu vitae metus pharetra venenatis ac non tellus. Vestibulum ultrices turpis urna, vitae condimentum sem pharetra in.\n" + "\n" + "Maecenas aliquet auctor ipsum eget congue. Sed at ullamcorper ante. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse scelerisque at erat at condimentum. Vivamus sed aliquet risus, non tempor odio. Etiam pulvinar, mauris ut placerat consequat, ipsum massa imperdiet turpis, eget consequat justo metus sit amet ligula. Donec vel lacinia erat. Donec eget enim sed justo euismod vehicula ut in metus. Suspendisse augue dolor, tempor eu mollis vitae, pellentesque sit amet nulla. Morbi ac sapien arcu. Vivamus in elit dictum orci dapibus blandit eget vitae est. Morbi sed ultricies neque. Ut at fringilla urna. Quisque dictum bibendum nisi, non pellentesque velit cursus vel.\n" + "\n" + "Etiam convallis tincidunt arcu sit amet pellentesque. Suspendisse vitae gravida tellus. Fusce consectetur turpis condimentum, molestie libero pellentesque, aliquet dolor. Duis ullamcorper purus sem, id ornare lacus interdum non. Aenean quis arcu elementum, ultrices tellus sed, dapibus nisl. Aliquam ut iaculis mi, vitae porttitor tellus. Vestibulum lacinia velit sed venenatis volutpat. Nullam magna ipsum, feugiat vestibulum nunc tincidunt, egestas ultrices libero. Quisque fringilla risus ut lectus posuere vulputate. Fusce diam mi, efficitur vitae nulla eget, facilisis luctus nisi. Sed scelerisque hendrerit porttitor. Aenean mollis, urna in bibendum bibendum, lectus orci dictum sapien, ut pretium dui lacus vel turpis. Nunc hendrerit est sit amet turpis venenatis suscipit. Phasellus fermentum aliquam tellus nec sodales.\n" + "\n" + "Etiam eget scelerisque erat, nec commodo arcu. Nullam tempus vehicula auctor. Integer feugiat ornare viverra. In nulla arcu, faucibus ut risus malesuada, elementum egestas eros. Maecenas varius augue faucibus, vulputate turpis at, vestibulum nisi. Etiam placerat vehicula erat, ac viverra nulla interdum id. Sed nibh sem, bibendum ac sodales vitae, iaculis vel magna. Phasellus fringilla quis lectus ac egestas. Praesent iaculis, orci non ultrices mattis, urna ipsum suscipit tortor, nec viverra mi tortor id libero. Quisque vehicula malesuada elit, vitae interdum nunc. In laoreet viverra scelerisque. Nam venenatis blandit tortor, vel aliquam mi rutrum eget. In ut nibh ut nibh lobortis ullamcorper. Morbi neque elit, dictum vel justo nec, pulvinar fermentum purus. Sed consequat dictum hendrerit. Quisque pulvinar mi volutpat est aliquet facilisis.\n" + "\n" + "Phasellus ultrices euismod ligula, ac sagittis diam semper eu. Nulla aliquam justo vel leo congue condimentum. Fusce molestie tellus felis, vel fringilla mi molestie ac. Praesent venenatis sapien eget lectus gravida, vitae condimentum ligula sagittis. Mauris varius placerat sagittis. Phasellus eget tortor quis felis pellentesque malesuada pharetra a lectus. Sed rutrum mi id aliquam lacinia. Donec posuere auctor vulputate. Duis a ante id nisl cursus accumsan. "));
        Chunk chunk1 = new Chunk("Contact information");
        chunk1.setLocalDestination("contact");
        Chapter chapter = new Chapter(new Paragraph(chunk1), 1);
        chapter.setNumberDepth(0);
        document.add(chapter);
        PdfPTable table = new PdfPTable(2);
        table.addCell(new Paragraph("test 1", catFont));
        table.addCell("2");
        document.add(table);
        // step 5
        document.close();
    } catch (IOException ex) {
        Logger.getLogger(itextPdf.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : PdfPTable(com.itextpdf.text.pdf.PdfPTable) FileOutputStream(java.io.FileOutputStream) BaseFont(com.itextpdf.text.pdf.BaseFont) Chapter(com.itextpdf.text.Chapter) IOException(java.io.IOException) Document(com.itextpdf.text.Document) Chunk(com.itextpdf.text.Chunk) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont) Paragraph(com.itextpdf.text.Paragraph) Test(org.junit.Test)

Example 59 with Paragraph

use of com.itextpdf.text.Paragraph in project opentheso by miledrousset.

the class BaseDeDonnesBean method pdf.

/**
 * permet de generer une document pour pouvoir le telecharger
 * le format c'est pdf
 * @return
 * @throws SQLException
 * @throws Exception
 */
public StreamedContent pdf() throws SQLException, Exception {
    Thesaurus thesaurus = new Thesaurus();
    ExportStatistiques expo = new ExportStatistiques();
    expo.recuperatefils(connect.getPoolConnexion(), theso.getThesaurus().getId_thesaurus(), theso.getThesaurus().getLanguage(), 2);
    Document pdf = new Document(PageSize.LETTER);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer;
    Paragraph para = new Paragraph(expo.getDocument());
    writer = PdfWriter.getInstance(pdf, baos);
    if (!pdf.isOpen()) {
        pdf.open();
    }
    pdf.addTitle("theso");
    pdf.add(para);
    // Adding content to pdf
    pdf.close();
    InputStream stream = new ByteArrayInputStream(baos.toByteArray());
    fileDownload = new DefaultStreamedContent(stream, "application/pdf", "Thésaurus" + thesaurus.getId_thesaurus() + ".pdf");
    return fileDownload;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) PdfWriter(com.itextpdf.text.pdf.PdfWriter) Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) ByteArrayInputStream(java.io.ByteArrayInputStream) ExportStatistiques(mom.trd.opentheso.core.exports.helper.ExportStatistiques) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.itextpdf.text.Document) Paragraph(com.itextpdf.text.Paragraph)

Example 60 with Paragraph

use of com.itextpdf.text.Paragraph in project opentheso by miledrousset.

the class WritePdf method writeHieraPDF.

/**
 * ecri un thésaurus en PDF par ordre hiérarchique
 */
private void writeHieraPDF(ArrayList<Paragraph> paragraphs, String langue, String langue2, boolean isTrad, HashMap<String, ArrayList<String>> idToDoc) {
    ArrayList<SKOSResource> conceptList = xmlDocument.getConceptList();
    System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
    Collections.sort(conceptList, sortForHiera(isTrad, langue, langue2, idToNameHashMap, idToChildId, idToDoc, idToMatch, idToGPS, resourceChecked, idToIsTradDiff));
    for (SKOSResource concept : conceptList) {
        boolean isAtRoot = true;
        String conceptID = getIdFromUri(concept.getUri());
        Iterator i = idToChildId.keySet().iterator();
        String clef;
        ArrayList<String> valeur;
        while (i.hasNext()) {
            clef = (String) i.next();
            valeur = (ArrayList<String>) idToChildId.get(clef);
            for (String id : valeur) {
                if (id.equals(conceptID)) {
                    isAtRoot = false;
                }
            }
        }
        if (isAtRoot) {
            String name = idToNameHashMap.get(conceptID);
            if (name == null) {
                name = "";
            }
            paragraphs.add(new Paragraph(name + " (" + conceptID + ")", termFont));
            String indentation = "";
            writeHieraTermInfo(conceptID, indentation, paragraphs, idToDoc);
            writeHieraTermRecursif(conceptID, indentation, paragraphs, idToDoc);
        }
    }
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) Iterator(java.util.Iterator) 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