is it possible to generate the pdf dynamically using iTextSharp and view it in a new window through a Json call?
views:
68answers:
2
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
2010-06-22 13:55:46
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
2010-06-22 14:00:03
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
2010-06-22 14:58:10
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
2010-06-22 15:01:37
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
2010-06-22 15:08:40