Print/Save as PDF (keeping the CSS layout)

China☆狼群 提交于 2020-01-13 05:11:42

问题


When I simply print (like on paper), or save as PDF a page (using the browser built-in tool), the css is completely ignored and I just get ugly lines after lines of the content!!

Is there a way to do this (without having to convert the HTML 2 PDF/image)?

Thanks!


回答1:


You should look up Media Types in CSS... set one up for printing and you should be good to go. I've found that this page is really helpful.




回答2:


That's probably cause you've got the media option specified.

<!-- will ignore css on print -->
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />

<!-- will only use css when printing -->
<link href="style.css" rel="stylesheet" type="text/css" media="print" />

<!-- will use both -->
<link href="style.css" rel="stylesheet" type="text/css" />


来源:https://stackoverflow.com/questions/17820857/print-save-as-pdf-keeping-the-css-layout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!