Copy link to clipboard
Copied
Here is the sample code. The first PDF file is created just fine, but the rest files are missing background image. Similar issue was reported here Very odd CFDOCUMENT Bug | Raymond Camden's Blog, but I could not find a solution to this issue. Would appreciate any input!
<cfloop query = "MyQuery">
<cfdocument format = "PDF" filename="./docs/#filename#"
overwrite="yes"
localurl="true">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
body
{
background-image:url('image.jpg');
background-repeat:no-repeat;
}
</style>
</head>
<cfoutput >
<body>
<table width="100%" cellpadding="0" border=0> | |||||||||||||||
<tr> | |||||||||||||||
<td height="280px" colspan="4"> </TD> | |||||||||||||||
</TR> | |||||||||||||||
<tr valign="top"> | |||||||||||||||
<td align="center" colspan="4"> | |||||||||||||||
<span style="font-size:48; font-family: Calibri; color: black;font-weight: bold;"> | |||||||||||||||
#FirstName# #LastName# | |||||||||||||||
</span><br> | |||||||||||||||
<span style="font-size:25; font-family: Calibri; color: black;font-weight: bold;"> | |||||||||||||||
for the | |||||||||||||||
</span> <br> | |||||||||||||||
<span style="font-size:48; font-family: Calibri; color: black;font-weight: bold; "> | |||||||||||||||
#qNomination.proj_name# Project | |||||||||||||||
</span> | <br> | ||||||||||||||
</td> | |||||||||||||||
</tr> |
</body> |
</cfoutput>
</html>
</cfdocument>
</loop>
The example I have given you would work. It is all dynamic as I will now show.
In the following example, save the 2 CFM files and the image files in the same directory. Then open testFile.cfm in the browser. That will dynamically create 3 PDFs in the current directory
testFile.cfm
<cfloop list= "1,2,3" index="idx">
<cfinclude template="inc.cfm">
</cfloop>
inc.cfm
<cfoutput>
<cfdocument format = "PDF" localurl="true" filename="#expandPath('file#idx#.pdf')#" name="file#idx#" overwrite="true" >
<html>
<body
...Copy link to clipboard
Copied
It is, as you say, an old issue. I am surprised that it remains unsolved even in the current version of ColdFusion.
I have found the following workaround.
1) Save the output of cfdocument, that is, this code:
<cfoutput>
<cfdocument format = "PDF" filename="./docs/#filename#" overwrite="yes" localurl="true">
etc.
</cfdocument>
</cfoutput>
as the page inc.cfm, in the current directory.
2) Replace the content of the current page with
<cfloop query = "MyQuery">
<cfinclude template="inc.cfm">
</cfloop>
Copy link to clipboard
Copied
Thanks, BKBK, for your reply. I am not sure if your solution would work though, since I will need to write to the PDF different message and save to a different file during each loop, with the same background. Please advise. Thanks again...
Copy link to clipboard
Copied
The example I have given you would work. It is all dynamic as I will now show.
In the following example, save the 2 CFM files and the image files in the same directory. Then open testFile.cfm in the browser. That will dynamically create 3 PDFs in the current directory
testFile.cfm
<cfloop list= "1,2,3" index="idx">
<cfinclude template="inc.cfm">
</cfloop>
inc.cfm
<cfoutput>
<cfdocument format = "PDF" localurl="true" filename="#expandPath('file#idx#.pdf')#" name="file#idx#" overwrite="true" >
<html>
<body style="background-image:url('testImage#idx#.png');background-repeat: no-repeat;">
HTML body content of page#idx#
</body>
</html>
</cfdocument>
</cfoutput>
Copy link to clipboard
Copied
It worked! Thank you, thank you so much!!!