我有以下问题。我执行从JS到aspx页面的Ajax调用,作为参数传递base64编码的pdf。我的呼叫功能如下:
function PDF_Generator(base64)
{
var ESBParams =
{
encodedString : base64
}
try
{
$.ajax({
method : "POST",
url : pws_PDF_parsing_url,
data : ESBParams,
dataType : "html",
async : "false",
error :
function (xhr, err, errth){
alert('ERROR:' + errth);
},
success :
function (success){
window.open(success);
}
});
}
catch(obj)
{
alert(obj.messsage);
}
}
现在,我有以下aspx页面解码base64字符串,我会把解码后的pdf流回到javascript函数,以便在新页面中显示它(或者以另一种方式 - 我会感谢任何建议。)
using System;
public class PDF_Generator : System.Web.UI.Page
{
private string decodedPDF;
private string base64EncodedPDF;
Decoder decoder = new Decoder();
protected void Page_Load(object sender, EventsArgs e)
{
try
{
this.base64EncodedPDF = Request.Params["encodedString"]; //get encoded string from js
this.decodedPDF = decoder.decodeFromBase64toString(this.base64EncodedPDF); //decode string
byte[] pdfByteStream = decoder.getBytesFromString(this.decodedPDF);
Page.Response.ClearContent();
Page.Response.ContentType = "application/pdf";
Page.Response.AddHeader("Content-Disposition", "inline; filename=" + "summary.pdf");
Page.Response.AddHeader("Content-Length", pdfByteStream.Length.toString());
Page.Response.BinaryWrite((byte[])pdfByteStream);
Page.Response.End();
}
}
}