zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    php (一)
    php 运算符
    Python 元组
    Python 深拷贝和浅拷贝的区别
    Python 列表
    Python 字符串
    Python 循环控制
    Python 随机数,数学
    bzoj5018 [Snoi2017]英雄联盟
    bzoj5015 [Snoi2017]礼物
  • 原文地址:https://www.cnblogs.com/Iven-zhang/p/12218036.html
Copyright © 2011-2022 走看看