3

I am doing ajax POST as:

$.ajax({
    type: 'POST',
    url: rootUrl("Home/PrintInvoice/12"),
    success: function (result) {
        $("#TestInvoicePrint").empty();
        $("#TestInvoicePrint").html(result);
        window.open(result);
    }
});

Where I am getting PDF file in result from MVC action as,

public ActionResult PrintInvoice(long ID)
{
    var data = db.Documents.Where(x => x.InvoiceNumber == ID);
    ReportDocument rd = new ReportDocument();
    rd.Load(Server.MapPath("~/Reports/InvoiceDocument.rpt"));
    ConnectionInfo ConnInfo = new ConnectionInfo { ServerName = "10.0.0.154,1433\\sqlexpress", UserID = "CueReader", Password = "CueReader@123", DatabaseName = "Cue" };

    ParameterFieldDefinitions parmFields = rd.DataDefinition.ParameterFields;
    ParameterValues pvals = new ParameterValues();

    rd.ParameterFields["DocumentID"].CurrentValues.IsNoValue = true;

    Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    stream.Seek(0, SeekOrigin.Begin);

    return new FileStreamResult(stream, "application/pdf");              
}

How can I use the PDF file into my DOM Element from ajax POST?

OptimizedQuery
  • 1,262
  • 11
  • 21
Rahul
  • 2,309
  • 6
  • 33
  • 60
  • You can just do it as HTTP get. `window.open(rootUrl("Home/PrintInvoice/12"))`. Use OutputCacheAttribute to prevent caching if desired. – LostInComputer Jan 30 '14 at 08:02
  • Seems similar to this question: http://stackoverflow.com/questions/9840230/how-to-display-a-pdf-stream-in-a-browser-using-javascript – ppoliani Jan 31 '14 at 16:21
  • Can you clarify how you want to use the PDF in your dom? AFAIK, if you want to show the PDF, you'll need to embed a reader control. You may find this thread useful: http://stackoverflow.com/questions/291813/recommended-way-to-embed-pdf-in-html – kiprainey Feb 01 '14 at 23:55
  • Check http://pdfobject.com/ – crazybert Feb 05 '14 at 07:27
  • rather then return the filestreamresult save it somewhere in the folder then return the filename.pdf . then use it var iframe = $(' – Rahul Kumar Feb 05 '14 at 15:23

1 Answers1

0

it would be better if you could have the ajax give you a url (dynamic?) and then update an object data= attribute

DrogoNevets
  • 1,456
  • 3
  • 18
  • 34