在一个 asp.net Web 应用程序中,我使用下面的代码从共享路径读取 PDF 文件,并td使用 iframe 在表格标签中显示它。这样它就可以像缩略图/预览一样显示 pdf。这适用于小型 pdf 文件大小。但是对于 pdf 文件大小 > 25mb(大约),iframe 显示为空。
ImpersonationHelper.Impersonate(ConfigurationManager.AppSettings["Domain"], ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"], delegate
{
FileBuffer = System.IO.File.ReadAllBytes(filepath);
if (FileBuffer != null)
{
if (filepathnew.Contains("pdf"))
{
string base64String = Convert.ToBase64String(FileBuffer, 0, FileBuffer.Length);
pdfUrl = "data:application/pdf;base64," + base64String;
}
}
});
string pdfSource = String.Empty;
pdfSource = "<iframe src=" + pdfUrl + " visible='false' style='overflow:hidden' width='400' height='400' scrolling='no' type='application/pdf' id='pdfPreview'></iframe>";
StringBuilder table = new StringBuilder();
table.Append("<td >" + pdfSource1 + "</td>");