[英]Stream PDF to Byte Array
我正在嘗試將pdf文件加載到字節數組,但是在代碼運行后,字節數組的長度為零。 不知道我在做什么錯。 該項目是vs 2010,在vm 9x中運行win 7 32 bit操作系統。 希望對此問題有一個簡單的解決方法。 提前致謝。
以下代碼為我工作:
private void btnOpenFile_Click(object sender, EventArgs e)
{
string strId = gridViewMain.SelectedRows[0].Cells["id"].Value.ToString();
if (!string.IsNullOrEmpty(strId))
{
SqlCommand cmd = new SqlCommand(strQuery_GetAttachmentById, objConn);
cmd.Parameters.AddWithValue("@attachId", strId);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
SqlCommandBuilder sqlCmdBuilder = new SqlCommandBuilder(da);
da.Fill(dt);
DataRow dr = dt.Rows[0];
byte[] PDFBytes = (byte[])dr["attachment"];
LoadPdf(PDFBytes);
}
}
public void LoadPdf(byte[] pdfBytes)
{
var PDFstream = new MemoryStream(pdfBytes);
LoadPdf(PDFstream);
}
public void LoadPdf(Stream pdfstream)
{
// Create PDF Document
var pdfDocument = PdfDocument.Load(pdfstream);
// Load PDF Document into WinForms Control
pdfRenderer1.Load(pdfDocument);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.