tags:

views:

3638

answers:

3

I am using Itexthsharp for coverting html to pdf now my problem is that i m using htmlparser to convert html page to pdf but the problem is that htmlparser just convert first line to pdf all other line from html file is 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 please help me Any thank u in advance for helping

A: 

Oh i finally got the solution Instead of using htmlparser class i have now used 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();
A: 

I use

StreamReader tempReader = new StreamReader(tempFile);

        ArrayList p = HTMLWorker.ParseToList(tempReader,st); 

        for (int k = 0; k < p.Count; k++) 
        {
            documento.Add((IElement)p[k]); 
        }

        tempReader.Dispose();
        documento.Close();

and works fine too. but i put the dispose at the end

Robson Pascoal
A: 

using that code :

                    ArrayList p = HTMLWorker.ParseToList(new StreamReader(tempFile),new StyleSheet());
                for (int k = 0; k < p.Count; k++)
                {
                    document.Add((IElement)p[k]);
                }
                document.Close();

give this error :

Error 1 Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.ArrayList'

Nito