Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将Html转换为PDF文件并在C中使用iTextSharp保存#_C#_Asp.net - Fatal编程技术网

C# 如何将Html转换为PDF文件并在C中使用iTextSharp保存#

C# 如何将Html转换为PDF文件并在C中使用iTextSharp保存#,c#,asp.net,C#,Asp.net,我不知道怎么做,但你可以试试这个: 我不知道从哪里可以调用html文件?请澄清问题。你的问题是什么,错误日志,到目前为止的努力…没有显示错误。我已经在上面的代码中附加了一个html页面。现在我必须将其转换为pdf文件,并在执行exe时自动将该文件保存到驱动器中。 #region convert HTML To PDF static public void HTMLToPdf(string Contents, string FilePath, string strValue)

我不知道怎么做,但你可以试试这个:


我不知道从哪里可以调用html文件?请澄清问题。你的问题是什么,错误日志,到目前为止的努力…没有显示错误。我已经在上面的代码中附加了一个html页面。现在我必须将其转换为pdf文件,并在执行exe时自动将该文件保存到驱动器中。
    #region convert HTML To PDF
    static public void HTMLToPdf(string Contents, string FilePath, string strValue)
    {

        Document document = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

        //PDF for compliance overdue report.
        if (strValue == "due")
        {

            PdfWriter.GetInstance(document, new FileStream(FilePath,FileMode.Create));
        }
        //PDF for other compliance reports.
        else
        {

            PdfWriter.GetInstance(document, new FileStream(FilePath, FileMode.Create));
        }
        document.Open();
        iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);

        hw.Parse(new StringReader(Contents));

        document.Close();
    }
    #endregion