C# 在 ASP.NET 网页中打开 PDF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11646665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 18:39:17  来源:igfitidea点击:

Open PDF in web page of ASP.NET

c#asp.netpdf

提问by Lajja Thaker

I want to open PDF in ASP.NET aspx page. I dont want to export a pdf file.

我想在 ASP.NET aspx 页面中打开 PDF。我不想导出 pdf 文件。

Need just write pdf file in ASPX page same as we are writing bytes into Image control.

只需在 ASPX 页面中写入 pdf 文件,就像我们将字节写入 Image 控件一样。

采纳答案by Lajja Thaker

I got the answer , it is too simple.

我得到了答案,这太简单了。

I have answered here.

我已经在这里回答了。

Response.Clear();
string filePath = "myfile.pdf";
Response.contentType = "application/pdf";
Response.WriteFile(filePath);
Response.End();

回答by Kasper Cottaar

Place the pdf document in an IFrame in your page.

将 pdf 文档放在页面的 IFrame 中。

回答by Vikash Sinha

Try below code: Here FullPath is full path of file with file name

试试下面的代码:这里FullPath是文件名的完整路径

Dim f1 As New FileStream(FullPath, FileMode.Open)
Dim m1(f1.Length) As Byte
f1.Read(m1, 0, f1.Length)
f1.Close()
File.Delete(FullPath)
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.Clear()
Response.OutputStream.Write(m1, 0, m1.GetLength(0))

回答by daniel

to Create PDF-Files you can use a library like pdfsharp http://pdfsharp.com/

要创建 PDF 文件,您可以使用像 pdfsharp http://pdfsharp.com/这样的库

you can easily create PDFs with that. Example Code:

您可以使用它轻松创建 PDF。示例代码:

PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
...

and then save it on your Server

然后将其保存在您的服务器上

document.Save(filename);

then just link to it via an a-href or in an iframe.

然后只需通过 a-href 或 iframe 链接到它。