PDF链接转字节流输出
当一个PDF链接是重要的、不随便公开的、权限控制的,就可以用包一层方法,把PDF转另已页面输出
// PDF链接 string _electronicUrl ="https://wwwimages2.adobe.com/www.adobe.com/content/dam/acom/cn/legal/licenses-terms/pdf/PlatformClients_PC_WWEULA-zh_CN-20150407_1357.pdf"; var request = (HttpWebRequest) WebRequest.Create(_electronicUrl); request.Timeout = 30000; WebResponse response = request.GetResponse(); //string type = response.ContentType; Stream stream = response.GetResponseStream(); MemoryStream ms = new MemoryStream(); const int bufferLen = 5120; byte[] buffer_m = new byte[bufferLen]; int count = 0; while ((count = stream.Read(buffer_m, 0, bufferLen)) > 0) { ms.Write(buffer_m, 0, count); } stream.Close(); int buffsize = (int) ms.Length; //rs.Length 此流不支持查找,先转为MemoryStream byte[] buffer = new byte[buffsize]; ms.Position = 0; ms.Read(buffer, 0, buffsize); ms.Close(); string strBase64 = Convert.ToBase64String(buffer);