C# 在windows应用程序的adobe reader组件中将字节数组加载到pdf
我有一个pdf文件,在管理员所有的pdf文件都转换成字节数组存储在数据库中C# 在windows应用程序的adobe reader组件中将字节数组加载到pdf,c#,asp.net,winforms,C#,Asp.net,Winforms,我有一个pdf文件,在管理员所有的pdf文件都转换成字节数组存储在数据库中 public void Getfile() { byte[] file; string varFilePath = @"D:\PDFConvertion\pdf\100CountryHouses.pdf"; try { using (var stream = new FileStream(varFilePath, FileMode.Open, FileAccess.Rea
public void Getfile()
{
byte[] file;
string varFilePath = @"D:\PDFConvertion\pdf\100CountryHouses.pdf";
try
{
using (var stream = new FileStream(varFilePath, FileMode.Open, FileAccess.Read))
{
using (var reader = new BinaryReader(stream))
{
file = reader.ReadBytes((int)stream.Length);
}
}
SqlConnection sqlCon;
sqlCon = new SqlConnection("server details");
sqlCon.Open();
using (var sqlWrite = new SqlCommand("INSERT INTO pdftest Values(@File)", sqlCon))
{
sqlWrite.Parameters.Add("@File", SqlDbType.VarBinary, file.Length).Value = file;
sqlWrite.ExecuteNonQuery();
}
sqlCon.Close();
MessageBox.Show("Converted Success - Length " + Convert.ToString(file.Length));
}
catch (Exception Ex)
{
throw Ex;
}
}
一旦上传了文件,用户就可以查看文件,我已经使用adobe reader组件来加载pdf文件
private void button1_Click(object sender, EventArgs e)
{
string varPathToNewLocation = @"D:\PDFConvertion\converted\test.pdf";
try
{
SqlConnection sqlCon;
sqlCon = new SqlConnection("");
sqlCon.Open();
using (var sqlQuery = new SqlCommand(@"SELECT test FROM [dbo].[pdftest] ", sqlCon))
{
using (var sqlQueryResult = sqlQuery.ExecuteReader())
if (sqlQueryResult != null)
{
sqlQueryResult.Read();
var blob = new Byte[(sqlQueryResult.GetBytes(0, 0, null, 0, int.MaxValue))];
sqlQueryResult.GetBytes(0, 0, blob, 0, blob.Length);
using (var fs = new FileStream(varPathToNewLocation, FileMode.Create, FileAccess.Write))
fs.Write(blob, 0, blob.Length);
}
}
sqlCon.Close();
axAcroPDF1.LoadFile(@"D:PDFConvertion\converted\test.pdf");
}
catch (Exception Ex)
{
throw Ex;
}
}
但是我想直接将文件加载到adobe reader组件中,而无需存储在某个位置。您需要的是类似于LoadStream api的东西。快速搜索Acrobat SDK似乎没有发现任何问题。如果是web应用程序,可以将pdf文件放入网页的响应对象中。然后浏览器会自动打开acrobat reader。以下是c#代码片段:
这里有一个提示:永远不要使用
try/catch(Exception-ex){throw-ex;}
只需完全去掉try/catch块。不,它不是web应用程序。
Response.Buffer = true;
Response.Clear();
Response.ContentType = "application/pdf";
// if blob is the byte array of the pdf file
Response.BinaryWrite(blob);
Response.Flush();
Response.End();