在用PDF编写时以字符串格式退格 [英] Backspace in string formatting while writing in PDF

查看:69
本文介绍了在用PDF编写时以字符串格式退格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用PDF打印两列信息,其中包含用户输入的一些字符串。这是我到目前为止的代码:

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 = "";                                                                  
s = s + string.Format("{0,-60}", "Name: " + name);
s = s + string.Format("{0,15}","AAA: ");
p1.Add(s);
document.Add(p1);

string p = "";                                                                 
p = p + string.Format("{0,-60}", "Surname: " + surname);
p = p + string.Format("{0,15}","BBB: ");
p2.Add(p);
document.Add(p2);

string r = "";                                                        
r = r + string.Format("{0,-60}", "School: " + school);
r = r + string.Format("{0,15}","CCC: ");
p3.Add(r);
document.Add(p3);



如果用户输入,例如John Edward Jr.为了名字,Pascal Einstein W. Alfi为姓氏,圣约翰为学校,然后预期的输出是这样的:



姓名:John Edward Jr .________________ AAA:



姓:Pascal Einstein W. Alfi_______BBB:



学校:圣约翰____________________CCC:

我想每个字符串名称,姓氏和学校的空格都是问题所在。我怎么处理这个?



预期产量:



姓名:John Edward Jr ._________________ AAA:



姓:Pascal Einstein W. Alfi_______BBB:



学校:圣约翰________________________ CCC:


If the user enters, for example, "John Edward Jr." for name, "Pascal Einstein W. Alfi" for surname and "St. John" for school, then the expected output is something like this:

Name: John Edward Jr.________________AAA:

Surname: Pascal Einstein W. Alfi_______BBB:

School: St. John___________________CCC:
I suppose the spaces in every string name, surname and school are the problem. How can I deal with this?

EXPECTED OUTPUT:

Name: John Edward Jr._________________AAA:

Surname: Pascal Einstein W. Alfi_______BBB:

School: St. John________________________CCC:

推荐答案

如果您使用的是固定宽度字体,则只需使用每个字符串的长度来计算所需的空格数。如果您使用的是可变宽度字体,则需要使用图形绘制方法将每个字段定位在页面上的特定点。
If you are using a fixed width font, then you just need to use the length of each string to calculate the number of spaces required. If you are using variable width fonts than you need to use graphics draw methods to position each field at a specific point on the page.


这篇关于在用PDF编写时以字符串格式退格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆