CFDOCUMENT inserts some margin on left and right even if set to 0

899 Views Asked by At

I have this code running in Coldfusion 11.

<cfset fileName = "test.pdf">
<cfcontent type="application/pdf" reset="true">
<cfheader  name="Content-Disposition" value="attachment; filename=#fileName#">
<cfdocument localurl="yes" format="pdf" pagetype="letter" margintop=".5" marginbottom=".5" marginright="0" marginleft="0" orientation="portrait" unit="in" backgroundvisible="yes" overwrite="yes" fontembed="no">
    <cfdocumentsection>
        <div style="width:100%; background-color: #cccccc; margin: 0 0 0 0;padding: 0 0 0 0;">
            <h1>Hello World!</h1>
        </div>
    </cfdocumentsection>
</cfdocument>

This produces a PDF like this: enter image description here

The problem is that I have set the margin and padding of the div to 0 but still there is some space on the left and right.

Is there a way to remove this space programmatically so that the background spans the complete width of the page?

Update(7th August 2017)

I have updated the code as per comment/suggestion from James Moberg. But the issue still persists. Here is the updated code

<cfset fileName = "test.pdf">
<cfcontent type="application/pdf" reset="true">
<cfheader  name="Content-Disposition" value="attachment; filename=#fileName#">
<cfdocument localurl="yes" format="pdf" pagetype="letter" margintop=".5" marginbottom=".5" marginright="0" marginleft="0" orientation="portrait" unit="in" backgroundvisible="yes" overwrite="yes" fontembed="no">
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Test</title>
        <meta http-equiv=Content-Type content="text/html; charset=windows-1252" />
        <meta name=Generator content="Microsoft Word 12 (filtered)" />
    </head>
    <body style="margin: 0;padding: 0;">

    <cfdocumentsection>
        <div style="width:100%; background-color: #cccccc; margin: 0;padding: 0;">
            <h1>Hello World!</h1>
        </div>
    </cfdocumentsection>

    </body>
    </html>
</cfdocument>
1

There are 1 best solutions below

0
camilogr On

Try this, I have been able to create full custom pdf grids with coldfusion using css relative and absolute positions. Replace your cfdocumentsection with the following.

<cfdocumentsection>
  <div style="position:relative;left:-0.06in;width:102%;">
    <div style="background-color:#cccccc;">
        <h1>Hello World!</h1>
    </div>
    <div style="background-color:red;">
        <h1>Hello World!</h1>
    </div>
  </div>
</cfdocumentsection>