我有一个pdf元素,它作为字符串base64元素返回,因为它是一个MVC Web应用程序,文件位于服务器上。我目前正在使用PDFObject和pdf.js尝试在浏览器中查看这个PDF。但是,我似乎无法显示PDF,除非我传递一个url,当我将这个应用程序放在IIS中的服务器上时,它将无法工作。
那么,是否有一种方法可以让我嵌入的pdf与src="{my base 64 string}“一起使用,然后将PDFObject封装起来?如果没有,是否有办法通过PDFObject使用base64字符串而不是url?
此外,这是在IE 11
UPDATE这里是我的控制器
public ActionResult GetPDFString(string instrumentType, string booktype, string book, string startpage, string EndPage)
{
LRS_Settings settings = ctxLRS.LRS_Settings.FirstOrDefault();
string root = settings.ImagePathRoot;
string state = settings.State;
string county = settings.County;
g_filePath = @"\\10.20.170.200\Imaging\GA\075\Daily\" + instrumentType + "\\" + book + "\\";
//g_filePath = @"\\10.15.100.225\sup_court\Imaging\GA\075\Daily\" + instrumentType + "\\" + book + "\\";
byte[] file = imgConv.ConvertTifToPDF(g_filePath, booktype, book, startpage, EndPage);
var ms = new MemoryStream(file);
var fsResult = new FileStreamResult(ms, "application/pdfContent");
return fsResult;
//return imgConv.ConvertTifToPDF(g_filePath, booktype, book, startpage, EndPage);
}这是我的jquery
var options = {
pdfOpenParams: {
navpanes: 1,
toolbar: 0,
statusbar: 0,
pagemode: 'none',
pagemode: "none",
page: 1,
zoom: "page-width",
enableHandToolOnLoad: true
},
forcePDFJS: true,
PDFJS_URL: "/PDF.js/web/viewer.html"
}
PDFObject.embed("@Url.Action("GetPDFString", "DocumentView", new { instrumentType = ViewBag.instrumentType, BookType = Model.BookType, Book = ViewBag.Book, StartPage = ViewBag.StartPage, EndPage = ViewBag.endPage, style = "height:100%; width100%;" })", "#PDFViewer", options);现在的问题是,它没有在#PDFViewer中显示PDF,而是试图下载该文件。有人能帮我完成拼图的最后一块吗?快把我逼疯了。
发布于 2016-08-31 22:02:10
你试过用标准的html来代替吗?控制器动作
public ActionResult GetAttachment(string instrumentType, string booktype, string book, string startpage, string EndPage)
{
var fileStream = new FileStream(Server.MapPath("~/Content/files/sample.pdf"),
FileMode.Open,
FileAccess.Read
);
var fsResult = new FileStreamResult(fileStream, "application/pdf");
return fsResult;
}在你看来
<div id="PDFViewer">
<embed src="@Url.Action("GetAttachment", "DocumentView", new { instrumentType = ViewBag.instrumentType, BookType = Model.BookType, Book = ViewBag.Book, StartPage = ViewBag.StartPage, EndPage = ViewBag.endPage })" width="100%" height="100%" type="application/pdf"></embed>
</div>这是否适合您的需求,而不是使用PDFObject?
发布于 2016-08-31 23:36:09
确保将内容配置头设置为inline,否则浏览器将尝试下载该文件,而不是在视口中呈现它。
请参阅Content-Disposition:What are the differences between "inline" and "attachment"?
至于PDFObject还是普通的HTML,为了排除故障,我总是建议尝试静态标记(没有JS)来显示相同的PDF。如果它在那里工作,问题可能在于PDFObject (在本例中,PDFObject对Base64字符串的处理)。如果PDF没有通过普通标记正确地呈现,问题可能在于您的文件/Base64 64。
您可以从PDFObject静态标记生成器:http://pdfobject.com/generator获取静态标记的副本。
(我应该补充一点,我不能与PDF.js处理Base64字符串.)
https://stackoverflow.com/questions/39256848
复制相似问题