I have a problem I want to convert to PDF From using iTextSharp using version v5.4.0
1.The type or namespace name 'html' does not exist in the namespace 'iTextSharp.text' (are you missing an assembly reference?)
2.The name 'PdfWriter' does not exist in the current context
3.The name 'HTMLWorker' does not exist in the current context
{
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();
}
}