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