HTMLParser仅转换文件的第一行

时间:2022-10-29 19:41:29

I am using iText for .NET for converting HTML to PDF.
I'm using HtmlParser to convert an HTML page to PDF, but the problem is that Htmlparser only seems to convert the first line to pdf all other lines from the HTML file are not converted to PDF.

我使用iText for .NET将HTML转换为PDF。我正在使用HtmlParser将HTML页面转换为PDF,但问题是Htmlparser似乎只将第一行转换为pdf,HTML文件中的所有其他行都不会转换为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

所以请帮助我。任何感谢你提前帮助

3 个解决方案

#1


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

并且工作得很好。但我把处置放在最后

#2


Oh i finally got the solution Instead of using htmlparser class i have now used htmlworker class here is the new code

哦,我终于得到了解决方案而不是使用htmlparser类我现在使用的htmlworker类是新代码

ArrayList p = HTMLWorker.ParseToList(new StreamReader("fck.html"), st);
for (int k = 0; k < p.Count; k++)
{
    final.Add((IElement)p[k]);
}
final.Close();

#3


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

错误1无法将类型'System.Collections.Generic.List'隐式转换为'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);
                }

#1


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

并且工作得很好。但我把处置放在最后

#2


Oh i finally got the solution Instead of using htmlparser class i have now used htmlworker class here is the new code

哦,我终于得到了解决方案而不是使用htmlparser类我现在使用的htmlworker类是新代码

ArrayList p = HTMLWorker.ParseToList(new StreamReader("fck.html"), st);
for (int k = 0; k < p.Count; k++)
{
    final.Add((IElement)p[k]);
}
final.Close();

#3


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

错误1无法将类型'System.Collections.Generic.List'隐式转换为'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);
                }