tags:

views:

68

answers:

2

is it possible to generate the pdf dynamically using iTextSharp and view it in a new window through a Json call?

A: 

There is no advantage in doing this with Json unless the JSON request is going to do some checking or testing. I suggest to create a special HttpHandler which upon receiving a request, generates the PDF and returns it back to the browser. This way you can have a hyperlink which will open a new window and shows the pdf in it:

<a href="link to the handler" target="_blank">Open PDF</a>
Am
A: 

Why do you want to use Json? I think there is an easiest way. Ex:

<%= Html.ActionLink("View pdf","GeneratePdf","YourController" new{}, new{target="_blank"}) %>

In your controller

public ActionResult GeneratePdf()
{
     Document pdfDocument = new Document();
     MemoryStream stream = new MemoryStream();
     PdfWriter.GetInstance(pdfDocument,stream); 
     //add some code to generate your pdf content
     pdfDocument.Close();
     return new FileResult(stream,"application/pdf");
}
Gregoire
actually there are around 25 parameters being passed via json call to the server. based on those values a report has to be generated. if i go for an actionlink, all those params will be displayed in the url. is tht rite? plz suggest..
vinay
You can use Html.BeginForm instead of actionlink and pass your aprameters as hidden input. Or make a jquery ajax request with your parameters.
Gregoire
will making a $.getJSON() request be able to pop up the pdf in a new window? if yes, could you please share more info on this..
vinay