gpt4 book ai didi

c# - 如何打开浏览器PDF格式的数据?

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:19 25 4
gpt4 key购买 nike

我获取数据(沃尔沃汽车的价格)我的 xml 或 sql 数据库,我有“xyz.aspx”页面。如何在网络浏览器中打开 pdf。但我想了解如何打开 pdf(来自 sql 数据表的数据)xyz.aspx 或 another.aspx 中的数据...

样本:Volvos'prices pdf

最佳答案

假设您有一张这样的 table :

CREATE TABLE PDFTable (
[PDFID] [bigint] IDENTITY (1, 1) NOT NULL ,
[PDFFile] [varbinary(max)]
)

并且您将 PDF 文件以二进制格式存储在此表中。并且您想像这样向访问者公开您的 PDF 文件:

http://www.mysite.com/getpdf.aspx?pdfid=12

这是一个从数据库中读取二进制 pdf 数据并将其写入响应流的示例:

// PageLoad event of your getpdf.aspx page :
long pdfId= Convert.ToInt64(Request.QueryString["pdfid"]);

using (var conn = new SqlConnection(connectionString))
{
using (var command = new SqlCommand(
"SELECT PDFFile FROM PDFTable WHERE PDFId = @PDFID", conn))
{
command.Parameters.Add("@PDFID", SqlDbType.Int).Value = pdfId;
conn.Open();

Response.ContentType = "application/pdf";
Response.BinaryWrite((byte[]) command.ExecuteScalar());
}
}

此页面将使您的客户在他/她的浏览器中打开 pdf。

关于c# - 如何打开浏览器PDF格式的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/744969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com