RDLC 文本框行 Height/Line 间距
RDLC Textbox Line Height/Line Spacing
版本:http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition
我一直在网上寻找有关如何在 RDLC 文本框中添加行高或行间距的答案,但无济于事。
我也试过 <p style="line-height: 1.5;">
但导出为 PDF 时它不起作用。为了仔细检查这一点,我创建了一个简单的 html 文件,并使用这种样式实现了我想要的效果。
无论如何,我的文本框的内容是动态的,所以它的长度可以改变。如果这是固定行,那么我会根据需要简单地添加 <br/>
或 Environment.NewLine
。
文本框:
HTML - 将 HTML 标签解释为样式
=Parameters!DatePrinted.Value & "<br /><br /><br /><br /><br /><br />" &
"This is to certify that <b>" & UCase(Parameters!Name.Value) & "</b> is currently enrolled in the <b>" & Parameters!CurrentTerm.Value & "</b> trimester of School Year <b>" & Parameters!CurrentSchoolYear.Value & "</b> in the <b>" & Parameters!DegreeProgram.Value & "</b> degree program at the best school in the universe. S/He was admitted into the College on the <b>" & Parameters!FirstTerm.Value & "</b> trimester of School Year <b>" & Parameters!FirstSchoolYear.Value & "</b>."
& "<br /><br /><br />" &
"This certification is being issued upon the request of <b>" & Parameters!Name.Value & "</b> for <b>" & Parameters!SpecificPurpose.Value & "</b>."
& "<br /><br /><br /><br /><br /><br />" &
"<b>Some Name</b>"
& "<br />" &
"Position"
我试过了..
=Parameters!DatePrinted.Value & "<br /><br /><br /><br /><br /><br />" &
"<p style='line-height: 1.5;'>" &
"This is to certify that <b>" & UCase(Parameters!Name.Value) & "</b> is currently enrolled in the <b>" & Parameters!CurrentTerm.Value & "</b> trimester of School Year <b>" & Parameters!CurrentSchoolYear.Value & "</b> in the <b>" & Parameters!DegreeProgram.Value & "</b> degree program at the best school in the universe. S/He was admitted into the College on the <b>" & Parameters!FirstTerm.Value & "</b> trimester of School Year <b>" & Parameters!FirstSchoolYear.Value & "</b>."
& "</p>"
& "<br /><br /><br />" &
"<p style='line-height: 1.5;'>" &
"This certification is being issued upon the request of <b>" & Parameters!Name.Value & "</b> for <b>" & Parameters!SpecificPurpose.Value & "</b>."
& "</p>"
& "<br /><br /><br /><br /><br /><br />" &
"<b>Some Name</b>"
& "<br />" &
"Position"
当前输出:
与"<p style='line-height: 1.5;'>"
:
预期输出:
请忽略预期输出中的缩进。我重新使用了 Line Height in SSRS post.
中的图像
如果现有自定义代码可以为文本框中的每一行添加 <br/>
或 Environment.NewLine
,那么它肯定会有所帮助。我不熟悉报告中的自定义代码,所以我将不胜感激。
仍然没有使用 RDLC 或 SSRS 的直接解决方案。我改为使用 iTextSharp 并且很容易满足我的要求。
FontFactory.RegisterDirectories();
Font tnr = FontFactory.GetFont("Times New Roman", 12f, Font.NORMAL, BaseColor.BLACK);
Font tnr_bold = FontFactory.GetFont("Times New Roman", 12f, Font.BOLD, BaseColor.BLACK);
Font tnr_italic = FontFactory.GetFont("Times New Roman", 12f, Font.ITALIC, BaseColor.BLACK);
List<IElement> elements = new List<IElement>();
Paragraph p1 = new Paragraph(FormatUtility.FormatDate3(DateTime.Now), tnr);
p1.SetLeading(0f, 2f); // This is the line height/line spacing
elements.Add(p1);
elements.Add(Chunk.NEWLINE);
elements.Add(Chunk.NEWLINE);
Paragraph p2 = new Paragraph();
p2.SetLeading(0f, 2f); // This is the line height/line spacing
p2.Add(new Chunk("This is to certify that ", tnr));
p2.Add(new Chunk(name.ToUpper(), tnr_bold));
p2.Add(new Chunk(" is currently enrolled in the ", tnr));
.
.
.
p2.Add(new Chunk(" trimester of School Year ", tnr));
p2.Add(new Chunk(currentSchoolYearTxt, tnr_bold));
p2.Add(new Chunk(" in the ", tnr));
p2.Add(new Chunk(degreeProgram, tnr_bold));
p2.Add(new Chunk(" degree program at the best school in the universe. S/He was admitted into the College on ", tnr));
.
.
.
p2.Add(new Chunk(" trimester of School Year ", tnr));
p2.Add(new Chunk(firstSchoolYearTxt, tnr_bold));
p2.Add(new Chunk(".", tnr));
elements.Add(p2);
elements.Add(Chunk.NEWLINE);
Paragraph p3 = new Paragraph();
p3.SetLeading(0f, 2f); // This is the line height/line spacing
p3.Add(new Chunk("This certification is being issued upon the request of ", tnr));
p3.Add(new Chunk(name, tnr_bold));
p3.Add(new Chunk(" for ", tnr));
p3.Add(new Chunk(specificPurpose, tnr_bold));
p3.Add(new Chunk(".", tnr));
elements.Add(p3);
elements.Add(Chunk.NEWLINE);
elements.Add(Chunk.NEWLINE);
elements.Add(new Paragraph("Someone Name", tnr_bold));
elements.Add(new Paragraph("Position", tnr));
byte[] renderedBytes = CreatePDF(PageSize.LETTER, elements, 72f, 72f, 216f, 72f);
和
private byte[] CreatePDF(Rectangle pageSize, IList<IElement> elements, float marginLeft = 0f, float marginRight = 0f, float marginTop = 0f, float marginBottom = 0f)
{
byte[] renderedBytes = null;
using (MemoryStream ms = new MemoryStream())
{
// Margins: 72f = 1 inch
using (Document document = new Document(pageSize, marginLeft, marginRight, marginTop, marginBottom))
{
PdfWriter pdf = PdfWriter.GetInstance(document, ms);
document.Open();
foreach (IElement element in elements)
{
document.Add(element);
}
document.Close();
renderedBytes = ms.ToArray();
return renderedBytes;
}
}
}
我使用以下方法几乎在 RDLC 上实现了类似的效果:
string content = "Date <br/><br/><br/><br/><br/> This is to certify that <b>(NAME)</b> is currently enrolled in the <b>(CurrentTerm)</b> trimester of School Year <b>(CurrentSY)</b> in the <b>(Degree Program)</b> degree program at the best school in the universe. S/He was admitted into the College on <b>(FirstTerm)</b> trimester of School Year <b>(FirstSY)</b>. <br/><br/><br/> This certification is being issued upon the request of <b>(Name)</b> for <b>(specific purpose/s)</b>. <br/><br/><br/><br/><br/> <b>Some Name</b> <br/> Position";
content = content
.Replace("(NAME)", name.ToUpper()); // Replace necessary strings with variable values
content = SplitByBreak(content, 85);
和
public static string SplitByBreak(string text, int length)
{
List<string> ignoreList = new List<string>()
{
"<b>",
"</b>",
"<i>",
"</i>"
};
string br = "<br/>";
string newText = string.Empty;
string newLine = string.Empty;
// Make sure that <br/> is the standard break.
text = text.Replace("<br>", br);
string[] split = text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < split.Length; i++)
{
string testLine = string.Format("{0} {1}", newLine, split[i]).Trim();
string temp = testLine;
int lastIndexBr = testLine.LastIndexOf(br);
// Count from the last index of <br/>.
if (lastIndexBr >= 0)
{
temp = temp.Substring(lastIndexBr + br.Length);
}
// Do not include the length from the ignore list. -Eph 10.19.2018
foreach (string s in ignoreList)
{
temp = temp.Replace(s, string.Empty);
}
if (temp.Length > length)
{
newText = string.Format("{0} {1} {2}{2}", newText, newLine, br).Trim();
newLine = split[i];
}
else
{
testLine = string.Format("{0} {1}", newLine, split[i]).Trim();
newLine = testLine;
}
}
newText = string.Format("{0} {1}", newText, newLine).Trim();
return newText;
}
我创建的这个函数很好,但它只是为每个长度为 n
的字符串添加 <br/><br/>
,同时忽略 ignoreList
内的标签。这仅对具有相同字符宽度的字体有用,这对我不起作用。
版本:http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition
我一直在网上寻找有关如何在 RDLC 文本框中添加行高或行间距的答案,但无济于事。
我也试过 <p style="line-height: 1.5;">
但导出为 PDF 时它不起作用。为了仔细检查这一点,我创建了一个简单的 html 文件,并使用这种样式实现了我想要的效果。
无论如何,我的文本框的内容是动态的,所以它的长度可以改变。如果这是固定行,那么我会根据需要简单地添加 <br/>
或 Environment.NewLine
。
文本框:
HTML - 将 HTML 标签解释为样式
=Parameters!DatePrinted.Value & "<br /><br /><br /><br /><br /><br />" &
"This is to certify that <b>" & UCase(Parameters!Name.Value) & "</b> is currently enrolled in the <b>" & Parameters!CurrentTerm.Value & "</b> trimester of School Year <b>" & Parameters!CurrentSchoolYear.Value & "</b> in the <b>" & Parameters!DegreeProgram.Value & "</b> degree program at the best school in the universe. S/He was admitted into the College on the <b>" & Parameters!FirstTerm.Value & "</b> trimester of School Year <b>" & Parameters!FirstSchoolYear.Value & "</b>."
& "<br /><br /><br />" &
"This certification is being issued upon the request of <b>" & Parameters!Name.Value & "</b> for <b>" & Parameters!SpecificPurpose.Value & "</b>."
& "<br /><br /><br /><br /><br /><br />" &
"<b>Some Name</b>"
& "<br />" &
"Position"
我试过了..
=Parameters!DatePrinted.Value & "<br /><br /><br /><br /><br /><br />" &
"<p style='line-height: 1.5;'>" &
"This is to certify that <b>" & UCase(Parameters!Name.Value) & "</b> is currently enrolled in the <b>" & Parameters!CurrentTerm.Value & "</b> trimester of School Year <b>" & Parameters!CurrentSchoolYear.Value & "</b> in the <b>" & Parameters!DegreeProgram.Value & "</b> degree program at the best school in the universe. S/He was admitted into the College on the <b>" & Parameters!FirstTerm.Value & "</b> trimester of School Year <b>" & Parameters!FirstSchoolYear.Value & "</b>."
& "</p>"
& "<br /><br /><br />" &
"<p style='line-height: 1.5;'>" &
"This certification is being issued upon the request of <b>" & Parameters!Name.Value & "</b> for <b>" & Parameters!SpecificPurpose.Value & "</b>."
& "</p>"
& "<br /><br /><br /><br /><br /><br />" &
"<b>Some Name</b>"
& "<br />" &
"Position"
当前输出:
与"<p style='line-height: 1.5;'>"
:
预期输出:
请忽略预期输出中的缩进。我重新使用了 Line Height in SSRS post.
中的图像如果现有自定义代码可以为文本框中的每一行添加 <br/>
或 Environment.NewLine
,那么它肯定会有所帮助。我不熟悉报告中的自定义代码,所以我将不胜感激。
仍然没有使用 RDLC 或 SSRS 的直接解决方案。我改为使用 iTextSharp 并且很容易满足我的要求。
FontFactory.RegisterDirectories();
Font tnr = FontFactory.GetFont("Times New Roman", 12f, Font.NORMAL, BaseColor.BLACK);
Font tnr_bold = FontFactory.GetFont("Times New Roman", 12f, Font.BOLD, BaseColor.BLACK);
Font tnr_italic = FontFactory.GetFont("Times New Roman", 12f, Font.ITALIC, BaseColor.BLACK);
List<IElement> elements = new List<IElement>();
Paragraph p1 = new Paragraph(FormatUtility.FormatDate3(DateTime.Now), tnr);
p1.SetLeading(0f, 2f); // This is the line height/line spacing
elements.Add(p1);
elements.Add(Chunk.NEWLINE);
elements.Add(Chunk.NEWLINE);
Paragraph p2 = new Paragraph();
p2.SetLeading(0f, 2f); // This is the line height/line spacing
p2.Add(new Chunk("This is to certify that ", tnr));
p2.Add(new Chunk(name.ToUpper(), tnr_bold));
p2.Add(new Chunk(" is currently enrolled in the ", tnr));
.
.
.
p2.Add(new Chunk(" trimester of School Year ", tnr));
p2.Add(new Chunk(currentSchoolYearTxt, tnr_bold));
p2.Add(new Chunk(" in the ", tnr));
p2.Add(new Chunk(degreeProgram, tnr_bold));
p2.Add(new Chunk(" degree program at the best school in the universe. S/He was admitted into the College on ", tnr));
.
.
.
p2.Add(new Chunk(" trimester of School Year ", tnr));
p2.Add(new Chunk(firstSchoolYearTxt, tnr_bold));
p2.Add(new Chunk(".", tnr));
elements.Add(p2);
elements.Add(Chunk.NEWLINE);
Paragraph p3 = new Paragraph();
p3.SetLeading(0f, 2f); // This is the line height/line spacing
p3.Add(new Chunk("This certification is being issued upon the request of ", tnr));
p3.Add(new Chunk(name, tnr_bold));
p3.Add(new Chunk(" for ", tnr));
p3.Add(new Chunk(specificPurpose, tnr_bold));
p3.Add(new Chunk(".", tnr));
elements.Add(p3);
elements.Add(Chunk.NEWLINE);
elements.Add(Chunk.NEWLINE);
elements.Add(new Paragraph("Someone Name", tnr_bold));
elements.Add(new Paragraph("Position", tnr));
byte[] renderedBytes = CreatePDF(PageSize.LETTER, elements, 72f, 72f, 216f, 72f);
和
private byte[] CreatePDF(Rectangle pageSize, IList<IElement> elements, float marginLeft = 0f, float marginRight = 0f, float marginTop = 0f, float marginBottom = 0f)
{
byte[] renderedBytes = null;
using (MemoryStream ms = new MemoryStream())
{
// Margins: 72f = 1 inch
using (Document document = new Document(pageSize, marginLeft, marginRight, marginTop, marginBottom))
{
PdfWriter pdf = PdfWriter.GetInstance(document, ms);
document.Open();
foreach (IElement element in elements)
{
document.Add(element);
}
document.Close();
renderedBytes = ms.ToArray();
return renderedBytes;
}
}
}
我使用以下方法几乎在 RDLC 上实现了类似的效果:
string content = "Date <br/><br/><br/><br/><br/> This is to certify that <b>(NAME)</b> is currently enrolled in the <b>(CurrentTerm)</b> trimester of School Year <b>(CurrentSY)</b> in the <b>(Degree Program)</b> degree program at the best school in the universe. S/He was admitted into the College on <b>(FirstTerm)</b> trimester of School Year <b>(FirstSY)</b>. <br/><br/><br/> This certification is being issued upon the request of <b>(Name)</b> for <b>(specific purpose/s)</b>. <br/><br/><br/><br/><br/> <b>Some Name</b> <br/> Position";
content = content
.Replace("(NAME)", name.ToUpper()); // Replace necessary strings with variable values
content = SplitByBreak(content, 85);
和
public static string SplitByBreak(string text, int length)
{
List<string> ignoreList = new List<string>()
{
"<b>",
"</b>",
"<i>",
"</i>"
};
string br = "<br/>";
string newText = string.Empty;
string newLine = string.Empty;
// Make sure that <br/> is the standard break.
text = text.Replace("<br>", br);
string[] split = text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < split.Length; i++)
{
string testLine = string.Format("{0} {1}", newLine, split[i]).Trim();
string temp = testLine;
int lastIndexBr = testLine.LastIndexOf(br);
// Count from the last index of <br/>.
if (lastIndexBr >= 0)
{
temp = temp.Substring(lastIndexBr + br.Length);
}
// Do not include the length from the ignore list. -Eph 10.19.2018
foreach (string s in ignoreList)
{
temp = temp.Replace(s, string.Empty);
}
if (temp.Length > length)
{
newText = string.Format("{0} {1} {2}{2}", newText, newLine, br).Trim();
newLine = split[i];
}
else
{
testLine = string.Format("{0} {1}", newLine, split[i]).Trim();
newLine = testLine;
}
}
newText = string.Format("{0} {1}", newText, newLine).Trim();
return newText;
}
我创建的这个函数很好,但它只是为每个长度为 n
的字符串添加 <br/><br/>
,同时忽略 ignoreList
内的标签。这仅对具有相同字符宽度的字体有用,这对我不起作用。