I'm trying to re implement the choose file from file. by creating a button to select the PDF file then it run a function in the PdfViewerController.cs
public ActionResult Upload()
{
string filePath = "";
HttpPostedFileBase file = Request.Files[0]; //Uploaded file
int fileSize = file.ContentLength;
string fileName = file.FileName;
string mimeType = file.ContentType;
System.IO.Stream fileContent = file.InputStream;
file.SaveAs(Server.MapPath("~/") + fileName); //File will be saved in application root
MemoryStream stream = new MemoryStream();
file.InputStream.CopyTo(stream);
PdfRenderer pdfviewer = new PdfRenderer();
object jsonResult = new object();
jsonResult = pdfviewer.Load(stream);
return Content(JsonConvert.SerializeObject(jsonResult));
}
and on the javascript
function sendSelectedPDFToServer() {
var formdata = new FormData(); //FormData object
var fileInput = document.getElementById('fileInput');
//Iterating through each files selected in fileInput
for (i = 0; i < fileInput.files.length; i++) {
//Appending each file to FormData object
formdata.append(fileInput.files[i].name, fileInput.files[i]);
}
//Creating an XMLHttpRequest and sending
var xhr = new XMLHttpRequest();
xhr.open('POST', '/PdfViewer/Upload');
xhr.send(formdata);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText);
var PDFFile = xhr.responseText
}
}
return false;
}
how can I open the returned PDF from javascript ?