i want to convert my aspx page to pdf document by passing url with applied styles.....my task is when i pass url of my invoicepage.aspx which will be having datalist...labels and inline styles in the td table etc..i need to change them all to the exact format with all styles i included with that... to pdf doc....but am not able to get the desired output...could yo please help me am using "itextsharp.dll" for this.....version 5.4.3
i could not able to use Xml parser am getting compilation error i dnt knw whre am gng wrong...!! i will list my all coding here please review i will be very thank ful to u i have been stuck for weeks...."Its working but without proper alignment"
#########################################Default.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using iTextSharp.text;
using System.Net;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetWebHtmlSourceCode("http://localhost:9168/InvoicePDF.aspx");
}
public static void GetWebHtmlSourceCode(string url)
{
string Content = "";
StreamReader objStreamReader = default(StreamReader);
WebRequest objWebRequest = default(WebRequest);
WebResponse objWebResponse = default(WebResponse);
objWebResponse.ContentType = "application/pdf";
try
{
objWebRequest = WebRequest.Create(url);
objWebResponse = objWebRequest.GetResponse();
objStreamReader = new StreamReader(objWebResponse.GetResponseStream());
Content = objStreamReader.ReadToEnd();
objStreamReader.Close();
string filename = AppDomain.CurrentDomain.BaseDirectory + "Invoice.pdf";
Document document = new Document(PageSize.A4, 80, 50, 30, 65);
using (FileStream fs = new FileStream(filename, FileMode.Create))
{
PdfWriter.GetInstance(document, fs);
using (StringReader stringReader = new StringReader(Content))
{
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
HTMLWorker htmlparser = new HTMLWorker(document);
htmlparser.Parse(new StringReader(Content));
//XMLWorkerHelper i getting error "does not exist"
//so i used HTMLWorker
//XMLWorkerHelper.GetInstance().ParseXHtml(
//writer, document, html
//);
document.Close();
}
}
}
catch (Exception)
{
throw;
}
}
******************************************************************
#####################################Invoice.aspx
**************Code behind has some coding for populating the grid best on the parameters i pass with the invoice url...*******
Please help me to achieve this........
Ring ZhongPosted Sep 5, 2013, 5:39 AM