我需要在新浏览器选项卡中打开pdf文件。这个怎么做。 我正在使用如何在javascript中打开pdf文件新浏览器窗口
var docLocation = '../downloads/doc.pdf';
window.open(docLocation,"resizeable,scrollbar");
但它打开浏览器的下载对话框。如何实现这一目标?
我需要在新浏览器选项卡中打开pdf文件。这个怎么做。 我正在使用如何在javascript中打开pdf文件新浏览器窗口
var docLocation = '../downloads/doc.pdf';
window.open(docLocation,"resizeable,scrollbar");
但它打开浏览器的下载对话框。如何实现这一目标?
显示PDF的能力完全取决于用户是否有可用于显示PDF的插件,并且它们的设置被设置为以这种方式处理PDF文件。
这里有一些flash小部件,可以用来向用户展示pdf内容,但直接回答你的问题,你不能控制用户如何选择处理pdf文件的偏好。
这里
<a href="javascript:void(0);" onclick="javascipt:window.open('YourPDF.pdf');" class="popup">Clic to open.</a>
你需要在你的电脑已经安装了读卡器
确保Content-Type头是 '应用程序/ PDF' 而不是 '应用程序/八位字节流'
我尝试了上述所有解决方案,但都没有为我工作,我在mvc 3上运行javascript,并且在Chrome和Firefox上安装了剃须刀,adobe 11作为附加组件。这是我为了让它在所有上面的浏览器上工作而做的。
制造PDF控制器,在主视图剃刀代码从JavaScript这样
称为:
var URL_OPEN_REPORT_PDF = "@Url.Content("~/Report/OpenPDF/")";
的javascript:
var sURL = URL_OPEN_REPORT_PDF;
sURL = AddURLParameter(sURL, "ReportArchive", moControl.treeOrganization.getUserData(sItemUI, "reportarchive"));
window.open(sURL);
控制器ReportController.cs:
[Authorize]
[HttpGet]
public ActionResult OpenPDF(string ReportArchive)
{
PDFResult oPdfResult = new PDFResult();
ReportArchive oReportArchive;
var serializer = new JavaScriptSerializer();
oReportArchive = serializer.Deserialize<ReportArchive>(ReportArchive);
string FilePath = Server.MapPath(string.Format("~/Content/Reports/{0}", oReportArchive.FileName));
WebClient User = new WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if (FileBuffer != null)
{
oPdfResult.Length = FileBuffer.LongLength;
oPdfResult.FileBuffer = FileBuffer;
Response.BinaryWrite(FileBuffer);
} return View("PDF", oPdfResult);
}
视图模型PDFResult.cs:
public class PDFResult
{
/// <summary>
/// Content Length
/// </summary>
public long Length { get; set; }
/// <summary>
/// Content bytes
/// </summary>
public Byte[] FileBuffer { get; set; }
}
查看PDF.cshtml:
@model Report.PDFResult
@{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", Model.Length.ToString());
Layout = null;
}
此代码将在一个完整的窗口中打开一个PDF文档从JavaScript
var pdf = MyPdf.pdf;
window.open(pdf);
打开窗户的函数看起来像这样:
function openPDF(pdf){
window.open(pdf);
return false;
}