簡體   English   中英

在新的 Window 中打開 PDF 文件?

[英]Open PDF File in new Window?

嗨,我陷入了下一種情況,我需要打開一個 pdf 文件,我先上傳到服務器。 我試過以下代碼:

string Servidor = Request.Url.GetLeftPart(UriPartial.Authority);
var fullUrl  = Servidor + Session["strUrl"];

var NewProcess = new System.Diagnostics.Process();
NewProcess.StartInfo.FileName = fullUrl;
NewProcess.Start();

當我在本地主機中時,此代碼工作正常,但是當我部署我的 web 應用程序時,它不起作用。 有沒有其他解決方案來實現這一點?

在您生成的 html 中,您需要“a”標簽上的“target”屬性,名稱為 window,或更通用的“_blank”,以打開新的 window

例如

<a href="document.pdf" target="_blank">Open document in a new window</a>

或純 asp.net

<asp:HyperLink id="hyperlink1" NavigateUrl="document.pdf" Target="_blank" Text="Open document in a new window"  runat="server"/>  

您無法通過在遠程服務器上啟動新進程來打開 PDF。 您必須在托管在服務器上的網頁上創建一個鏈接,該鏈接指向您要打開的 pdf(也應托管在 web 服務器上)。

<a href="file.pdf">Open</a>

使用此代碼。 這就像一個冠軍。

Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = outputPdfFile;
process.Start();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM