版本: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帖子中的图片。
如果现有的自定义代码要为文本框内的每个新行添加<br/>
或Environment.NewLine
,则肯定会有所帮助。我不精于报表中的自定义代码,因此不胜感激。
答案 0 :(得分:0)
仍然没有使用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;
}
我创建的这个函数很好,但是它只是为每个<br/><br/>
长度的字符串添加n
而忽略了ignoreList
内部的标签。这仅对字符宽度相同但对我不起作用的字体有用。