Copy link to clipboard
Copied
Hi,
I am using ColdFusion 2018. I am printing a word document (dynamic) using the below code. But there are multiple issues. One is that the image (please refer screenshot) is not aligned. I want the image to be placed on top on extreme left and top (topmargin=0 and leftmargin=0). Also after the image i am placing a text which is not displayed in the generated word document. Please help. If there is a better way to generate word document in coldfusion please post that too.
<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>
<cfheader name="content-disposition" VALUE="attachment; filename=1.doc">
<cfoutput>
<table border="0" cellpadding="0" cellspacing="0">
<cfset type="application/msword">
<tr>
<td><img src="https://www.getinge-training.com/images/TopHeader.jpg" width="1429" height="496" border="0"></td>
</tr>
<tr>
<td>PERSON NAME</td>
</tr>
</table>
</cfoutput>
</body>
</html>
@Sandhya231275905kpl , l shall say it again: all of these attempts (with an HTML table, cfheader with Word Content-Disposition, styles, etc.) will NOT produce the display you want. It is well-nigh impossible for the margins that you set in HTML to carry over to MS Word.
Imagine you wish to frame a picture. Obviously, the dimensions and aspect-ratio of the frame and mat board will be the factors that determine how well your picture will fit.
You may be able to adapt the picture's dimensions. B
...Copy link to clipboard
Copied
ColdFusion is irrelevant to your question, as your script contains no ColdFusion code. Ignoring cfheader, your script is basically HTML. So you should sort out the alignment in HTML first, preferably before any ColdFusion intervention.
For a start, the HTML is confusing. Reasons:
Copy link to clipboard
Copied
Hello,
I am pasting the updated code below. As you mentioned that ColdFusion is irrelevent, same way those errors are irrelevent as it will not make any difference to the code. I hope you understood the solution that i am looking for (thanks for spending some time to find some mistakes in my dirty code through). I hope anybody who look at the screenshot will know what i am looking for. To make you happy I added some coldfusion code even then it is the same result. Please help only if you understood the requirement, else do not comment so that it will leave it open for others to give some suggestions that i am looking for.
<CFQUERY NAME="getreg" datasource="#client.datasource#">
SELECT fname,lname FROM reg WHERE reg_id = 39027
</CFQUERY>
<html>
<head>
<style> body { margin:0; } </style>
</head>
<body topmargin=0 leftmargin=0>
<cfheader name="content-disposition" VALUE="attachment; filename=1.doc">
<cfoutput>
<table border="0" cellpadding="0" cellspacing="0">
<cfset type="application/msword">
<tr>
<td><img src="https://www.getinge-training.com/images/TopHeader.jpg" width="1429" height="496" border="0"></td>
</tr>
<tr>
<td>#getreg.fname#</td>
</tr>
</table>
</cfoutput>
</body>
</html>
Copy link to clipboard
Copied
As you mentioned that ColdFusion is irrelevent, same way those errors are irrelevent as it will not make any difference to the code.
By @Sandhya231275905kpl
I would disagree. HTML is tolerant and flexible. If you make a mistake in HTML, browsers will likely ignore them and display the page in the best way they can.
I tested your script as follows:
1) I created a 1429 px by 496 px copy of your image and placed it in the same directory as the test CFM page.
2) I created test.cfm, which contains:
<html>
<head>
<style> body { margin:0; } </style>
</head>
<body topmargin=0 leftmargin=0>
<cfheader name="content-disposition" VALUE="attachment; filename=1.doc">
<cfoutput>
<table border="0" cellpadding="0" cellspacing="0">
<cfset type="application/msword">
<tr>
<td><img src="http://localhost:8500/workspace/CF_Project/TopHeader.jpg" width="1429" height="496" border="0"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</cfoutput>
</body>
</html>
3) I ran test.cfm. The result is a Word page in which the image is located in the top-left corner. (image of result attached)
Copy link to clipboard
Copied
Tried, getting the same result. Look like your output is in web layout. See if you get the proper output by seeing the word content in "Print Preview" with ruler enabled. I think I will have to work on something more to fix this as i don't see any difference from my code.
Copy link to clipboard
Copied
I have attached the print-preview. Is it what you expect?
Have you considered my suggestion? Reminder:
1. Create the HTML page, using the necessary styles to position the image and page elements.
2. Get the HTML page to display precisely as you want.
3. Introduce CFML code into the mix only after 2.
I am not preaching. I myself have been using this method for years.
Copy link to clipboard
Copied
There is whitespace in the print preview, this is not what i am looking for. I am expecting the output like this (attached) where there is no whitespace on left, right, top. Bottom i will fill in with some more content using coldfusion cfquery. In the preview you can see that the image is filled in the page width completely where there is no whitespace left off.
Copy link to clipboard
Copied
How did you create this version that has your desired perfect alignment? With Word, not involving html? As bkbk noted, this doesn't seem a cf issue, unless you are saying you created an html page which "works perfectly", but then changes when served via cf, without any change (and even without cfml)
Fwiw, we discussed in another thread last week the same image/page formatting, which we helped you solve as a pdf. Now you're moving on to a word document. As you can see, we do try to help.
I suspect you just wish we'd offer the answer rather than engage in "20 questions" and troubleshooting. If we had it, we would. And if you wait long enough, others may.
If you feel we've hit a roadblock and you need in our from more people, there are still other places you can ask for CF help, which I list in a category of my cf411.com site, cf411.com/cfhelp.
Copy link to clipboard
Copied
Thank you is all i can reply.
Copy link to clipboard
Copied
I managed to print the content in word using the below code. Still there is whitespace on top and left which i wanted to avod (please see screenshot). Please reply if anyone can help.
<CFQUERY NAME="reg" datasource="#client.datasource#">
SELECT first_name,last_name,credential FROM registration
WHERE registration_id = #url.id#
</CFQUERY>
<CFQUERY NAME="req" datasource="#client.datasource#">
select city,state from evh_request where event_id=#url.eventid#
</CFQUERY>
<html>
<head>
<title>Certificate</title>
<style>
body { margin:0; margin-left: 0px;margin-top: 0px;}
.normaltxt { font-family: Arial, Helvetica, Sans-serif;font-size: 25px; border: none;FONT-WEIGHT: normal; }
.namebold { font-family: Arial Black, Helvetica, Sans-serif;font-size: 52px; border: none;FONT-WEIGHT: bold;}
.boldtxt { font-family: Arial Black, Helvetica, Sans-serif;font-size: 28px; border: none;FONT-WEIGHT: bold; }
</style>
</head>
<body>
<cfheader name="content-disposition" VALUE="attachment; filename=1.doc">
<cfset type="application/msword">
<table border=0 cellspacing=0 cellpadding=0 width=200>
<tr><td><img src="https://www.getinge-training.com/images/TopHeader.jpg" width="630" height="220" border="0"></td></tr>
<tr><td></td></tr><tr>
<td align=center height=140 valign=middle><font class="normaltxt">This certificate is to confirm</font>
</td></tr>
<tr><td align=center height=180 valign=middle><font class="namebold"><cfoutput>#reg.first_name# #reg.last_name# #reg.credential#</cfoutput></font></td></tr>
<tr><td align=center height=120 valign=top><font class="normaltxt">attended a didactic presentation and<br>received cadaver laboratory training on<br>Endoscopic Vessel Harvesting utilizing the<br><br></font></td></tr>
<tr><td align=center height=130 valign=middle><font class="boldtxt">Vasoview® Endoscopic Vessel Harvesting System<font></td></tr>
<tr><td align=center height=150 valign=middle><font class="normaltxt"><cfoutput>#DateFormat(Now(),"mmmm d, yyyy")#</cfoutput><br><cfoutput>#req.City#, #req.state#</cfoutput><br></td></tr>
<tr> <td align=left height=60 valign=bottom> <img src="https://www.getinge-training.com/images/signature.jpg" width="345" height="110" border="0"></td> </tr>
</table>
</body>
</html>
Copy link to clipboard
Copied
I would merely repeat my last comment. Please reconsider it.
Copy link to clipboard
Copied
@Sandhya231275905kpl , l shall say it again: all of these attempts (with an HTML table, cfheader with Word Content-Disposition, styles, etc.) will NOT produce the display you want. It is well-nigh impossible for the margins that you set in HTML to carry over to MS Word.
Imagine you wish to frame a picture. Obviously, the dimensions and aspect-ratio of the frame and mat board will be the factors that determine how well your picture will fit.
You may be able to adapt the picture's dimensions. But there is a limit to how the picture can affect the mat board and frame. In fact, the frame is fixed and determines the required size and aspect ratio of the picture, not vice versa.
This analogy carries over to your code. The HTML output corresponds to the picture, with or without mat board. MS Word (independent software unrelated to CF) supplies the fixed frame. MS Word may supply headers, footers or margins that you cannot anticipate in the HTML.
What your HTML code is doing is, simply, streaming HTML output to the browser. The Content-Disposition header tells the browser to offer the content as a downloadable MS Word file rather than display it inline.
That's it. Just as the picture in our frame analogy has limited influence on the dimensions of the frame and mat board, so too HTML has limited influence on the footers, headers, margins, styling, etc. that MS Word may impose.
What to do then?
Your best bet is to avoid the table tag. Use divs instead.
A simple example to demonstrate:
<html>
<head>
<cfheader name="content-disposition" value="attachment; filename=1.doc">
</head>
<body style="margin-top: 0in">
<div style="margin-left:-1.0in;margin-right:-1.0in;">
<img src="http://localhost:8500/workspace/CF_Project/TopHeader.jpg" border="0" width="1429" height="496" style="max-width:100%;">
</div>
</body>
</html>
Copy link to clipboard
Copied
If the automated generation of this document (a certificate) is as important to you as I think it is, then you should use a specialist library to generate the doc or docx file. For example, Apache POI.
Copy link to clipboard
Copied
I have yet another suggestion. Use the method that most learning institutions use to print their certificates.
I consider that to be the best solution.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more