3

I have a PDF that I generate via the CFDocument tag. When it generates the PDF and you click on the "printer" icon to pop up the print dialog. For Page Sizing & Handling if it's set to either "Fit" or "Shrink oversized pages", it prints fine. If "Actual size" is selected then the header gets shifted off the page and gets chopped off. I'm using ColdFusion 11 on Windows 7.

To recreate this, I removed all my styles and did a simple test with the following basic code:

<cfdocument format="PDF" saveAsName="test_#dateFormat(now(),'yyyymmdd')#T#timeFormat(now(),'hhmmss')#.pdf">
   <cfdocumentitem type="header">HEADER</cfdocumentitem>
   <cfdocumentsection>
       BODY
   </cfdocumentsection>
   <cfdocumentitem type="footer">
       #cfdocument.currentpagenumber# / #cfdocument.totalpagecount#
   </cfdocumentitem>
</cfdocument>

Which generates the following PDF: PDF Generated

Then I click the "Printer" icon which pops up the printer settings: Shrink Oversized Pages

If you look closely to the preview image in the dialog box, you can see that the header text is within the document. Now if I select "Actual size" instead, it gives the following: Actual Size

If you look at the preview, this time you can see that everything shifted up and the header is partially outside the document which results in half of the header getting chopped off and illegible when printed.

Anyone know why this is happening and how to fix it?

yaki33
  • 65
  • 2
  • 8
  • 1
    Check the `cfdocument` tag attributes, especially `pageType` and the `margin` ones. – Alex Dec 23 '15 at 23:36
  • The margintop attribute didn't work. All it did was increase the header and made the font bigger. Once I choose "Actual size" it still shifts off the page. I also tried the scale attribute with the same result when I choose "Actual size" – yaki33 Dec 24 '15 at 16:48
  • cfdocument has always been a bit quirky. Hate to say it, but you tried the old div hack to add header margin? ie `
    HEADER
    ` .
    – Leigh Dec 31 '15 at 16:25
  • Yes, I've tried the div trick but that did not work. In the end I ended up adjusting the pageHeight and pageWidth slightly to make it work. – yaki33 Jan 01 '16 at 18:25
  • Weird, it seemed to work for me in a similar environment. Glad you found a work around. Might search the [bug database](http://bugbase.adobe.com) to see if it is a known issue. – Leigh Jan 01 '16 at 20:52

2 Answers2

1

To fix this, I ended up playing around with the pageWidth and pageHeight along with the pageType attributes in CFDocument.

<cfdocument format="PDF" pageType="custom" pageWidth="8.5" pageHeight="10.75" saveAsName="test_#dateFormat(now(),'yyyymmdd')#T#timeFormat(now(),'hhmmss')#.pdf">
   <cfdocumentitem type="header">HEADER</cfdocumentitem>
   <cfdocumentsection>
       BODY
   </cfdocumentsection>
   <cfdocumentitem type="footer">
       #cfdocument.currentpagenumber# / #cfdocument.totalpagecount#
   </cfdocumentitem>
</cfdocument>

Standard letter size is 8.5" X 11" (which is default in CFDocument) so I just slightly adjusted the height to 10.75" and the header stayed within the page boundaries even when I clicked "Actual size" in the print dialog. Seems kind of odd that I have to do this to make the header fit on the page without getting chopped off but it works. Adjusting the height any further just scales the header too much and doesn't look good so I went with 10.75".

yaki33
  • 65
  • 2
  • 8
0

To be honest, using the cfdocument tags for me has been nothing short of brutal. If you can use external tools to do the same (in other words, if your business and sys admins will allow you to use them), I would suggest using WKHTMLToPDF. You can find out more about it here: http://wkhtmltopdf.org/

I have to say we have had great luck with this tool. It also works across platforms if that matters in your environment.

Hope this helps.

Johann S
  • 1
  • 1
  • Yes, I tried WKHTMLToPDF but the problem is that it doesn't handle repeating headers. If the document content overflows to the next page the header will not repeat and would have to be handled manually which is a difficult thing to do given that the data the client enters cannot be predicted and they can have 1 or multiple pages. – yaki33 Jan 01 '16 at 18:27
  • I just looked at the documentation here: https://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html Looks like you can create a repeating header and/or footer. Hope that helps! – Johann S Jan 05 '16 at 17:01