简体   繁体   中英

How to go to next line after certain width ItextSharp c#?

i'm working on small desktop level windows application, i'm trying to build a resume using user's data and write into a pdf file.

in pdf i need to have new line after some width of text.

 BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.BOLD); //Font.normal for normal...

        Paragraph p1 = new Paragraph(new Chunk("ASHUTOSH ANIL KALE", font));
        p1.Alignment = Element.ALIGN_CENTER;
        doc.Add(p1);

        BaseFont bf2 = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
        iTextSharp.text.Font font2 = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL);
        Paragraph p2 = new Paragraph(new Chunk("F-6 chaiyana-sagar apartment,road no-7, gulmohar colony,south shivaji nagar, sangli mahrashra, India ", font2));
        p2.Alignment = Element.ALIGN_CENTER;

        doc.Add(p2);

for the above code i'm getting this output

在此处输入图片说明

But i need in this format, what should to go next line after few width

在此处输入图片说明

all you need to do is to split that word by (",") and then add new line or new paragraph for remaining words

you can simply add new line like this

document.Add(new Chunk("\n"));

or you can try like this

doc.Add(new Paragraph(" "));

//just give a space between (" ") and it will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM