In the admin section, on the module settings tab, what is the proper way to use the stylesheet URL setting? I have copied the original print.css file into my theme's css folder and am trying to get this setting correct so the module will use my file for styling the printed output.
Currently, my print.css file is located here;
drupal/sites/example.com/themes/genesis_sub/css/print.css
What do I need to enter in the URL setting, and how are the 'macros' %b and %t supposed to be used? I understand they are for base path and theme path, respectively, but there's no indication if they are supposed to be used together, or need to be used at all.
Thanks for the help.
Comment | File | Size | Author |
---|---|---|---|
#40 | print-671972-40.patch | 67.9 KB | anoopsingh92 |
#35 | print-671972-35.patch | 39.55 KB | anoopsingh92 |
#28 | interdiff_20_28.diff | 1.41 KB | hkirsman |
#28 | print-make_custom_print_css_work_for_pdfs-671972-28.patch | 1.09 KB | hkirsman |
#20 | print-mpdf-css-fix.patch | 831 bytes | cslevy |
Issue fork print-671972
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 671972-custom-print.css-file changes, plain diff MR !2
Comments
Comment #1
kbrum CreditAttribution: kbrum commentedSolution found.
After several iterations I discovered that both macros are required when the print.css file is moved under the theme;
example;
%b%t/css/print.css
It would be nice to have something written in the readme.txt file about these variables and examples of their use.
This is a really neat module. Thanks for all the hard work it took for development and maintaining.
Comment #3
mvcI would like to suggest that this be added to README.txt:
Old text:
To modify the template of printer friendly pages, simply edit the print.tpl.php or the css/print.css files.
New text:
To modify the template of printer friendly pages, simply copy the print.tpl.php or the css/print.css files to your theme directory. To use your custom CSS file instead of the default, go to Administration > Configuration > User interface > Printer, email and PDF versions > Settings and enter the location of your file, such as %t/css/print.css (the placeholder %t will be replaced with the directory of your theme).
The idea here is to discourage people from modifying the copy of print.css or print.tpl.php which ship with the module, as these changes will be wiped out whenever the module is updated.
Comment #4
donpwinston CreditAttribution: donpwinston commentedThis does not appear to work for "PDF version". It only works for "Printer-friendly version". Am I doing anything wrong?
I must be because it would be useless.
Comment #5
mvcpointing to HEAD so this gets noticed.
Comment #6
littlepixiez CreditAttribution: littlepixiez commentedI can't get the css customisation to show up on the PDF versions either... I hope this gets resolved soon.
Comment #7
schifazl CreditAttribution: schifazl commentedThis is a strange issue I'm having too. I say strange because locally works, but on the production site it doesn't.
Comment #8
prabhatjn CreditAttribution: prabhatjn commentedYes css is not working on the pdf pages, so I am updating this issue as this is a critical issue for me.
P.
Comment #9
prabhatjn CreditAttribution: prabhatjn commentedAt least the inline styles are working, I am going to use that until someone fix this issue.
Thanks,
P.
Comment #10
milos.kroulik CreditAttribution: milos.kroulik commentedComment #11
graper CreditAttribution: graper commentedThe problem seems to be dependent on the order that the pdf file is added to the array for style sheets.
The css file that is save in the module's admin page is added to the list of stylesheets in file print.pages.inc on line 382. The use of drupal_add_css does not include a group option.
changing the line from
drupal_add_css(strtr($print_css, array('%t' => drupal_get_path('theme', variable_get('theme_default')))));
to
drupal_add_css(strtr($print_css, array('%t' => drupal_get_path('theme', variable_get('theme_default')))), array('group' => CSS_THEME) );
is a start. this allows the css in the print module settings to be output when the theme css files are output. This helped me with a theme that had stylesheets in the info file, which were output last.
with the group options being a number, the following line will definitely ensure that the print module settings' css file is output last for any of the print modules output.
drupal_add_css(strtr($print_css, array('%t' => drupal_get_path('theme', variable_get('theme_default')))), array('group' => 10000, 'media'=>'print', 'weight' => 10000) );
Comment #12
roball CreditAttribution: roball commentedThe same custom
print.css
file does work fine for both Printer-friendly and PDF output modes.Comment #13
bisonbleu CreditAttribution: bisonbleu commentedI'm a bit confused...
With NO Custom stylesheet.
A - When I add body {background:#F00;} to sites/all/modules/print/css/print.css I get a red background in both 'Printer-friendly version' and 'PDF version'. I expected that.
Leaving the above CSS in (red bg) and setting Custom stylesheet to: %t/css/print.css
B - When I add body {background:#00F;} to sites/all/themes/mytheme/css/print.css I get a blue background in both 'Printer-friendly version' and 'PDF version'.
C - But, at one point before that, I added body {background:#0F0;} to sites/all/themes/mytheme/print.css and I got a green background in 'Printer-friendly version' and a blue background in 'PDF version'.
I have deleted sites/all/themes/mytheme/print.css and flushed the caches numerous times and now I seem to be getting consistent results as described in B.
p.s. I tried the code in #11 but it didn't help - it actually breaks what works right now.
Comment #14
Dinis CreditAttribution: Dinis as a volunteer commented+1 here, unable to get any custom styling for the PDF version to work, though it works correctly with the 'Printer' version.
Comment #15
sonfdAlso experiencing this issue. Weirdly enough on my dev environment the styles get applied to the PDF version, but after deploying to another environment the styles are only applied to the printer friendly version. I suspect it has something to do with the server / file permissions?
I also see the following when clearing cache:
I'm using dompdf, btw.
I also don't get images. Although the broken image is linked and if I click it it takes me to the actual image file in perfect condition on the server.
Comment #16
sonfdHey all,
My issue was linked to a php setting: allow_url_fopen. I think this needs to be on, but it's a security risk, so it's disabled on most servers and is recommended disabled by drupal. The two big issues for me were Images and CSS. Here's how I was able to work around this issue:
Images: There's an option at admin/config/user-interface/print/pdf to "Access images via local file access". I enabled it because the issues in the help text aren't issues for me.
CSS: I dropped my css into a
tag in the header of the html (e.g. print[--whatever].tpl.php) BOOM! PDF styled just how I wanted it originally!Comment #17
marcoka CreditAttribution: marcoka commentedi use TCPFD. the setting doesnt help.
i also hacked the css a inside the module directory to be sure that the code is working. the changes dont work.
i call www.foo.de/printpfd/viewname
maybe it is because it is a view?
i will try to include my css directly in the template next
Comment #18
marcoka CreditAttribution: marcoka commentedok here is my results:
- mPdf with 2.x dev works nice. i just copied it in and boom. like 1 minute config
- dompdf...well so bad. Had it working when copying the font files manually around. images missing. 1 hour 100% fail
- TCPDF. Everything BUT the css worked. Wasnt able to get any styling (hacked module css, created a custom one, used the settings..nothing). 2 hours trying to get the css to work. fail.
Comment #19
drupal_lib CreditAttribution: drupal_lib commentedGreat module! I am having trouble getting it to "find" my custom CSS. I have tried different variations in the common settings > custom stylesheet, such as the full path to the print.css file and %t/print.css, and it doesn't seem to be working. Any suggestions? Thanks.
Comment #20
cslevy CreditAttribution: cslevy commentedComment #21
cslevy CreditAttribution: cslevy commentedComment #22
annetee CreditAttribution: annetee commentedI'm having the same issue as everyone else, custom CSS for PDFs is working locally and the path to the custom CSS file is correct but the CSS isn't included when I test on dev/production environments on a remote server. From this issue and https://www.drupal.org/node/2042061 I've gathered that the server isn't able to read the CSS file when the PDF is being generated, and I'm not sure how to resolve this actual issue. That said, a (slightly terrible) workaround is to include custom CSS in
<style>
tags within the custom template. To avoid pasting my entire CSS file I was able to make this work:Yikes...at least it's working I suppose! Note that my custom CSS file is located within my custom module that also holds my custom template.
Comment #23
sonfdI ended up tracking down my issue. The dev servers are password protected in a fashion similar to: http://www.htaccesstools.com/articles/password-protection/. Removing this password protection seemed to resolve this.
Comment #24
jcloys CreditAttribution: jcloys as a volunteer commentedI was able to fix by applying the patch in comment #20 and setting the custom stylesheet path using the entire path and not the macros.
Comment #25
charginghawk CreditAttribution: charginghawk at Genuine commentedI ran into this issue when I was using a custom module to generate a PDF from a form in a block, using
pdf_using_mpdf_api()
in a submit handler.Due to
pdf_using_mpdf_api()
usingglobal $theme_path;
, and this running headlong into #194098: path_to_theme() returns path to module that calls it,pdf_using_mpdf_api()
was looking for my css file in the blockreference module. My solution was to run:$GLOBALS['theme_path'] = drupal_get_path('theme', $GLOBALS['theme_key']);
before running
pdf_using_mpdf_api()
.Comment #26
nubeli CreditAttribution: nubeli commentedThe patch in #20 doesn't work for me. I think the issue is that after the patch writes the stylesheet, the next line is writing HTML including the . I think that overwrites the stylesheet (see https://mpdf.github.io/css-stylesheets/introduction.html#using-a-stylesheet). But if I change it to (so it only prints the body):
then it doesn't print the print template head. I also tried putting the stylesheet after writing the $mpdf->WriteHTML($html); and that doesn't seem to work either. I may just have to print stylesheet directly in the template until I've got more time to fiddle with this.
Comment #27
crutch CreditAttribution: crutch commented#20 did work for me on patched 2.x-dev and mPDF library using
%t/css/print.css
in the custom stylesheet field, disable "keep current theme css", re-save theme at appearance/theme and flush all caches.I just don't know how to handle div elements
display:inline-block;verticle-align:top;
. Seems to be some inconsistency between html and pdf for inline-blocks but this would be a separate issue probably for mPDF specifically.Comment #28
hkirsman CreditAttribution: hkirsman commentedDidn't work for so added more code + %t parsing
Comment #29
jcnventura CreditAttribution: jcnventura at 1xINTERNET commentedI'm confused why you on error, a
drupal_set_message()
is logged, but then the stylesheet is still included and added to the PDF object.Comment #30
anoopsingh92Hello, I am working on this issue. I will provide the patch. Thanks
Comment #32
anoopsingh92Hello,
I am trying to apply patch #20 but it is not working for me.
I am getting these errors.
Thanks
Comment #33
anoopsingh92Hello,
I have fixed all these issues from this.
Thanks
Comment #34
anoopsingh92Hello,
I have fixed a lot of issues but some issues are still pending. I am listing all pending issues here. I will provide the patch for this.
Thanks
Comment #35
anoopsingh92Hello,
I have fixed some issues in this Patch. Please review this.
Thanks
Comment #36
anoopsingh92I am still working on the remaining issues.
Comment #38
anoopsingh92Hello,
I am still working on the remaining issues of this.
I will come back with the patch shortly.
Thanks
Comment #39
anoopsingh92Hello,
I have fixed most of the issues only the listed issues are pending.
Providing the latest patch shortly.
Thanks
Comment #40
anoopsingh92Hello,
I have fixed most of the issues in this patch please review it.
Thanks
Comment #41
anoopsingh92