Asp.net mvc Adobe嵌入式PDF保存到服务器,提供损坏的文件
我使用Adobe Document Services PDF Embed API在我的网站和Iam中显示PDF文件,允许用户在PDF中添加便笺,然后保存 我的问题是我需要将文件保存回服务器。但是我找不到PDF缓冲区。我需要将pdf缓冲区或更新的pdf发送到我的Asp.net ConbtrollerAsp.net mvc Adobe嵌入式PDF保存到服务器,提供损坏的文件,asp.net-mvc,pdf,Asp.net Mvc,Pdf,我使用Adobe Document Services PDF Embed API在我的网站和Iam中显示PDF文件,允许用户在PDF中添加便笺,然后保存 我的问题是我需要将文件保存回服务器。但是我找不到PDF缓冲区。我需要将pdf缓冲区或更新的pdf发送到我的Asp.net Conbtroller adobeDCView.previewFile({ /* Pass information on how to access the file */
adobeDCView.previewFile({
/* Pass information on how to access the file */
content: {
/* Location of file where it is hosted */
location: {
url: myurl,
},
},
/* Pass meta data of file */
metaData: {
/* file name */
fileName: "-VER - 0.pdf"
}
}, viewerConfig);
/* Define Save API Handler */
var saveApiHandler = function (metaData, content, options) {
console.log(metaData, content, options);
return new Promise(function (resolve, reject) {
/* Dummy implementation of Save API, replace with your business logic */
/
var formData = new FormData();
formData.append('metaData', metaData);
formData.append('content', content); // is this the pdf buffer ???
formData.append('options', options);
setTimeout(function () {
//Want to do ajax call to controller here
var response = {
code: AdobeDC.View.Enum.ApiResponseCode.SUCCESS,
data: {
metaData: Object.assign(metaData, { updatedAt: new Date().getTime() })
},
};
resolve(response);
}, 2000);
});
};
在我的控制器里我有
[HttpPost ]
public ActionResult GetData(object Metadata, Object content,object option)
{
BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream()) {
bf.Serialize(ms, content);
System.IO. File.WriteAllBytes(@"C:\1.pdf", ms.ToArray());
}
return View();
}
正如@joelgeraci所建议的,我们需要将内容转换为base64,并将其添加到表单数据中,然后发送给控制器操作(归功于@joelgeraci提供的代码笔)
var base64PDF = arrayBufferToBase64(content);
var formData = new FormData();
formData.append('content', base64PDF);
函数转换arraybuffer
function arrayBufferToBase64(buffer) {
var binary = "";
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
函数arrayBufferToBase64(缓冲区){
var binary=“”;
var字节=新的Uint8Array(缓冲区);
var len=字节数。字节长度;
对于(变量i=0;i
在控制器中
[HttpPost]
public ActionResult GetData(object Metadata, Object content, object option, IEnumerable<HttpPostedFileBase> productImg, String DocumentID, string filename)
{
byte[] sPDFDecoded = Convert.FromBase64String(((string[])content)[0]);
string filepath = "C:\1.pdf";
System.IO.File.WriteAllBytes(filepath, sPDFDecoded);
return View();
}
[HttpPost]
public ActionResult GetData(对象元数据、对象内容、对象选项、IEnumerable productImg、字符串DocumentID、字符串文件名)
{
字节[]SPDFDECODE=Convert.FromBase64String(((字符串[])内容)[0]);
string filepath=“C:\1.pdf”;
System.IO.File.writealBytes(文件路径,sPDFDecoded);
返回视图();
}
我有一个代码笔的工作示例。在我的示例中,PDF保存在本地,但您可以使用相同的技术将其提交到服务器。