Copy link to clipboard
Copied
Attempting to resolve an issue and I have reduced issue down to simplest form.
<cfhtmltopdf unit="in" marginBottom="1" marginLeft="1" marginRight="1" marginTop="1" orientation="portrait" pageType="letter">
this is a test <cfoutput>#now()#</cfoutput>
</cfhtmltopdf>
The Top Margin in 1 3/16 inch and Left margin in 1 1/16 inch. In my code the margins are 1 5/16 for top and 1 3/16 for left, but we have HTML tags and style that I am thinking I will have to tweak, but the above example should give one inch and one inch on top and left margin and it is not.
Is there anything that I can do to correct this issue? It seems like a PDF service issue to me.
CF ENT 11, update 9 on Windows Server 2012 R2 64 bit.
Copy link to clipboard
Copied
What about your HTML? Have you set the outer containing element (div, table, etc.) to have 0px padding and margin?
V/r,
^_^
Copy link to clipboard
Copied
Please let us know what the issue is. I tested your code with
<cfprocessingdirective suppressWhiteSpace = "yes">
<cfhtmltopdf unit="in" marginBottom="1" marginLeft="1" marginRight="1" marginTop="1" orientation="portrait" pageType="letter">this is a test <cfoutput>#now()#</cfoutput></cfhtmltopdf><cfcontent type="application/pdf">
</cfprocessingdirective>
and then with
<cfprocessingdirective suppressWhiteSpace = "yes">
<cfhtmltopdf unit="in" marginBottom="1" marginLeft="1.1875" marginRight="1" marginTop="1.3125" orientation="portrait" pageType="letter">this is a test <cfoutput>#now()#</cfoutput></cfhtmltopdf><cfcontent type="application/pdf">
</cfprocessingdirective>
I got 2 PDF documents with respective margins (marginLeft=1, marginTop=1) and (marginLeft=19/16, marginTop=21/16), as expected.
Copy link to clipboard
Copied
When I generate the odd with 1 set to all margins the margin is larger than 1 inch. I thought I had explained that in my original post. But that is the problem. No html used at all just the example code I posted margins are off by 1/16 of an inch on left and 3/16 on top
Copy link to clipboard
Copied
Ah, it's clear. Then remove all white space, for example, as in
<cfprocessingdirective suppressWhiteSpace = "yes"><cfhtmltopdf unit="in" marginBottom="1" marginLeft="1" marginRight="1" marginTop="1" orientation="portrait" pageType="letter">this is a test <cfoutput>#now()#</cfoutput></cfhtmltopdf></cfprocessingdirective>
Copy link to clipboard
Copied
The removal of white space had no effect on PDF generation. Still 3/16 of an inch too big.
I removed 3/16 from my margin and resolved my issue for now, but I was wondering if there is a setting in an XML file or something that is messing with this at this point.
This was the solution that got margins to truly be one inch for us:
<cfhtmltopdf unit="in" marginBottom="0.8125" marginLeft="0.8125" marginRight="0.8125" marginTop="0.8125" orientation="portrait" pageType="letter" saveAsName="#l_name#.pdf">
this is a test <cfoutput>#now()#</cfoutput>
</cfhtmltopdf>
Copy link to clipboard
Copied
Hi Matthew,
If you are unable to get the margins you want, then please report a bug.
For the time being, I will recommend the Open Source tool, wkhtmltopdf, if you need hair-sharp accuracy. I shall now give you an example of wkhtmltopdf usage.
My Coldfusion is on a 64-Bit Windows machine, so I downloaded and installed wkhtmltox-0.12.3.2_msvc2013-win64.exe . The executable I wish to use is located at C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe.
I then created 2 files (within same directory under web root):
testFile.cfm
this is a test <cfoutput>#now()#</cfoutput>
html2PDF.cfm
<!--- Set up wkhtmltopdf's header and footer options --->
<cfset wkHTMLToPDFHeader = '--header-spacing 2 --header-left "Header_left_text" --header-right "Header_right_text" --header-font-size 9 --header-line --header-font-name opensans_regular'>
<cfset wkHTMLToPDFFooter = '--footer-left "footer_left_text" --footer-right "footer_right_text" --footer-font-size 9 --footer-line --footer-font-name opensans_regular'>
<!--- Set up all wkhtmltopdf's options --->
<!---
Use
-B or --margin-bottom
-R or --margin-right
-T or --margin-top
-L or --margin-left
-s or --page-size
--->
<cfset wkHTMLToPDFOptions = "-B 25.4mm -R 25.4mm -T 25.4mm -L 25.4mm -s Letter --disable-smart-shrinking " & wkHTMLToPDFHeader & " " & wkHTMLToPDFFooter>
<!--- Current directory relative to web root: /workspace/CF_Project/Pdf/ --->
<cfexecute name="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"
arguments="#wkHTMLToPDFOptions# http://localhost:8500/workspace/CF_Project/Pdf/testFile.cfm #expandpath('result.pdf')#" timeout="10">
</cfexecute>
This creates a PDF (result.pdf) with one-inch margins. NB: 1 inch = 25.4mm. I have included, for the sake of generality, a header and a footer.
As you can see from the wkhtmltopdf documentation, you can do much more besides with this tool. Have fun with it.