3
votes

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?

2
Check the cfdocument tag attributes, especially pageType and the margin ones.Alex
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
cfdocument has always been a bit quirky. Hate to say it, but you tried the old div hack to add header margin? ie <div style="margin-top: 10px">HEADER</div> .Leigh
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
Weird, it seemed to work for me in a similar environment. Glad you found a work around. Might search the bug database to see if it is a known issue.Leigh

2 Answers

1
votes

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

0
votes

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.