2014-03-18 27 views
0

我想创建多个pdf并将它们保存到一个目录。我有一个基于Appid的查询。对于每个appid,我需要在该位置创建PDF和存储。我可以为一个appid创建pdf。当我尝试为多个appid创建pdf时,数据将被添加到当前的pdf中。以下是我的代码。请告知这里发生了什么问题。在Coldfusion中创建多个pdf到一个目录

<cfquery name="getdetails" datasource="#CSTTDB#" username="#CSTTUSR#" password="#CSTTPWD#"> 
select a.motsid,B.APP,B.ITCONTACT,B.STD,B.ED,B.DIRECTOR,a.tool,a.upddate,a.EAQUESTION from bnsit.TBLEAMGMT a,scott.tblaccessmgmt b 
where A.MOTSID = b.motsid 
and a.motsid = '16' 
and a.recid = '28' 
and a.EAQUESTION = 'Yes' 
</cfquery> 

<cfif getdetails.recordcount gt 0> 
<cfloop query="getdetails"> 
<cfdocument 
    format="pdf" 
    srcfile="\\wiwauk4colddw11.itservices.sbc.com\ITUPCOMP\pdf\"  
    filename="#getdetails.motsid#_#dateformat(upddate,"mmddyy")#_eareport.pdf" 
    overwrite="yes"> 


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
    <title>Emergency Access BNSIT - #getdetails.motsid#</title> 
</head> 

<style type="text/css" media="print"> 
td{ 
    width=50%; 
} 
.tpx td{ 
    border: solid 1px black; 
} 

</style> 

<body> 

<img src="email_header_plain.jpg" align="center" border= "0" alt="Header"> 
<p align="center"> 
<font size="+2" color="navy"> <strong>EMERGENCY ACCESS BNSIT</strong></font> 
</p> 
<br> 
<cfoutput> 
<cfset timenow = dateformat(now(),'mm/dd/yyyy')> 
<TABLE id="mytable" align="center" class="tpx" bgcolor="azure" border="1" width="80%"> 
<tr> 
    <tr> 
    <th align="left"><strong>MOTSID:</strong></th> 
    <th align="left">#motsid#</th> 
    </tr> 
    <tr> 
    <th align="left"><strong>Application Name:</strong></th> 
    <th align="left">#app#</th> 
    </tr> 
    <tr> 
    <th align="left"><strong>IT Contact:</strong></th> 
    <th align="left">#itcontact#</th> 
    </tr> 
    <tr> 
    <th align="left"><strong>STD:</strong></th> 
    <th align="left">#STD#</th> 
    </tr> 
    <tr> 
    <th align="left"><strong>Director:</strong></th> 
    <th align="left">#director#</th> 
    </tr> 
    <tr> 
    <th align="left"><strong>ED:</strong></th> 
    <th align="left">#ED#</th> 
    </tr> 
    <tr> 
    <th align="left"><strong>Access Provisioning Tool:</strong></th> 
    <th align="left">&nbsp;</th> 
    </tr> 
    <tr> 
    <th align="left"><strong>Emergency Access Tool:</strong></th> 
    <th align="left">#tool#</th> 
    </tr> 
    <tr> 
    <th align="left"><strong>Confirmation Received Date:</strong></th> 
    <th align="left">#dateformat(upddate,"mm/dd/yyyy")#</th> 
    </tr> 
</table> 


</cfoutput> 

</body> 
</html> 
</cfdocument> 
</cfloop> 

<cffile action="COPY" source="\\wiwauk4colddw11.itservices.sbc.com\ITUPCOMP\pdf\#getdetails.motsid#_#dateformat(upddate,"mmddyy")#_eareport.pdf" destination="\\135.16.235.36\devcompliance\pdfreports\"> 

    </cfif> 

编辑:我更新了上面的代码,我试图将创建的PDF文件从一个位置复制到另一个服务器。使用给定的命名约定,PDF文件正在源文件夹中创建。

但我即将在cffile副本获得低于错误。请有什么想法?

enter image description here

回答

2

此代码

<cfdocument 
    format="pdf" 
    srcfile="\\wiwauk4colddw11.itservices.sbc.com\ITUPCOMP\pdf\" 
    filename="testpdf.pdf" 
    overwrite="yes">

是创建名为 “testpdf.pdf” 的一个单一的PDF文件。通过循环查询内容,内容在此标记内创建。

请将您的CFLOOP移动到CFDOCUMENT标记之外。现在,对于每条记录,您将创建一个包含单个记录的数据值的新PDF。

,你还必须更改文件的名称创建动态显示:

<cfloop query="getdetails"> 

<cfdocument 
    format="pdf" 
    srcfile="\\wiwauk4colddw11.itservices.sbc.com\ITUPCOMP\pdf\" 
    filename="testpdf_#getdetails.motsid#.pdf" 
    overwrite="yes"> 

    <!--- HTML content ---> 

</cfdocument> 

</cfloop>

这将创建一个唯一的每个motsid名称的新的PDF文件。否则,您只需重新创建一个名为“testpdf.pdf”的文件,该文件最终将具有查询中最后一条记录的内容。

+0

非常感谢!最初我像你说的那样将cfloop移出cfdocument,但没有移动结束标签!!!!现在我做了,它再次感谢! – user747291