在chrome新版本上使用window.open显示base64 pdf数据

时间:2017-10-12 06:34:11

标签: javascript angularjs google-chrome pdf

我在新窗口中使用以下代码将open base64数据作为pdf

create or replace function MATHS_F 
   (p_id IN varchar2)

   RETURN number
   is res_code VARCHAR2(2);
   points number(3,0);     

   cursor c1 is
   select substr(substr(lcstring, instr(lcstring,'02')+2),1,2) 
   from sdata s
   where s.id = p_id;

BEGIN

   open c1;
   fetch c1 into res_code;
   close c1;

   select c_points
   into points 
   from lcresults l 
   where l.lc_code = res_code;

   RETURN points;


exception when no_data_found then
   return 99;

END MATHS_F;

这适用于Chrome版本56.0.2924.87 但不适用于版本61.0.3163.100 [参考屏幕截图]
Sample plunker code

enter image description here

3 个答案:

答案 0 :(得分:5)

var pdfResult = data_.data.info.result.result;

let pdfWindow = window.open("")
pdfWindow.document.write("<iframe width='100%' height='100%' src='data:application/pdf;base64, " + encodeURI(pdfResult) + "'></iframe>")

这用于在浏览器选项卡中显示base64 pdf。

答案 1 :(得分:2)

我使用AngularJS遇到了类似的问题。这就是我管理的方式,在我的例子中,我将URL中的文件作为arraybuffer加载。希望它有所帮助。

$http({
    method: 'GET',
    url: '/api/transaction-file/'+id,
    responseType:'arraybuffer'
}).then(function(response){
    var file = new Blob([response.data], {type: 'application/pdf'});
    var fileURL = URL.createObjectURL(file);
    window.open(fileURL);
}, function(response){
    //Error
});

答案 2 :(得分:0)

我也有问题,我与朋友Petrus的解决方案是:


body {
  color: #000;
  font: 1em/1.5 "Helvetica Neue", Helvetica, Arial, sans-serif;

}

.primary-content{
  text-align:center;
  font-family: 'Abolition Regular', Helvetica, Arial, sans-serif;
  font-size: 15rem;
  padding-top:20px;
    margin-top:0;
  padding-bottom: 50px;
  margin-bottom:0px;
  display:block;
}

.title{
  display:block;
  text-align:center;
  padding-left:15rem;
  padding-right:15rem;
}

.team{
  text-align:center;
  font-size:7rem;
  padding-top:0;
  margin-top:0;
  width:100%;
}

.bot {
float:left;
width:47%;
padding:1px 1px 1px 1px; 
margin: 0 1px 0 1px;
}

.pod {
float:right;
width:47%;
padding:1px 1px 1px 1px; 
margin: 90.66px 1px 90.66px 1px;
}
<div class="primary-content">
       <span class="title">FTC TEAM 4466</span>
          <a href="#egg">egg</a>
      
      
            <div class="bot-pod">
              <div class="bot">
                   <img src="img/finalbot.svg" alt="old robot">
                </div>
                <div class="pod">
                   <img src="img/finalpod.svg" alt="old robot">
                </div>
             </div>
   
      
      <div class="team">
              <span class="title">testing</span>
              <h1>4466</h1>
              <span class="egg">        <p>
          <a href="#egg">egg</a>
        </p></span>
      </div><!-- End  -->

		</div><!-- End .primary-content --> 
```
Relevant CSS
```