Error in pdf report creation

Posted by Klbaiju under jQuery on 1/9/2015 | Points: 10 | Views : 1282 | Status : [Member] | Replies : 1
Hi,

in my application iam using pdf report.

i wrote the code in button's click event .and it is working fine.

my requirement is to convert it into jquery ajax method like this
$('#btnreport').click(function (e) {
e.preventDefault();
var tid = $('#HiddenField2').val();
var bookedby = $('#txtebooked').val();
var source = $('#txtesource').val();
var destination = $('#txtedestination').val();
var vals = $('#HiddenField3').val();
var tdates = vals.split('-');

var tdate = tdates[1] + '-' + tdates[2] + '-' + tdates[3];
// var tdate = $('#tid').val();
var fare = $('#txtefare').val();
var advance = $('#txteadvance').val();
alert(fare);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Busdetails.aspx/PrintReport",
data: "{tid:'" + tid + "',bookedby:'" + bookedby + "',source:'" + source + "',destination:'" + destination + "',tdate:'" + tdate + "',fare:'" + fare + "',advance:'" + advance + "'}",
dataType: "json",
success: function (data) {
alert(data.d);

}
});

[WebMethod]
public static string PrintReport(string tid,string bookedby,string source, string destination,string tdate,string fare,string advance)
{
var document = new Document(PageSize.A4, 50, 50, 25, 25);
string msg=string.Empty;
// Create a new PdfWrite object, writing the output to a MemoryStream
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(document, output);
if (fare != "0" && advance != "0")
{
// Open the Document for writing
document.Open();
// Read in the contents of the Receipt.htm HTML template file
string contents = File.ReadAllText(HttpContext.Current.Server.MapPath("~/HTMLTemplate/Receipt.htm"));

// Replace the placeholders with the user-specified text
contents = contents.Replace("[lblid]", tid);
contents = contents.Replace("[lbname]", bookedby);
contents = contents.Replace("[lbsource]", source);
contents = contents.Replace("[lbdest]", destination);
contents = contents.Replace("[lbtourdate]", tdate);
contents = contents.Replace("[lbfare]", fare);
contents = contents.Replace("[lbadvance]", advance);
contents = contents.Replace("[lbdate]", DateTime.Now.ToShortDateString());



var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null);
foreach (var htmlElement in parsedHtmlElements)
document.Add(htmlElement as IElement);



// You can add additional elements to the document. Let's add an image in the upper right corner
var logo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/Images/lakshmi-1.gif"));
logo.SetAbsolutePosition(310, 750);
document.Add(logo);

document.Close();

System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", string.Forma




Responses

Posted by: Vuyiswamb on: 1/12/2015 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
What is your problem ?

Thank you for posting at Dotnetfunda
[Administrator]

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response