Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print/Save as PDF (keeping the CSS layout)

Tags:

html

css

pdf

save

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!

like image 594
user1083320 Avatar asked Jul 23 '13 20:07

user1083320


2 Answers

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" />
like image 104
dan-klasson Avatar answered Oct 04 '22 14:10

dan-klasson


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.

like image 21
ajdigregorio Avatar answered Oct 04 '22 14:10

ajdigregorio