Hi all,

According to the documentation, the leading of a paragraph depends on the font. However, when I create a paragraph using the ElementFactory, passing in a property that corresponds to the font size, the leading is not computed based on that size. Below is code that demonstrates this effect -- the third paragraph's leading is not computed based on font size. Is this a bug? A feature? How do I get around it?

My goal is to maintain a stack of attributes. So, for example, if I want some text to be italic, I copy the top of the attribute stack, add the italic attribute to it, push that onto the stack, and use that set of attributes in a new chunk. Once I'm done with the chunk, I can pop the attributes off the stack, and continue adding chunks using the previous attributes. This would be useful for processing HTML, where you could get a run of characters, followed by the italic open tag, some more characters, the italic close tag, and then more characters.

Any ideas?

Thanks,

--Rob

package sample;

import java.io.*;
import java.util.*;

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import com.lowagie.text.factories.*;

public class Sample
{
    public static void main(String[] args) throws Exception
    {
        Document pdfdoc = new Document();
        // PdfWriter.getInstance(pdfdoc, System.out);
        PdfWriter.getInstance(pdfdoc,
                new FileOutputStream("sample.pdf"));

        pdfdoc.open();

        Paragraph p1 = new Paragraph(new Chunk(
                "This is my first paragraph, font size 10.",
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        pdfdoc.add(p1);

        Paragraph p2 = new Paragraph(new Chunk(
                "This is my second paragraph, font size 50.",
                FontFactory.getFont(FontFactory.HELVETICA, 50)));
        pdfdoc.add(p2);

        Properties attrs = new Properties();

        attrs.put(ElementTags.SIZE, "50");
        Paragraph p3 = ElementFactory.getParagraph(attrs);
        Chunk c3 = ElementFactory.getChunk(attrs);
        c3.append("This is my third paragraph, also font size 50.");
        p3.add(c3);
        pdfdoc.add(p3);

        pdfdoc.close();
    }
}

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to