Display PDF file from database in browser using Web API in AngularJS

Last Reply 6 months ago By dharmendr

Posted 6 months ago

How to display pdf files from the database using angularjs in html

I'm not getting any error on the browser console, my whole browser page is white and empty.

$http.get("http://localhost:49556/api/purchaseOrder/getEmpImages", { responseType: 'arraybuffer' })
.then(function (response) {
    var file = new Blob([response], { type: 'application/pdf' });
    var fileURL = URL.createObjectURL(file);
    $scope.content = $sce.trustAsResourceUrl(fileURL);
})

 

<form name="cntrl.Form1" role="form" enctype="multipart/form-data"> 
    <embed ng-src="{{content}}" style="width:200px;height:200px;"></embed>
</form>

 

[HttpGet]
[ActionName("getEmpImages")]
public string getEmpImages()
{
    SqlConnection myConnection = new SqlConnection();
    myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ERPConnectionStringI"].ConnectionString;
    SqlCommand sqlCmd = new SqlCommand();
    sqlCmd.CommandType = CommandType.StoredProcedure;
    sqlCmd.CommandText = "GET_PURCHASE_INVOICE_DOC";
    sqlCmd.Connection = myConnection;
    //sqlCmd.Parameters.AddWithValue("@Parameter", Parameter);
    SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
    DataSet ds = new DataSet();
    string jsonString = string.Empty;
    myConnection.Open();
    sda.Fill(ds);
    myConnection.Close();
    jsonString = JsonConvert.SerializeObject(ds.Tables[0]);
    return jsonString;
}

 

You are viewing reply posted by: dharmendr 6 months ago.
Posted 6 months ago

Use iframe to display in browser. Refer below link.

Display binary PDF data from Database in browser in AngularJS