Adersh Ram
Привет ,
Этот образец поможет вам.
//saving HTML as PDF locally and then opening
Document document = new Document();
string filename = Path.GetTempPath() + "MyFiles.pdf";
StringBuilder strSelectUserListBuilder = new StringBuilder();
// strSelectUserListBuilder.Append("<table border="2" width="300" cellspacing="1" cellpadding="1" bgcolor="#DD00AA"><tr rowspan="2"><td>TEST1</td><td rowspan="2">TEST2</td></tr><tr><td>TEST3</td><td>TEST4</td></tr><tr><td>TEST5</td><td>TEST6</td></tr></table>");
strSelectUserListBuilder.Append("<h1>This is my test PDF sample</h1><table border="1" bgcolor="#CCCE0E"> <tr> <td colspan="2">my table</td> </tr> <tr> <td>my table</td> <td>my table</td> </tr> <tr> <td>200</td> <td>100</td> </tr> <tr> <td>500</td> <td>100</td> </tr> <tr> <td>700</td> <td>500</td> </tr></table>");
//writer - have our own path!!! and see you have write permissions...
PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create));
document.Open();
//Here is where your HTML source goes................
String htmlText = strSelectUserListBuilder.ToString();
//make an arraylist ....with STRINGREADER since its no IO reading file...
ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null);
//add the collection to the document
for (int k = 0; k < htmlarraylist.Count; k++)
{
document.Add((IElement)htmlarraylist[k]);
}
document.Close();
WebClient myWeb = new WebClient();
Byte[] myBuff = myWeb.DownloadData(filename);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", myBuff.Length.ToString());
Response.BinaryWrite(myBuff);
Response.Flush();
Response.Close();