外部CSS是否适用于由jsPDF生成的pdf [英] Does external css get applied to the pdfs generated by jsPDF

查看:104
本文介绍了外部CSS是否适用于由jsPDF生成的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用jspdf进行一些演示。我有一个html文件,我的css在外部文件中。

I have started making some demos using jspdf. I have a html file and my css is in external file.

我已经写下了下面的代码来生成我的pdf

I have written the below code to generate my pdf

$('#pdfButton').on('click', function(){

   var pdf = new jsPDF('p','in','letter')
   , source = $('#main')[0]
   , specialElementHandlers = {
      '#bypassme': function(element, renderer){
      return true
      }
   }

  pdf.fromHTML(
     source // HTML string or DOM elem ref.
      , 0.5 // x coord
      , 0.5 // y coord
      , {
            'width':700 // max width of content on PDF
            , 'elementHandlers': specialElementHandlers
       }
   )
   pdf.output('dataurl');

   });


});

其中 main 是要导出其内容的div的ID作为pdf。
内容以PDF形式导出,但不是全部内容(pdf会被剪切)。它可以是动态内容。另外,我在外部文件中的css没有得到应用,像 table-row ,背景颜色等风格没有得到应用。

where main is the id of the div whose content I want to export as pdf. The content is exporting as pdf but not the entire content(the pdf gets cut). It can be dynamic content. Also the css I have in external files are not getting applied , styles like table-row, background-color, etc are not getting applied.

如何在生成pdf之前将我的外部css应用到pdf中?
是否可以使用jsPDF ..?任何建议请。

How can I get my external css applied to the pdf before it is generated? Is it even possible with jsPDF..? Any suggestions please.

在此先感谢

推荐答案

我知道jsPDF不采取外部CSS。它事实上甚至不采取内联的CSS。目前不适合使用jspdf将html转换为pdf。

As far as I know jsPDF doesnt take external css. It infact doesnt even take inline css. It is currently not suitable to use jspdf for converting html to pdf.

希望这有助于。

这篇关于外部CSS是否适用于由jsPDF生成的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆