I have a custom Drupal 7 module that prints out the contents of a form, parses it and replaces all the form elements with equivalent divs, then prints out the HTML using DOMDocument()
.
This is then run through wkhtmltopdf to generate a PDF. I also have a little preg_replace
that converts all occurrences of textarea/input
to .div-textarea/.div-input
in some inline CSS.
The issue, however, is that the default Drupal CSS files and the CSS files that are included in the custom theme are unable to be processed by this regex, because the drupal_get_css()
function returns <link>
tags and CSS's @import
rule.
So the question is: do you know how I can get Drupal's theme output to print the actual raw contents of the CSS files in the HTML rather than these stylesheet links so that I can run the replacement function over it?
Or are there any better ways of copying CSS rules from one element/class to another?
I did this using a php funciton: file_get_contents
Then your code looks something like:
$css = file_get_contents(drupal_get_path('theme', 'my_theme') . 'css/my_css.css');
Then you can print that css in any template or append to any string to get your output.
Edit:
To get a list of all css files run: $css_list = drupal_add_css();