Javascript jsPDF不';不能在Chrome中工作,只有Firefox&;游猎

Javascript jsPDF不';不能在Chrome中工作,只有Firefox&;游猎,javascript,google-chrome,pdf,jspdf,html2canvas,Javascript,Google Chrome,Pdf,Jspdf,Html2canvas,我正在尝试使用jsPDF将应用程序导出为PDF。浏览完网页,在这里抓取了一行代码,在那里抓取了一个部分-我已经设法让它工作了。。。有点 它适用于Firefox和Safari,但不适用于Chrome。 使用的JS文件(来自jsPDF)。也许是矫枉过正。还有Jquery <script type="text/javascript" src="PDF/standard_fonts_metrics.js"></script>

我正在尝试使用jsPDF将应用程序导出为PDF。浏览完网页,在这里抓取了一行代码,在那里抓取了一个部分-我已经设法让它工作了。。。有点

它适用于Firefox和Safari,但不适用于Chrome。

使用的JS文件(来自jsPDF)。也许是矫枉过正。还有Jquery

    <script type="text/javascript" src="PDF/standard_fonts_metrics.js"></script> 
    <script type="text/javascript" src="PDF/split_text_to_size.js"></script>               
    <script type="text/javascript" src="PDF/from_html.js"></script>
    <script type="text/javascript" src="PDF/addhtml.js"></script>               
    <script type="text/javascript" src="PDF/addimage.js"></script>

我使用的代码是:

<script type="text/javascript">
function demoFromHTML() {
  $('#listAreaPDF').css("display", "block");

  var pdf = new jsPDF('p', 'pt', 'letter');
  // source can be HTML-formatted string, or a reference
  // to an actual DOM element from which the text will be scraped.
  source = $('#listAreaPDF')[0];

  pdf.setFontSize(24);
  pdf.text(35, 40, "PDF Title here");

  pdf.setFontSize(10);
  pdf.text(500, 40, "Company Name AB");

  // we support special element handlers. Register them with jQuery-style 
  // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
  // There is no support for any other type of selectors 
  // (class, of compound) at this time.
  specialElementHandlers = {
    // element with id of "bypass" - jQuery style selector
    '#bypassme': function (element, renderer) {
      // true = "handled elsewhere, bypass text extraction"
      return true
    }
  };
  margins = {
    top: 80,
    bottom: 60,
    left: 40,
    width: 522
  };


  // all coords and widths are in jsPDF instance's declared units
  // 'inches' in this case
  pdf.fromHTML(
    source, // HTML string or DOM elem ref.
    margins.left, // x coord
    margins.top, {// y coord
      'width': margins.width, // max width of content on PDF
      'elementHandlers': specialElementHandlers
    },
    function (dispose) {
      html2canvas($("#presentationArea"), {
        onrendered: function (canvas) {
          var imgData = canvas.toDataURL(
            'image/png');

          pdf.addImage(imgData, 'PNG', 20, 300);
          pdf.save('Test.pdf');
        }
      });
      // dispose: object with X, Y of the last line add to the PDF 
      // this allow the insertion of new lines after html
      // pdf.save('Test.pdf');
    },
    margins
  );
  $('#listAreaPDF').css("display", "none");
}
</script>

函数demoFromHTML(){
$('#listAreaPDF').css(“显示”、“块”);
var pdf=新的jsPDF(“p”、“pt”、“字母”);
//源可以是HTML格式的字符串或引用
//到实际的DOM元素,文本将从该元素中删除。
source=$('#listAreaPDF')[0];
pdf.setFontSize(24);
文本(35,40,“此处为pdf标题”);
pdf.setFontSize(10);
文本(500,40,“公司名称AB”);
//我们支持特殊的元素处理程序。用jQuery风格注册它们
//ID或节点名称的ID选择器。(“#iAmID”、“div”、“span”等)
//不支持任何其他类型的选择器
//(类,指化合物)此时。
SpecialElementHandler={
//id为“bypass”的元素-jQuery样式选择器
“#绕过我”:函数(元素、渲染器){
//true=“在别处处理,绕过文本提取”
返回真值
}
};
边距={
排名:80,
底数:60,
左:40,,
宽度:522
};
//所有坐标和宽度都以jsPDF实例声明的单位表示
//在本例中为“英寸”
pdf.fromHTML(
source,//HTML字符串或DOM元素引用。
margins.left,//x坐标
margins.top,{//y坐标
“宽度”:margins.width,//PDF上内容的最大宽度
“elementHandlers”:specialElementHandlers
},
功能(处置){
html2canvas($(“#呈现区域”){
onrendered:函数(画布){
var imgData=canvas.toDataURL(
“图像/png”);
pdf.addImage(imgData,'PNG',20300);
保存('Test.pdf');
}
});
//dispose:将最后一行的X,Y添加到PDF中的对象
//这允许在html之后插入新行
//保存('Test.pdf');
},
边距
);
$('#listAreaPDF').css(“显示”、“无”);
}
为了适应我的应用程序,我做了一些小改动,添加了一个到html2canvas的连接,将图像从我的应用程序中取出并放入PDF。在Safari和Firefox中,它实际上可以正常工作

当在Chrome中点击并激活此功能时,我甚至没有收到一份空白的PDF,我什么也得不到。甚至不会生成弹出窗口或页面

为什么Firefox和Safari可以工作而Chrome不能工作? 我还没有尝试过Internet Explorer,但我不会屏住呼吸。 如果你知道这样做的方法,我完全赞成


为您提供的任何帮助或建议干杯。

此问题可能与chrome有关

删除:内容启动的顶部框架到数据URL的导航(已删除)

我们打算阻止网页加载数据:使用标签、window.open、window.location和类似机制在顶部框架中加载URL

诸如data:之类的伪URL通常会让用户感到困惑。由于不熟悉,这些方案被广泛用于欺骗和网络钓鱼攻击。理想情况下,浏览web的用户应该只使用两种众所周知的方案(http和https)

M58中已弃用

M60中的拆卸


一个可能的解决方案是,如前面提到的google groups线程中所述,使用iFrame。

该问题可能特定于保存请求。这表明这可能会有所帮助。“#PresentationArea”是否指向div元素?