【问题标题】:CFDOCUMENT inserts some margin on left and right even if set to 0即使设置为 0,CFDOCUMENT 也会在左右两边插入一些边距
【发布时间】:2017-08-05 06:32:55
【问题描述】:

我在 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>

这会产生一个像这样的 PDF:

问题是我已经将 div 的边距和内边距设置为 0,但左右仍然有一些空间。

有没有办法以编程方式删除此空间,以便背景跨越页面的整个宽度?

更新(2017 年 8 月 7 日)

我已根据 James Moberg 的评论/建议更新了代码。但问题仍然存在。这是更新的代码

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

【问题讨论】:

  • 您没有 BODY 标签。如果您使用浏览器查看,也会有填充/边距。添加边距/填充为“0”的 BODY 并查看它是否有任何区别。 (如果您想要更好的字体/CSS/SVG/边框支持,请查看 WKHTMLTOPDF。我在 CF8-2016 中使用它。)
  • 你好@JamesMoberg,谢谢你的建议。我尝试使用 body 标签,但问题仍然存在。我希望我已经将它与 cfdocumentsection 一起正确使用。我正在编辑一些使用 cfdocument 实现的旧代码。也许从长远来看,我可以考虑使用 WKHTMLTOPDF,但现在我急于对当前功能进行一些更改。
  • 你在body标签中使用了CSS吗? CFDocument HTML 解析器已过时。您可能需要使用 leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0"
  • CFdocument CSS 解析器并不总是“获取”您使用的所有 CSS。试试 "margin-left: 0px; margin-right: 0px;..." 等。也可以尝试 without 标签,这在此处没有多大作用。

标签: coldfusion pdf-generation coldfusion-11 cfdocument


【解决方案1】:

试试这个,我已经能够使用 css 相对和绝对位置创建带有冷融合的完整自定义 pdf 网格。将您的 cfdocumentsection 替换为以下内容。

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

【讨论】:

    猜你喜欢
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    • 2017-02-01
    相关资源
    最近更新 更多