HTMLParser converts only the first line of the file
I am using iText for .NET to convert HTML to PDF.
I am using HtmlParser to convert HTML page to PDF, but the problem is that Htmlparser only converts the first line to pdf, all other lines from the HTML file are not converted to PDF.
Here is the code
Document document = new Document();
final = new Document();
StreamWriter writer = new StreamWriter("fck.txt");
writer.WriteLine(FCKeditor1.Value);
writer.Close();
// Changing the extension of txt file to html file
File.Move("C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\fck.txt", "C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\fck.html");
PdfWriter writer1 = PdfWriter.GetInstance(final, new FileStream("final1.pdf", FileMode.Create));
final.Open();
HtmlParser.Parse(final, "fck.html");
final.Close();
File.Delete("C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\fck.html");
So please help me Any thanks in advance for the help
+1
Mehul Thakkar
source
to share
3 answers
Oh I finally got the solution Instead of using the htmlparser class I now used the htmlworker class here is the new code
ArrayList p = HTMLWorker.ParseToList(new StreamReader("fck.html"), st);
for (int k = 0; k < p.Count; k++)
{
final.Add((IElement)p[k]);
}
final.Close();
+1
Mehul Thakkar
source
to share
Error 1 Unable to implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.ArrayList'
Use it like this:
List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile),new StyleSheet());
foreach (IElement element in htmlarraylist)
{
document.Add(element);
}
0
source to share