Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<html>
<body>
<table>
        <tr>        
            <td colspan="2" style="text-align:center; font-size:80; font-family:Verdana; font-weight:bold;border:1px solid Black;">
                &nbsp;</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>
Posted
Updated 23-Nov-16 20:45pm
v4
Comments
Member 12427895 7-Nov-16 23:51pm    
Maybe it is useful to mention, it uses iTextSharp, a .NET PDF library for creating the PDF file (from this HTMl fle)

no need of <.![CDATA[
and function extract() should be
function extract() {
var str=[RoomName]; return str.substring(0, str.lastIndexOf("["));

1 solution

C#
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;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900