Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
My understanding is that the print.css file should style all the PDF as well as printer friendly versions of output from the module by default. But like others, my PDFs are not getting styled. I saw a few other tickets about this issue, but none of the proposed solutions seemed to work with TCPDF. Does anyone know of a solution that does?
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#17 | print-add-custom-pdf-css-1230480.patch | 2.55 KB | cobenash |
Comments
Comment #1
paulen CreditAttribution: paulen commentedCan't get it working in dompdf either for that matter.
Comment #2
jcnventura CreditAttribution: jcnventura commentedIt works fine in dompdf. However, TCPDF seems to only load CSS when loading the HTML text from a file..
From the documentation, it seems to be able to handle CSS if it is inlined.. I've a (very dirty) hack to inline the CSS (which works well if there's no @include directives), in the print_mail module that could probably be used here..
Comment #3
jcnventura CreditAttribution: jcnventura commentedCommitted to 7.x-2.x-dev a mechanism to inline the CSS when creating a PDF.
Comment #5
george.plescan CreditAttribution: george.plescan commentedCould you please explain how to make the CSS work. I have the latest version, but the CSS it not being used.
I have put sites/all/modules/print/css/print.css in the Custom stylesheet settings and still nothing.
Thank you.
Comment #6
jcnventura CreditAttribution: jcnventura commentedI was never able to make the CSS work in TCPDF, and I can't understand why. Even though it's passed inline, and so something like example 61 (http://www.tcpdf.org/examples/example_061.phps) should have worked. Every other lib seems to be able to include CSS.
It seems to be some bug with TCPDF, which should be reported to the maintainer.
Comment #7
jcnventura CreditAttribution: jcnventura commentedNo further info in two weeks. Closing the issue again.
Comment #8
cornel.eftimie CreditAttribution: cornel.eftimie commentedHi all, maybe this would help:
with this
I have used it only for hiding some elements and it works fine.
I suppose you could add some other css code before /head
Good luck!
Comment #9
msypes CreditAttribution: msypes commentedI'm looking for solutions to this as well.
Comment #8 didn't change anything for me. I have no indication that the copied function overrides the module's version, i.e., I don't think it's being called at all.NB: Interesting finding, probably documented elsewhere, but I'll post it here in case it helps as well. The overriding function you create must be in your main theme. Initially I was trying this with an administrative view, so put the css and code into that theme's template.php file. Only when I moved them to the main theme did everything work as expected.
Comment #10
dbassendine CreditAttribution: dbassendine commentedI found the styling would not apply to TCPDF either, and I did some testing using the print_pdf.tpl.php template to see where styles would or would not apply:
I'm not clear why an external stylesheet included at this stage works, but it doesn't when referenced in the template HEAD. This definitely needs to be fixed in the default theme function, as TCPDF styling is just not working right now. Perhaps we use the #8 snippet and include:
Would this be the right approach, do you think?
Thanks, David
Comment #11
hockey2112 CreditAttribution: hockey2112 commentedWhen I follow the steps in #8, I receive this error:
I wonder if I did something wrong when copying the code over to the theme's template.php file. This is what I added, at the end of that file:
Does any of that look "off"?
Comment #12
mxlav CreditAttribution: mxlav commentedneed to change your're function name from
theme_print_pdf_tcpdf_content
tofusion_starter_print_pdf_tcpdf_content
?Note I also tried #8 and it picked up the new css..altought it is ignoring a lot of stuff like padding, alignments ets...
Comment #13
gaurav.goyal CreditAttribution: gaurav.goyal commentedI am using the below code, but still css is not applied on the downloaded pdf.
(.*)!sim', $vars['html'], $matches);
$pattern = '!(?:
|
)!si';
$matches[1] = preg_replace($pattern, '', $matches[1]);
// Make CCK fields look better
$matches[1] = preg_replace('!(
$matches[1] = preg_replace('!(
)\s*!sm', '$1', $matches[1]);
$matches[1] = preg_replace('!
!sm', '', $matches[1]);
// Since TCPDF's writeHTML is so bad with
, do everything possible to make it look nice
$matches[1] = preg_replace('!<(?:p(|\s+.*?)/?|/p)>!i', '
', $matches[1]);
$matches[1] = str_replace(array('
'), $matches[1]);
do {
$prev = $matches[1];
$matches[1] = preg_replace('!()
(\s*?
)!s', '$1$2', $matches[1]);
} while ($prev != $matches[1]);
@$pdf->writeHTML('
' . $matches[1]);return $pdf;
?>
Comment #14
gaurav.goyal CreditAttribution: gaurav.goyal commentedPlease Ignore the above code.
I am using the below code, but still css is not applied on the downloaded pdf.
$pdf = $vars['pdf'];
// set content font
$pdf->setFont($vars['font'][0], $vars['font'][1], $vars['font'][2]);
preg_match('!(.*)!sim', $vars['html'], $matches);
$pattern = '!(?:
|
)!si';
$matches[1] = preg_replace($pattern, '', $matches[1]);
// Make CCK fields look better
$matches[1] = preg_replace('!(
$matches[1] = preg_replace('!(
)\s*!sm', '$1', $matches[1]);
$matches[1] = preg_replace('!
!sm', '', $matches[1]);
// Since TCPDF's writeHTML is so bad with
, do everything possible to make it look nice
$matches[1] = preg_replace('!<(?:p(|\s+.*?)/?|/p)>!i', '
', $matches[1]);
$matches[1] = str_replace(array('
'), $matches[1]);
do {
$prev = $matches[1];
$matches[1] = preg_replace('!()
(\s*?
)!s', '$1$2', $matches[1]);
} while ($prev != $matches[1]);
@$pdf->writeHTML('
' . $matches[1]);return $pdf;
Comment #15
NIKS_Artreaktor CreditAttribution: NIKS_Artreaktor commentedgaurav.goyal - read carefully #8
you didn't change function - step 3.
and fix carefully "your_theme" in drupal_get_path('theme', 'your_theme')
----------------------------------------------------------------------------------
And want to say to everyone who tried fix in #8 and didn't get result - first time i didn't get result
i did everything right, but i don't know why it gave not effect.
After i install
mPDF library handler
and library
and tried to change to use TCPDF again - i so that it changed...
so be attentive - to don't get my mistake - check changes carefully.
thanks for fix.
P.S.
mPDF library - it seams to me better
- utf-8 (unicode) - Okey
- images - it seems to me more original ( in TCPDF - it was like bigger because of wrong sizes and quality of image was worse).
Comment #16
j.johnson.bbt CreditAttribution: j.johnson.bbt commentedNot getting this to work. Tried this at the bottom of my theme template.php file but no success. What's wrong?
Comment #17
cobenashThis Patch provide custom pdf css settings.
Go to /admin/config/user-interface/print/pdf/tcpdf
Input the custom pdf css path and then tcpdf will get the css file.