字符串操作& PDF输出文件 [英] String manipulation & PDF output file
问题描述
首先,谢谢你试图帮助我。它应该很简单(我想我只是遗漏了一些东西)
我有一个htm文件用于生成pdf文件并从屏幕选择中获取日期
它是关于字符串操作(从字符串中提取以[开头并显示结果的子字符串)
示例而不是Van5 [15]它应该显示范
(注意:[RoomName],[ClassName]的数据是来自前一个屏幕的变量)
代码是正确的,并在jsfiddle.net上验证。问题是,它用于创建PDF输出文件的HTM文件显示在脚本标记之间的内容;
函数extract()
{
var str =Van5 [14];
返回str.substring(0,str.lastIndexOf([));
}
document.getElementById(demo)。innerHTML = extract();
我的问题是,如何在PDF文件上显示此功能的结果(Van5),而不是标签之间的内容
我尝试过:
First of all, thank you for trying to help me. It should be simple (I think I am only missing something)
I have a htm file that it’s used to produce a pdf file and gets date from a screen selection
It is about string manipulation (extraction a substring that starts with "[" from a string and displaying the result )
Example instead of Van5[15] it’s supposed to display Van
(Note: data for [RoomName], [ClassName]are variables that comes from a previous screen)
The code is correct and verified on jsfiddle.net . The problem is, this HTM file that it is used to create the PDF output file displays on top the content between script tags;
function extract()
{
var str = "Van5 [14]";
return str.substring(0, str.lastIndexOf("["));
}
document.getElementById("demo").innerHTML = extract();
My question is, how to display the result(Van5) of this function on PDF file, not the content between tags
What I have tried:
<html>
<body>
<table>
<tr>
<td colspan="2" style="text-align:center; font-size:80; font-family:Verdana; font-weight:bold;border:1px solid Black;">
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center; font-size:60; font-family:Verdana; font-weight:bold;border:1px solid Black;">
[RoomName]
<p id="demo"></p>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center; font-size:29;font-family:Verdana;font-weight:bold;border:1px solid Black;">
[ClassName]
</td>
</tr>
</table>
<script>
function extract() {
var str = "Van5 [14]";
return str.substring(0, str.lastIndexOf("["));
}
document.getElementById("demo").innerHTML = extract();
</script>
</body>
</html>
推荐答案
I solve this task by myself. I just added the code between comments(//Remove square brackets..//) to the .cs file. For anyone that might need help with this topic, I am adding the code snippet here:
if (ReportList.Count > 0)
{
PdfWriter writer = PdfWriter.GetInstance(Report, new FileStream(FullPath, FileMode.Create));
Report.Open();
try
{
if (ListRoomSign.Count > 0)
{
foreach (var ObjReportList in ReportList)
{
foreach (var ObjRoomSignList in ListRoomSign)
{.....
string contents = System.IO.File.ReadAllText(HTMLFilePath);
//Remove square brackets value from room name when printing room signs
if (ObjReportList.Location.Contains("["))
{
ObjReportList.Location = ObjReportList.Location.ToString().Substring(0, ObjReportList.Location.ToString().LastIndexOf("["));
}
//
contents = contents.Replace("[RoomName]", ObjReportList.Location);
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null);
foreach (var htmlElement in parsedHtmlElements)
{
Report.Add(htmlElement as IElement);
}
Report.NewPage();
}
}
}
Report.Close();
}
catch (Exception)
{
FullPath = string.Empty;
}
}
return FullPath;
这篇关于字符串操作& PDF输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!