4 Replies Latest reply on Aug 7, 2017 4:04 PM by joellet12206649

    cfhtmltopdf and css paged media limitations

    joellet12206649 Level 1

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

        • 1. Re: cfhtmltopdf and css paged media limitations
          Jamo Level 2

          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.)

          • 2. Re: cfhtmltopdf and css paged media limitations
            joellet12206649 Level 1

            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

            • 3. Re: cfhtmltopdf and css paged media limitations
              Jamo Level 2

              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.

              • 4. Re: cfhtmltopdf and css paged media limitations
                joellet12206649 Level 1

                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.