Example usage for com.lowagie.text Paragraph add

List of usage examples for com.lowagie.text Paragraph add

Introduction

In this page you can find the example usage for com.lowagie.text Paragraph add.

Prototype

public boolean add(Object o) 

Source Link

Document

Adds an Object to the Paragraph.

Usage

From source file:it.prato.comune.tolomeo.web.TolomeoPrintPDFServlet.java

License:Open Source License

private void printErr(Document doc) {
    try {/*from  w w  w .j  a  v  a2 s .  c om*/
        Paragraph par = new Paragraph();
        par.setAlignment(Paragraph.ALIGN_CENTER);
        par.add("\n\n");
        par.add("Errore di stampa!");
        par.add("\n");
        par.add("Contattare sit@comune.prato.it");

        doc.add(par);
    } catch (Exception e) {
    }
}

From source file:mx.dr.util.report.impl.PdfService.java

License:Open Source License

/**
* write a label in pdf document.//from  w ww. j  ava  2 s .  c  o m
* <br/>
* escribe una etiqueta en el documento pdf.
* @param doc pdf document / documento pdf.
* @param dto object that encompasses the values of the labels to be placed in the document / objeto que engloba los valores de las etiquetas que se colocaran en el documento.
* @param offset jump on the Y axis to be given before placing the tag in the document / salto en el eje Y que se dara antes de colocar la etiqueta en el documento.
* @param table container table if applicable / contenedor de tabla si es que aplica.
* @throws Exception If an error occurs / si ocurre algun error.
*/
public void estampaEtiqueta(Document doc, Object dto, Float offset, PdfPTable table) throws Exception {
    List<Field> fields = new ArrayList<Field>();

    for (Field m : dto.getClass().getDeclaredFields()) {
        m.setAccessible(true);
        if (m.getAnnotation(DRPdfLabel.class) != null) {
            fields.add(m);
        }
    }
    Collections.sort(fields, new Comparator<Field>() {

        public int compare(Field o1, Field o2) {
            DRPdfLabel etiqueta1 = o1.getAnnotation(DRPdfLabel.class);
            DRPdfLabel etiqueta2 = o2.getAnnotation(DRPdfLabel.class);
            String uno = int2String(etiqueta1.y()) + "." + int2String(etiqueta1.order());
            String dos = int2String(etiqueta2.y()) + "." + int2String(etiqueta2.order());
            return uno.compareTo(dos);

        }

        private String int2String(int num) {
            if (num < 10) {
                return "0" + num;
            } else {
                return String.valueOf(num);
            }
        }
    });
    DRPdfLabel etiqueta;
    DRPdfTable etiquetaTabla;
    int lineaActual = 0;
    Paragraph pantagram = null;
    StringBuffer sb = null;
    Font font;
    Object valor;
    String label;
    DRPdfImage img;
    int residuo;
    int adicional = 0;
    for (Field m : fields) {
        etiqueta = m.getAnnotation(DRPdfLabel.class);
        img = m.getAnnotation(DRPdfImage.class);
        valor = m.get(dto);
        if (valor != null && valor instanceof List) {
            etiquetaTabla = m.getAnnotation(DRPdfTable.class);
            PdfPTable tableDance = null;
            if (etiquetaTabla != null) {
                tableDance = new PdfPTable(etiquetaTabla.colsPercentage());
                tableDance.setSpacingBefore(etiqueta.offset());
                for (String c : etiquetaTabla.columnLabels()) {
                    tableDance.addCell(c);
                }
            }
            if (pantagram != null) {
                doc.add(pantagram);
                pantagram = null;
            }
            for (int i = 0; i < ((List) valor).size(); i++) {
                if (i == 0 && etiqueta.offset() > 0) {
                    estampaEtiqueta(doc, ((List) valor).get(i), etiqueta.offset(), tableDance);
                } else {
                    estampaEtiqueta(doc, ((List) valor).get(i), null, tableDance);
                }
            }
            if (etiquetaTabla != null) {
                doc.add(tableDance);
            }
        } else if (img != null) {
            /* File file = new File(IMGDIR + valor);
            FileInputStream inImg = new FileInputStream(file);
            byte[] b=new byte[(int)file.length()];
            inImg.read(b);*/

            Image ima = Image.getInstance(IMGDIR + valor);

            //System.out.println(ima.getPlainWidth());
            ima.scaleAbsoluteWidth(img.width());
            //System.out.println(ima.getScaledWidth());
            ima.scaleAbsoluteHeight(ima.getScaledWidth());
            ima.setAlignment(img.style());
            ima.setAbsolutePosition(img.x(), img.y());
            doc.add(ima);

        } else if (table != null) {

            PdfPCell cerda = null;

            label = value2String(valor);
            residuo = etiqueta.length() - label.length();
            label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label;
            DRPdfColumn col = m.getAnnotation(DRPdfColumn.class);
            if (col != null) {
                cerda = new PdfPCell(new Paragraph(label));
                cerda.setColspan(col.colspan());
                table.addCell(cerda);
            } else {
                table.addCell(label);
            }

        } else {
            if (lineaActual < etiqueta.y()) {
                if (pantagram != null) {
                    doc.add(pantagram);
                }
                if (offset == null || etiqueta.y() > 1) {
                    if (etiqueta.offset() > 0) {
                        pantagram = new Paragraph(etiqueta.offset());
                    } else {
                        pantagram = new Paragraph();
                    }
                } else {
                    pantagram = new Paragraph(offset);
                }
                lineaActual = etiqueta.y();
            }

            if (etiqueta.wspacesBefore() > 0) {
                sb = new StringBuffer("");
                fillEmpty(etiqueta.wspacesBefore(), sb);
                font = new Font(Font.COURIER, 12);
                pantagram.add(new Chunk(sb.toString(), font));
            }
            sb = new StringBuffer("");
            label = value2String(valor);
            residuo = etiqueta.length() - label.length();
            label = etiqueta.length() > 0 && residuo < 0 ? label.substring(0, etiqueta.length()) : label;

            if (etiqueta.font().equals(BaseFont.COURIER)) {
                font = new Font(Font.COURIER, etiqueta.fontSize(), etiqueta.style(),
                        new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2]));
                adicional = 0;
            } else {
                font = FontFactory.getFont(TTFDIR + etiqueta.font(), BaseFont.CP1252, BaseFont.EMBEDDED,
                        etiqueta.fontSize(), etiqueta.style(),
                        new Color(etiqueta.color()[0], etiqueta.color()[1], etiqueta.color()[2]));
                adicional = label.equals("") ? (residuo / 2) + 1 : 0;
            }

            if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.DER) && residuo > 0) {
                fillEmpty(residuo + adicional, sb);
            }
            sb.append(label);
            if (etiqueta.length() > 0 && etiqueta.justified().equals(DRPdfLabel.JUSTIFIED.IZQ) && residuo > 0) {
                fillEmpty(residuo + adicional, sb);
            }
            pantagram.add(new Chunk(sb.toString(), font));
        }
    }
    if (pantagram != null) {
        doc.add(pantagram);
    }

}

From source file:net.bull.javamelody.internal.web.pdf.PdfCacheInformationsReport.java

License:Apache License

private void addConfigurationReference() throws DocumentException {
    final Anchor ehcacheAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont());
    ehcacheAnchor.setName("Ehcache configuration reference");
    ehcacheAnchor.setReference(/*  w ww. j  a v  a 2 s  .  co m*/
            "http://ehcache.sourceforge.net/apidocs/net/sf/ehcache/config/CacheConfiguration.html#field_summary");
    ehcacheAnchor.setFont(PdfFonts.BLUE.getFont());
    final Paragraph ehcacheParagraph = new Paragraph();
    ehcacheParagraph.add(ehcacheAnchor);
    ehcacheParagraph.setAlignment(Element.ALIGN_RIGHT);
    addToDocument(ehcacheParagraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCoreReport.java

License:Apache License

private void writeGraphs(Collection<JRobin> jrobins, Map<String, byte[]> mySmallGraphs)
        throws IOException, DocumentException {
    if (collector.isStopped()) {
        // pas de graphs, ils seraient en erreur sans timer
        // mais un message d'avertissement  la place
        final String message = getString("collect_server_misusage");
        final Paragraph jrobinParagraph = new Paragraph(message, PdfFonts.BOLD.getFont());
        jrobinParagraph.setAlignment(Element.ALIGN_CENTER);
        addToDocument(jrobinParagraph);//from   ww  w .  ja v a 2 s.c o m
        return;
    }
    if (collector.isStorageUsedByMultipleInstances()) {
        final String message = getString("storage_used_by_multiple_instances") + "\n\n";
        final Paragraph jrobinParagraph = new Paragraph(message, PdfFonts.BOLD.getFont());
        jrobinParagraph.setAlignment(Element.ALIGN_CENTER);
        addToDocument(jrobinParagraph);
    }
    final Paragraph jrobinParagraph = new Paragraph("",
            FontFactory.getFont(FontFactory.HELVETICA, 9f, Font.NORMAL));
    jrobinParagraph.setAlignment(Element.ALIGN_CENTER);
    jrobinParagraph.add(new Phrase("\n\n\n\n"));
    final Collection<byte[]> graphs;
    if (mySmallGraphs != null) {
        // si les graphiques ont t prinitialiss (en Swing) alors on les utilise
        graphs = mySmallGraphs.values();
    } else {
        if (jrobins.isEmpty()) {
            return;
        }
        graphs = new ArrayList<byte[]>(jrobins.size());
        for (final JRobin jrobin : jrobins) {
            graphs.add(jrobin.graph(range, SMALL_GRAPH_WIDTH, SMALL_GRAPH_HEIGHT));
        }
    }
    int i = 0;
    for (final byte[] graph : graphs) {
        if (i % 3 == 0 && i != 0) {
            // un retour aprs httpSessions et avant activeThreads pour l'alignement
            jrobinParagraph.add(new Phrase("\n\n\n\n\n"));
        }
        final Image image = Image.getInstance(graph);
        image.scalePercent(50);
        jrobinParagraph.add(new Phrase(new Chunk(image, 0, 0)));
        jrobinParagraph.add(new Phrase(" "));
        i++;
    }
    jrobinParagraph.add(new Phrase("\n"));
    addToDocument(jrobinParagraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCounterRequestContextReport.java

License:Apache License

private void writeDurations(List<CounterRequestContext> contexts) throws DocumentException, IOException {
    getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

    final Paragraph paragraph = new Paragraph("", cellFont);
    boolean first = true;
    for (final CounterRequestContext context : contexts) {
        if (!first) {
            paragraph.add(new Chunk('\n', cellFont));
        }/*  w  ww.j  a v  a 2 s .c o  m*/
        final int duration = context.getDuration(timeOfSnapshot);
        final Counter parentCounter = context.getParentCounter();
        final PdfCounterReport counterReport = counterReportsByCounterName.get(parentCounter.getName());
        if (parentCounter.getIconName() != null) {
            paragraph.add(new Chunk(getImage(parentCounter.getIconName()), 0, -1));
        }
        final Font slaFont;
        if (counterReport == null) {
            slaFont = infoCellFont;
        } else {
            slaFont = counterReport.getSlaFont(duration);
        }
        paragraph.add(new Phrase(integerFormat.format(duration), slaFont));
        first = false;
    }
    addCell(paragraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfCounterRequestContextReport.java

License:Apache License

private void writeRequest(CounterRequestContext context, PdfPCell cell, int margin)
        throws DocumentException, IOException {
    final Paragraph paragraph = new Paragraph(getDefaultCell().getLeading() + cellFont.getSize());
    paragraph.setIndentationLeft(margin);
    if (context.getParentCounter().getIconName() != null) {
        paragraph.add(new Chunk(getImage(context.getParentCounter().getIconName()), 0, -1));
    }/*from  ww w.  ja  va2s.  c  o m*/
    paragraph.add(new Phrase(context.getCompleteRequestName(), cellFont));
    cell.addElement(paragraph);
}

From source file:net.bull.javamelody.internal.web.pdf.PdfDocumentFactory.java

License:Apache License

Element createParagraphElement(String paragraphTitle, String iconName) throws DocumentException, IOException {
    final Paragraph paragraph = new Paragraph("", paragraphTitleFont);
    paragraph.setSpacingBefore(5);/*www  . j a va  2 s . c  o m*/
    paragraph.setSpacingAfter(5);
    if (iconName != null) {
        paragraph.add(new Chunk(getParagraphImage(iconName), 0, -5));
    }
    final Phrase element = new Phrase(' ' + paragraphTitle, paragraphTitleFont);
    element.setLeading(12);
    paragraph.add(element);
    // chapter pour avoir la liste des signets
    final ChapterAutoNumber chapter = new ChapterAutoNumber(paragraph);
    // sans numro de chapitre
    chapter.setNumberDepth(0);
    chapter.setBookmarkOpen(false);
    chapter.setTriggerNewPage(false);
    return chapter;
}

From source file:net.bull.javamelody.internal.web.pdf.PdfJobInformationsReport.java

License:Apache License

private void addConfigurationReference() throws DocumentException {
    final Anchor quartzAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont());
    quartzAnchor.setName("Quartz configuration reference");
    quartzAnchor.setReference("http://www.quartz-scheduler.org/docs/index.html");
    quartzAnchor.setFont(PdfFonts.BLUE.getFont());
    final Paragraph quartzParagraph = new Paragraph();
    quartzParagraph.add(quartzAnchor);
    quartzParagraph.setAlignment(Element.ALIGN_RIGHT);
    addToDocument(quartzParagraph);//  w  w w  . j  av a 2s.  com
}

From source file:net.bull.javamelody.internal.web.pdf.PdfMBeansReport.java

License:Apache License

private void writeAttributes(MBeanNode mbean) throws DocumentException {
    final String description = mbean.getDescription();
    final List<MBeanAttribute> attributes = mbean.getAttributes();
    if (description != null || !attributes.isEmpty()) {
        currentTable = createAttributesTable();
        if (description != null) {
            currentTable.getDefaultCell().setColspan(3);
            addCell('(' + description + ')');
            currentTable.getDefaultCell().setColspan(1);
        }/* www . j a v a  2  s . c  o  m*/
        for (final MBeanAttribute attribute : attributes) {
            writeAttribute(attribute);
        }
        final Paragraph paragraph = new Paragraph();
        paragraph.setIndentationLeft(margin);
        paragraph.add(currentTable);
        addToDocument(paragraph);
        addText("\n");
    }
}

From source file:net.bull.javamelody.internal.web.pdf.PdfProcessInformationsReport.java

License:Apache License

private void addPsCommandReference() throws DocumentException {
    final Anchor psAnchor = new Anchor("ps command reference", PdfFonts.BLUE.getFont());
    psAnchor.setName("ps command reference");
    psAnchor.setReference("http://en.wikipedia.org/wiki/Ps_(Unix)");
    psAnchor.setFont(PdfFonts.BLUE.getFont());
    final Paragraph psParagraph = new Paragraph();
    psParagraph.add(psAnchor);
    psParagraph.setAlignment(Element.ALIGN_RIGHT);
    addToDocument(psParagraph);// w ww  .ja  v a 2 s  .  co m
}