Backspace in string formatting while printing to PDF

前端 未结 3 1528
刺人心
刺人心 2021-01-20 04:54

I\'m trying to print in PDF two columns of information that contain some strings that the user inputs. This is my code so far:

string s = \"\";
int width = 6         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-20 05:35

    The issue is the spacing key you use when printing to PDF. Simply use non-breaking spaces instead (press Alt+<255>) or you can convert your spaces with the below code:

    string s = " ";
    if(s == " ")
    {
     s = " "
    }
    

    OR

    use "My name is this".Replace(" ", " ");

    Update 2

    Since you are using iText# you can you the API to insert spaces by doing for example:

    iTextSharp.text.Paragraph s = new iTextSharp.text.Paragraph(name, font);
    s.SpacingAfter = 20;
    s.Add("AAA: ");
    

    Please let me know if my answer support your question.

提交回复
热议问题