前幾天做了個系統報表功能,利用的是水晶報表。今天BOSS要求按下打印按鈕直接彈出打印機設置窗口而不是通
過PDF進行打印(水晶報表默認)。
忙活了半天總算解決了,和大家分享下。
此功能需要下載個插件,PrintControl.cab,自己在網上搜索下。
第一步:將PrintControl.cab放在網站的目錄下,這里我放在了根目錄下。
第二步:設置Web.Config文件,首先在<configSections>標簽中加入如下代碼。
<configSections>
<sectionGroup name="businessObjects">
<sectionGroup name="crystalReports">
<section name="printControl" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, Custom=null" />
</sectionGroup>
</sectionGroup>
<!--省略其他-->
</configSections>
然后在<configSections>標簽后面加入如下代碼
<businessObjects>
<crystalReports>
<printControl>
<add key="url " value="http://127.0.0.1/aizhigala//PrintControl.cab" />
</printControl>
</crystalReports>
</businessObjects>
第三步:在報表頁面加入如下代碼
<object classid="CLSID:BAEE131D-290A-4541-A50A-8936F159563A" codebase="http://127.0.0.1/aizhigala/PrintControl.cab" version="10,2,0,1078" viewastext style="display: none"></object>
第四步:設置crystalreportviewer的PrintMode為ActiveX
<cr:crystalreportviewer id="Ruling1ReportView" PrintMode="ActiveX" runat="server" autodatabind="true" BorderColor="DimGray" BorderWidth="1px" Height="50px" ToolbarStyle-BorderColor="Black" ToolbarStyle-BorderStyle="Solid" ToolbarStyle-BorderWidth="1px" Width="100%"/>
完!
