Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-20157

Text color and background are not preserved by default when exporting to PDF

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 14.9
    • 14.4.4
    • Export - PDF
    • None
    • Unknown
    • N/A
    • N/A

    Description

      The new PDF export is using the browser's print function to generate the PDF, which means the @media print styles are applied on the exported content. Bootstrap removes text colors and backgrounds when printing:

      print.less
      @media print {
        *,
        *:before,
        *:after {
          color: #000 !important; // Black prints faster: h5bp.com/s
          text-shadow: none !important;
          background: transparent !important;
          box-shadow: none !important;
        }
        ...
      }
      

      This makes sense when using a real printer, but it's not expected when generating the PDF. We need to find a way to distinguish in the CSS/LESS files between the case when a page is printed to paper (a real printer) or printed to PDF. The text color and backgrounds should be preserved in the second case.

      The current workaround is to duplicate styles in the PDF export template and to use !important in lots of places.

      Note that the browser is also adjusting the colors used in order to generate a print friendly version, but we can prevent it with:

      PDF Template
      @media print {
        /* Browsers try to improve the contrast in order to generate print-friendly PDFs and for this they change the colors
          we specify in CSS. The following rules tell the browser to preserve our colors. */
        * {
          -webkit-print-color-adjust: exact;
          print-color-adjust: exact;
        }
        ...
      }
      

      An idea would be to add an option to the PDF export to express whether the generated PDF should be print-friendly (the current behavior) or not (preserve colors and backgrounds as it).

      Attachments

        Issue Links

          Activity

            People

              mflorea Marius Dumitru Florea
              mflorea Marius Dumitru Florea
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: