Copy link to clipboard
Copied
I am using the below code to generate a PDF. The top part of the page is an image but there is whitespace while placing the image in the generated PDF. How do i remove the whitespace from the PDF. Any suggestions? Please find the code snippet below. Attached the CURRENT.JPG and EXPECTED.JPG images. In the current you can find a portion marked in red which i need to remove. The PDF should look exactly like the expected.JPG
<cfdocument pagetype="legal" format="PDF" marginbottom="0" margintop="0" marginleft="0" marginright="0" >
<table border=0 cellspacing=0 cellpadding=0 height=200>
<tr><td valign=top align=left>
<img src="https://www.getinge-training.com/images/TopHeader.jpg" width="1429" height="496" border=0>
<br><br><br><br><p align=center><font size=10>NAME OF THE PERSON</td></tr>
</table>
</cfdocument>
There are a couple of problems, and at least one solution.
The problem is in the fact that the border you see is actually an html margin (for the implicit body) of 8 pixels, on the top, left, right, and bottom. You can see it if you just remove the cfdocument tag and view the HTML in a browser.
And on the surface, you should be able to change that/those margins, such as with css setting the body margin to 0. But you will find that while doing that makes that border go away in a browser, it d
...It seems to work well with the body margin 0:
<cfhtmltopdf marginBottom='0' marginLeft='0' marginRight='0' marginTop='0' orientation="portrait" pageType="letter" saveAsName="PersonsName" >
<html>
<head>
<style>
body { margin:0; }
</style>
</head>
<body>
<img src="https://www.getinge-training.com/images/TopHeader.jpg" width="1429" height="496" border="0">
</body>
</html>
</cfhtmltopdf >
Hi @Sandhya231275905kpl ,
Two suggestions:
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src=""https://wwwCopy link to clipboard
Copied
There are a couple of problems, and at least one solution.
The problem is in the fact that the border you see is actually an html margin (for the implicit body) of 8 pixels, on the top, left, right, and bottom. You can see it if you just remove the cfdocument tag and view the HTML in a browser.
And on the surface, you should be able to change that/those margins, such as with css setting the body margin to 0. But you will find that while doing that makes that border go away in a browser, it does NOT go away in the cfdocument. This is just a limitation of the very old internal browser engine that CF has embedded since CFDocument was added at the turn of the century (called the ICE Browser).
So instead, as you may know, CF11 added a NEW way to generate PDFs in CFML, using cfhtmltopdf instead of cfdocument. And indeed, if you switch the cfdocument (open and close tags) to cfhtmltopdf, the border will be gone. And you don't even need to modify your HTML at all (no need of a body tag or styling of its margin).
Sometimes, we just have to let go of cfdocument and consider using cfhtmltopdf when possible. Note that it does rely on a separate "ColdFusion add-on service" that needs to be running and can be installed along side CF or installed separately, both of which would by default run the add-on service on the same machine as CF (but it can be installed on yet another machine). Then the CF Admin has a "PDF Service" page that points CF at that add-on service (and has buttons for starting and verifying the connection from CF to that service).
Let us know if that may work for you. If not, I am sure others will chime in with still more possibilities for you to consider.
Copy link to clipboard
Copied
Thanks for the reply. I used cfhtmltopdf (code snippet below) where it looks better but there are still few pixels shown on left and top. The requirement is to show an image in the PDF certificate. Is there anything else i should do to avoid the whitespace. Also attached the generated PDF.
<cfhtmltopdf marginBottom='0' marginLeft='0' marginRight='0' marginTop='0' orientation="portrait" pageType="letter" saveAsName="PersonsName" >
<img src="https://www.getinge-training.com/images/TopHeader.jpg" width="1429" height="496" border="0">
</cfhtmltopdf >
Copy link to clipboard
Copied
It seems to work well with the body margin 0:
<cfhtmltopdf marginBottom='0' marginLeft='0' marginRight='0' marginTop='0' orientation="portrait" pageType="letter" saveAsName="PersonsName" >
<html>
<head>
<style>
body { margin:0; }
</style>
</head>
<body>
<img src="https://www.getinge-training.com/images/TopHeader.jpg" width="1429" height="496" border="0">
</body>
</html>
</cfhtmltopdf >
Copy link to clipboard
Copied
This worked great. Thank you.
Copy link to clipboard
Copied
Hi @Sandhya231275905kpl ,
Two suggestions:
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src=""https://www.getinge-training.com/images/TopHeader.jpg" width="1429" height="496" border="0"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><p align="center"><font size="10">NAME OF THE PERSON</font></p></td>
</tr>
<cfdocument pagetype="legal" format="PDF" marginbottom="0" margintop="0" marginleft="0" marginright="0" ><div style="position:relative;margin-top:-0.11in;margin-left:-0.07in;margin-bottom:-0.06in;margin-right:-0.08in;width:100%;">
<table border="0" cellspacing="0" cellpadding="0">
...
</table>
</div>
</cfdocument>Copy link to clipboard
Copied
This solution worked great too. Thank you 🙂
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more