Skip to main content
itisdesign
Inspiring
December 14, 2009
Question

Bug #81169 - Div bkgrnd color (of 1st div w/ content) not honored if cfdocument/pdf written to disk

  • December 14, 2009
  • 1 reply
  • 485 views

Bug for: Div background color (of 1st div w/ content) is not honored when cfdocument/pdf is written directly to disk.

==================
Steps to reproduce
==================

Run the following code with (and without) the cfdocument 'name' attribute.  Then compare both PDFs (the PDF written directly to browser, and the PDF written directly to disk)

<cfdocument format="pdf" name="myPDF">
<div style="background-color:#1a9cee;"></div>
<div style="background-color:#1a9cee; border:2px solid #1a9cee;">I am the 1st div w/ content. Background color is only honored when PDF is written to browser. When PDF is written to disk, background color is near black.</div>
<div style="background-color:#1a9cee; border:2px solid #1a9cee;">I am the 2nd div w/ content. Background color is always honored.</div>
</cfdocument>

<cfif structKeyExists(variables, "myPDF")>
  <cfpdf action="write" source="variables.myPDF" destination="#expandPath('./MyPDF.pdf')#" overwrite="yes" />
</cfif>

==================
Attachments

==================

PDF written directly to disk: 20091214_Bug_81169_CFDocumentPDFDivBkgrndColorNotHonored_01.pdf

PDF written directly to browser: 20091214_Bug_81169_CFDocumentPDFDivBkgrndColorNotHonored_02.pdf

Thanks!,

-Aaron Neff

Btw, this bug is new to CF9.  This bug did not affect CF 8.0.1.

    This topic has been closed for replies.

    1 reply

    itisdesign
    Inspiring
    December 16, 2009

    Ok, if anyone else is experiencing this same issue, here is a workaround.  The issue is that when a cfdocument-generated PDF is written directly to disk, then the background color of the 1st non-empty block-display HTML element is ignored (unless there is an inline-display HTML element preceding it).  Instead, the background color is near-black.

    So, the workaround is to simply ensure an inline-display HTML element preceds the problematic block-display HTML element.  (a <span></span> will do the trick)

    Here was the original code.  Note that line #3 is the 1st non-empty HTML element, and that it is a div (block-display), and it has a background color.  If the PDF is written to disk, then the specified background color is ignored.  Instead, the background color is near-black.  Again, this does not occur when the PDF is written directly to browser.

    1| <cfdocument format="pdf" name="myPDF">
    2| <div style="background-color:#1a9cee;"></div>

    3| <div style="background-color:#1a9cee; border:2px solid #1a9cee;">I am the 1st non-empty block-display HTML element. Background color is only honored when PDF is written to browser. When PDF is written to disk, background color is near black (unless preceded by an inline-display HTML element).</div>
    4| <div style="background-color:#1a9cee; border:2px solid #1a9cee;">I am the 2nd div w/ content. Background color is always honored.</div>
    5| </cfdocument>

    6| <cfif structKeyExists(variables, "myPDF")>
    7|   <cfpdf action="write" source="variables.myPDF" destination="#expandPath('./MyPDF.pdf')#" overwrite="yes" />
    8| </cfif>

    Here is the 'fixed' code (note that "display:inline" has been added to line #2):

    1| <cfdocument format="pdf" name="myPDF">
    2| <div style="background-color:#1a9cee; display:inline;"></div>

    3| <div style="background-color:#1a9cee; border:2px solid #1a9cee;">I am the 1st non-empty block-display HTML element. Background color is only honored when PDF is written to browser. When PDF is written to disk, background color is near black (unless preceded by an inline-display HTML element).</div>
    4| <div style="background-color:#1a9cee; border:2px solid #1a9cee;">I am the 2nd div w/ content. Background color is always honored.</div>
    5| </cfdocument>

    6| <cfif structKeyExists(variables, "myPDF")>
    7|   <cfpdf action="write" source="variables.myPDF" destination="#expandPath('./MyPDF.pdf')#" overwrite="yes" />
    8| </cfif>

    magical