Changing text line spacing

↘锁芯ラ 提交于 2019-11-27 14:03:10

According to the PDF specification, the distance between the baseline of two lines is called the leading. In iText, the default leading is 1.5 times the size of the font. For instance: the default font size is 12 pt, hence the default leading is 18.

You can change the leading of a Paragraph by using one of the other constructors. See for instance: public Paragraph(float leading, String string, Font font)

You can also change the leading using one of the methods that sets the leading:

paragraph.SetLeading(fixed, multiplied);

The first parameter is the fixed leading: if you want a leading of 15 no matter which font size is used, you can choose fixed = 15 and multiplied = 0.

The second parameter is a factor: for instance if you want the leading to be twice the font size, you can choose fixed = 0 and multiplied = 2. In this case, the leading for a paragraph with font size 12 will be 24, for a font size 10, it will be 20, and son on.

You can also combine fixed and multiplied leading.

    private static Paragraph addSpace(int size = 1)
    {

        Font LineBreak = FontFactory.GetFont("Arial", size);      
        Paragraph paragraph = new Paragraph("\n\n", LineBreak);
        return paragraph;

    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!