ldt25290 ldt25290 - 2 years ago 114
iOS Question

UIPrintPageRenderer issue : generate pdf when loading multiple css files in HTML file

I'm using BNHtmlPdfKit to generate pdf file from html template.
This lib has a UIWebView, it will load html string.

Then it use UIPrintPageRenderer to generate pdf file.

In HTML file, I have imported 2 css files like below :

<link href="style.css" rel="stylesheet" type="text/css" />
<link href="bootstrap.css" rel="stylesheet" type="text/css" />


Currently, the rendered pdf file has only css style of the bootstrap.css file.

However, I tried to add important! property for each item in style.css, the pdf could display css style of style.css file.

#myContent {
background-color: lightblue !important;
font-family: Helvetica Neue, sans-serif;
color: red !important;
padding: 20px;
}


Anyone has been able to generate pdf using multiple css file and without using !important property?

Answer Source

The crux is that bootstrap.css overwrites your style via @media print { } rules and UIPrintPageRenderer prints the content to PDF file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download