Coldfusion使用wkhtmltopdf创建报告 [英] Coldfusion creating reports with wkhtmltopdf

查看:96
本文介绍了Coldfusion使用wkhtmltopdf创建报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在 wkhtmltopdf方面寻求帮助。

我已经下载并安装并试图使其与我的程序正常工作。

I have downloaded and installed and trying to get it to work correctly with my program.

我拥有的是一种表格,允许用户选择打印,预览或excel。当用户选择打印时,我要弹出一个查询创建的html表,具体取决于所选的关联和位置。

What I have is a form that lets the user choose print, preview or excel. When the user chooses print I want pop up the html table that is created by a query depending on the associates and locations that are chosen.

现在,当用户选择打印时

Right now when the user chooses print it just shows this table in the browser.

<cfif FORM.Format IS "print">

<!---<cfdocument format="pdf" scale="75" backgroundvisible="yes" overwrite="no" fontembed="yes">--->

<link rel="stylesheet" href="css/form-table.css"/>

<!---<cfdocumentitem type="header" > 
    <cfoutput><p align= "right">Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</p></cfoutput> 
</cfdocumentitem> --->

<div class="RTable">
    <h3 class="RTable-h3">CHECKLIST STATS</h3>

    <cfoutput>
    <ul class="RTable-headingList">
        <li>FROM <span class="RTable-headingList-date">#dateFormat(date1, 'mm/dd/yyyy')#</span> TO <span class="RTable-headingList-date">#dateFormat(date2, 'mm/dd/yyyy')#</span></li>
        <li>LOCATIONS: <span class="RTable-headingList-locations">#locList#</span></li>
    </ul>
    </cfoutput>

    <table class="table table-hover RTable-table">

        <thead>
            <tr>
                <th>Associate Name</th>
                <th>Location</th>
                <th><small>Generated by</small>Associate</th>
                <th><small>Generated by</small>Selected Location(s)</th>
                <th><small>Associate Percentage of</small>Location Total</th>
            </tr>
        </thead>

        <tbody>
        <cfoutput query="GetEmployeeInfo">
      <tr>
          <td class="RTable-name"><cfif rnA EQ 1><strong>#assoc_name#</strong></cfif></td>
          <td class="RTable-location"><cfif rnL EQ 1>#trans_location#</cfif></td>
          <td>#checklistsByAssocLoc#</td> 
          <td>#assocChecklistsByLoc#</td> 
          <td>#DecimalFormat(totalChecklistsByAssocLocPct)# %</td> 
          <!---<td> rnA: #rnA# | rnL: #rnL# | rnTotAssoc: #rnTotAssoc# </td> --->
      </tr>
      <cfif rnTotAssoc EQ 1> 
      <tr class="RTable-row-associate-total"> 
          <td>Associate Total</td> 
          <td></td> 
          <td>#totalChecklistsByAssoc#</td> 
          <td>#totalAssocChecklistsByAllFilteredLoc#</td> 
          <td>#DecimalFormat(totalChecklistsByLocPct)# %</td>
      </tr>
      </cfif>
    </cfoutput>
    </tbody>
</table>

</div>

<!---</cfdocument>--->

我正在尝试像 cfdocument 一样使用它在< cfif FORM.Format IS print> 中,我该如何执行该表?如何替换该表?我将其用作报告,但不想将一百万个报告保存到服务器。我想我正在为右脚下车寻求帮助。

I am trying to use it like cfdocument in the <cfif FORM.Format IS "print"> do I cfexecute this table some how in replace of how I have the table? I am using this as reports and dont want to save a million reports to the server. I guess I am looking for some assistance in getting off on the right foot. Any help would be greatly appreciated.

Iv尝试在if print内添加以下代码:

Iv tried adding this code inside the if "print":

<cfexecute name="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" 
    arguments="http://path/path/checklist/wkhtmltestpage.cfm C:\temp\wkhtmlTest.pdf"
    errorVariable="errorMessage"
    timeout="10"
    /> 

但这不会下载该文件以显示要打印的用户。

But this does not download it to show the user to print.

由于某种原因,它不会转到该链接,因此我指定其将登录页面制作为pdf ...

Also for some reason its not going to the link I am specifying its making a pdf of the login page...

推荐答案

当WKHTMLTOPDF请求该网页时,用户未通过身份验证,并且CGI.Http_User_Agent包含 wkhtmltopdf。请求的远程IP还将是服务器上配置的本地IP。因此,我不会直接使用WKHTMLTOPDF处理任何CFM脚本。

When WKHTMLTOPDF requests the webpage, the "user" is not authenticated and the CGI.Http_User_Agent contains "wkhtmltopdf". The remote IP of the request will also be a local IP that is configured on the server. As a result, I don't directly process any CFM scripts using WKHTMLTOPDF.

我建议:


  • 使用CFContent捕获生成的静态HTML。

  • 将HTML保存到具有随机文件名的公共访问目录中。

  • 使用带有WKHTMLTOPDF命令行的Web路径+随机文件名。

  • 生成PDF后,删除随机文件。

  • Use CFContent to capture generated static HTML.
  • Save the HTML to a public-accessible directory with a random file name.
  • Use the web path + random file name w/WKHTMLTOPDF command line.
  • After PDF is generated, delete random files.

此过程将使任何问题更易于排除。我更喜欢使用相同的随机文件名创建静态BAT文件,以便可以在服务器上甚至在PC上本地重新手动运行,以进一步排除故障并查看程序返回的任何奇怪消息。您还需要传递许多其他命令行设置(页边距,方向,页面大小,页眉/页脚,JS延迟等),因此最好的方法是使用所有命令行参数创建一个独立的BAT文件。 (我在另一个问题中注意到您可能正在使用 CFX_Exec 。我建议使用它

This process will make any issues easier to troubleshoot. I prefer creating static BAT files with the same randomized filename so that I can manually re-run on the server or even locally on my on PC to further troubleshoot and view any weird messages returned by the program. There's many other command line settings you'll want to pass (margins, orientation, pagesize, header/footer, JS delay, etc), so creating a standalone BAT file with all of the command line arguments is the best approach. (I noticed in another question that you may be using CFX_Exec. I recommend using it over CFExecute.)

<!--- Simple WKHTMLTOPDF Generation Usage --->
<cfset FileID = CreateUUID()>
<cffile action="WRITE" file="#webroot#\#FileID#.htm" output="#TheHTML#">
<cfexecute name="C:\wkhtmltopdf.exe" arguments="http://mywebsite.com/#FileID#.htm C:\temp\#FileID#.pdf" timeout="30">
<cffile action="DELETE" file="#webroot#\#FileID#.htm">

要交付PDF文件,您可以执行302重定向到随机PDF文件,然后让您Web服务器处理mimetype(然后将其删除),或使用CFContent使用ColdFusion线程将其传递并自动将其删除:

To deliver the PDF file, you can either perform a 302 redirect to the randomized PDF file and let your webserver handle the mimetype (and then delete it later) or use CFContent to deliver it using a ColdFusion thread and automatically delete it:

<!--- Return PDF to browser inline or as downloadable attachment --->
<!--- <cfheader name="content-disposition" value="attachment; filename=""NiceFilename.pdf"""> --->
<cfheader name="content-disposition" value="inline; filename=""NiceFilename.pdf""">
<cfcontent type="application/pdf" file="C:\temp\#FileID#.pdf" deletefile="Yes">

这篇关于Coldfusion使用wkhtmltopdf创建报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆