• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfhtmltopdf and css paged media limitations

New Here ,
Aug 01, 2017 Aug 01, 2017

Copy link to clipboard

Copied

Are there any known limitation with using CSS paged media or guides on how to style a pdf when using cfhtmltopdf?

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 02, 2017 Aug 02, 2017

Copy link to clipboard

Copied

Do you have sample HTML?  (I'm asking because I use WKHTMLTOPDF w/ColdFusion 8-2016 to generate PDFs and would like to compare results.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

I doubt this would help. My CSS shows fine it's just the @print css media calls are ignored. I also tried to do @media print and those get ignored as well.

I have also looked into WKHTMLTOPDF and it does not go well with my projects work flow. I just need to know if CSS paged media or print css works with cfhtmltopdf. I need 100% control over the style of my PDF created.

print-html.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

We had to adjust our workflow a bit too, but it actually maked it easier to debug as the pre-PDF object is a regular HTML document that we can further review & tweak .  With WKTHMLTOPDF, "Print CSS" is respected.  There's a built-in "Table of Contents" feature that generates a special PDF bookmark hierarchy based on H1-5 tags (default = 4 levels).  You can perform page breaks w/CSS and use CSS to indicate that sections should be kept together.  Page numbers (in the footer) can be dynamically determined using javascript.

    table, tr, td, th, tbody, thead, tfoot {

        page-break-inside: avoid !important;

    }

    .keeptogether {page-break-inside:avoid !important;}

    .pagebreakAfter {page-break-after:always !important;}

    .pagebreakBefore {page-break-before:always !important;}

Are these the features you are looking for?

Regarding "CSS perfection", I don't think you're going to find it using CFDocument.  According to this LearnCFinAWeek document, CFDocument hasn't been updated for 9 years and supports only HTML 4.01, XML 1.0, DOM Level 1 & 2, CSS1 and CSS2 (only 76 supported CSS style).  Five years ago, this was thought to provide 90% coverage of most HTML generation that you;d attempt to do... but none of my clients were impressed with our PDF generation until we switched to WKHTMLTOPDF.  We also greatly reduced our times attempting to tweak the CSS to make it look right as we were usually able to get content looking almost perfect before even performing PDF conversion.https://gist.github.com/learncfinaweek/4121316

I believe CF2016's CFHTMLtoPDF is based on WKHTMLTOPDF, but it's throttled (limited to single user unless you have Enterprise) and access is blackboxed using CFTag language... so some features may be limited to what they make available and you never know when it will be updated.

https://cfdocs.org/cfhtmltopdf

I prefer using WKHTMLTOPDF because I can have concurrent PDF generation occur in the background without using any ColdFusion threads.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2017 Aug 07, 2017

Copy link to clipboard

Copied

LATEST

Ok, thank you for the time and reply.

TL;DR: 'Some features, for CFHTMLtoPDF, may be limited to what they make available and you never know when it will be updated.'

Limitations on CSS print and print media for cfhtmltopdf is currently unknown. Use a third party library or service for 100% control of PDF styles.

Alternatives are WKHTMLTOPDF, PDFreactor, Prince and Antenna House.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation