Search in sources :

Example 6 with BadElementException

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

the class DOC002PDF method buildFrontispicio.

private void buildFrontispicio(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);
    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(curriculoMinimo.getCurso().getDescricao(), fontManager.getDefaultFont()));
    // Paragraph p7 = new Paragraph();
    // p7.setAlignment(Element.ALIGN_CENTER);
    // p7.add(new Phrase("PLANO DE UNIDADES DIDÁTICAS DO CURSO " + curriculoMinimo.getCurso().getCodigo(), fontManager.getDefaultFont()));
    // Paragraph p8 = new Paragraph();
    // p8.setAlignment(Element.ALIGN_CENTER);
    // p8.add(new Phrase(curriculoMinimo.getAnoPublicacaoPUD(), fontManager.getDefaultFont()));
    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.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 7 with BadElementException

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

the class PDFTitlePage method getLogo.

/*
	 * Methods for the different attributes.
	 * 
	 */
private Image getLogo() {
    try {
        URL url = new URL(job_info.getDlConfig().getAsString("pdf-logo"));
        if (url != null && !url.equals("")) {
            Image logo = Image.getInstance(url);
            logo.setAlignment(Element.ALIGN_CENTER);
            return logo;
        }
    } catch (BadElementException e) {
        logger.error(e.getMessage());
    } catch (MalformedURLException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) BadElementException(com.itextpdf.text.BadElementException) IOException(java.io.IOException) Image(com.itextpdf.text.Image) URL(java.net.URL)

Aggregations

BadElementException (com.itextpdf.text.BadElementException)7 Image (com.itextpdf.text.Image)7 IOException (java.io.IOException)7 Phrase (com.itextpdf.text.Phrase)5 Paragraph (com.itextpdf.text.Paragraph)4 PdfPCell (com.itextpdf.text.pdf.PdfPCell)4 PdfPTable (com.itextpdf.text.pdf.PdfPTable)3 BaseColor (com.itextpdf.text.BaseColor)1 DocumentException (com.itextpdf.text.DocumentException)1 Font (com.itextpdf.text.Font)1 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1