我有一个问题,我想转换为PDF使用版本v5.4.0使用iTextSharp
1.命名空间'iTextSharp.text'中不存在类型或命名空间名称'html'(您是否缺少装配参考?)
2.当前上下文中不存在名称“PdfWriter”
3.当前上下文中不存在名称“HTMLWorker”
{
string fileName = "pdfDocument" + DateTime.Now.Ticks + ".pdf";
Response.Clear();
GeneratePDF("", fileName, true, "");
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.Flush();
Response.End();
}
protected void GeneratePDFAndDownload(object sender, EventArgs e)
{
string fileName = "pdfDocument" + DateTime.Now.Ticks + ".pdf";
Response.Clear();
GeneratePDF("", fileName, true, "");
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.Flush();
Response.End();
}
private void GeneratePDF(string path, string fileName, bool download, string text)
{
var document = new Document();
try
{
if (download)
{
PdfWriter.GetInstance(document, Response.OutputStream);
}
else
{
PdfWriter.GetInstance(document, new FileStream(path + fileName, FileMode.Create));
}
StringBuilder strB = new StringBuilder();
document.Open();
if (text.Length.Equals(0))
{
BindMyGrid();
using (StringWriter sWriter = new StringWriter(strB))
{
using (HtmlTextWriter htWriter = new HtmlTextWriter(sWriter))
{
istorijaKupovinaGreedView.RenderControl(htWriter);
}
}
}
else
{
strB.Append(text);
}
using (TextReader sReader = new StringReader(strB.ToString()))
{
List<IElement> list = HTMLWorker.ParseToList(sReader, new StyleSheet());
foreach (IElement elm in list)
{
document.Add(elm);
}
}
}
catch (Exception ee)
{
lblMessage.Text = ee.ToString();
}
finally
{
document.Close();
}
}
private void BindMyGrid()
{
throw new NotImplementedException();
}
}