HTMLParser 只转换文件的第一行

发布于 2024-07-19 08:07:09 字数 924 浏览 5 评论 0原文

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

这是代码

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");

所以请帮助我 提前感谢您的帮助

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

彻夜缠绵 2024-07-26 08:07:09

我使用

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();

并且效果也很好。 但我把处理放在最后

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

随心而道 2024-07-26 08:07:09

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

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

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();
满身野味 2024-07-26 08:07:09

错误 1 ​​无法隐式转换类型
'System.Collections.Generic.List' 到
'System.Collections.ArrayList'

像这样使用它:

List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StreamReader(tempFile),new StyleSheet());
                foreach (IElement element in htmlarraylist)
                {
                    document.Add(element);
                }

Error 1 Cannot 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);
                }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文