码迷,mamicode.com
首页 > Web开发 > 详细

[原创]Lodop打印, 以及Lodop引用css文件控制打印样式的问题.

时间:2016-04-26 19:03:27      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:

最近在做Lodop打印功能:

思路是:  用MasterPage搭个打印页面的框架, 然后在具体的页面中填入数据, 打印的样式由母版页和CSS来控制.

困扰了一天的问题是:  在打印的JS文件中, 引用外部css文件时, 需要拼出实际的含有IP地址的CSS文件地址, 并且需要用双斜杠(//)来代替单斜杠.

 

代码如下:

//母版页, 注意:  url的拼接形式

<input id="hidCssRef" name="hidCssRef" type="hidden" value =‘<link href="http://<%= this.Request.Url.Authority %>//App_Themes//<%=Application["Theme"].ToString()%>//Css//PrintStyleSheet.css" rel="stylesheet" type="text/css" />‘ />

 

//PrintHelper.Master

技术分享
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="PrintHelper.master.cs" Inherits="JN.UI.Commons.PrintHelper.PrintHelper1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="/App_Themes/<%= Application["Theme"].ToString() %>/Css/PrintStyleSheet.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.json.js" type="text/javascript"></script>
    <script src="/Scripts/jquery.commons.js" type="text/javascript"></script>
    <asp:ContentPlaceHolder ID="headPlaceHolder" runat="server">
    </asp:ContentPlaceHolder>
    <style>
        @media print
        {
            .noprint
            {
               display:none;
            }

            .printOnly
            {
                display: block;
            }
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="page">
            <!--<input type="button" value="打印" onclick=‘<%= "printPreview(\‘"+ this.ContentPlaceHolder1.ClientID +"\‘);"%>‘ />-->
            <input type="button" value="打印" onclick=‘<%= "printPreview(\"printContent\");" %>‘ />
            <input id="hidCssRef" name="hidCssRef" type="hidden" value =‘<link href="http://<%= this.Request.Url.Authority %>//App_Themes//<%=Application["Theme"].ToString()%>//Css//PrintStyleSheet.css" rel="stylesheet" type="text/css" />‘ />
            
            <!--PrintStart-->
            <div id="printContent">
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                </asp:ContentPlaceHolder>
            </div>
            <!--PrintEnd-->
        </div>
    </form>
</body>
</html>
View Code

 

//PrintHelper.Master.cs

技术分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace JN.UI.Commons.PrintHelper
{
    public partial class PrintHelper1 : System.Web.UI.MasterPage
    {
        #region 全局变量
        private string _printType = HttpContext.Current.Request.QueryString.AllKeys.Contains("pType") ? HttpContext.Current.Request.QueryString["pType"] : string.Empty;
        #endregion

        #region 控件事件
        protected void Page_Init(object sender, EventArgs e)
        {
            //加载lodop的object
            HtmlGenericControl objControl = null;

            //string jsPathPatt = "~/Commons/PrintHelper/Resources/Scripts/{0}.js";
            string jsPathPatt = "/Commons/PrintHelper/Resources/Scripts/{0}.js";
            string jsPath = string.Empty;

            switch (_printType)
            {
                case "winPter":
                    goto default;
                case "webPter":
                    //jsPath = this.Page.ResolveUrl(string.Format(jsPathPatt, "WebrowserPrinter"));
                    jsPath = string.Format(jsPathPatt, "WebrowserPrinter");
                    break;
                case "lodPter":
                    //加载lodop的原始JS文件
                    string jsSrcPath = string.Format("/App_Libs/Lodop/6.203/{0}.js", "LodopFuncs");
                    HtmlGenericControl JsSrcControl = new HtmlGenericControl("script");
                    JsSrcControl.Attributes.Add("type", "text/javascript");
                    JsSrcControl.Attributes.Add("src", jsSrcPath);
                    this.headPlaceHolder.Controls.Add(JsSrcControl);
                    //lodop打印功能的JS
                    jsPath = string.Format(jsPathPatt, "LodopPrinter");
                    //lodp的object
                    objControl = new HtmlGenericControl("object");
                    objControl.Attributes.Add("id", "LODOP_OB");
                    objControl.Attributes.Add("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
                    objControl.Attributes.Add("id", "LODOP_OB");
                    objControl.Attributes.Add("width", "0");
                    objControl.Attributes.Add("height", "0");
                    //加载FF支持
                    HtmlGenericControl ffLodopSup = new HtmlGenericControl("embed");
                    ffLodopSup.Attributes.Add("id", "LODOP_EM");
                    ffLodopSup.Attributes.Add("type", "application/x-print-lodop");
                    ffLodopSup.Attributes.Add("width", "0");
                    ffLodopSup.Attributes.Add("height", "0");
                    objControl.Controls.Add(ffLodopSup);
                    break;
                default:
                    jsPath = string.Format(jsPathPatt, "WindowPrinter");
                    break;
            }
            //加载JS
            HtmlGenericControl JsControl = new HtmlGenericControl("script");
            JsControl.Attributes.Add("type", "text/javascript");
            JsControl.Attributes.Add("src",jsPath);
            
            this.headPlaceHolder.Controls.Add(JsControl);
            if(objControl != null)
                this.headPlaceHolder.Controls.Add(objControl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #endregion

        #region 初始化及绑定方法
        #endregion
    }
}
View Code

 

//具体的打印页面

//GodownEntryPrint.aspx

技术分享
<%@ Page Title="" Language="C#" MasterPageFile="~/Commons/PrintHelper/PrintHelper.Master" AutoEventWireup="true" CodeBehind="GodownEntryPrint.aspx.cs" Inherits="JN.UI.InventoryAdmin.GodownEntryPrint" %>
<%@ Register src="UserControls/UC_PrintTop.ascx" tagname="UC_PrintTop" tagprefix="uc1" %>
<%@ Register src="UserControls/UC_GodownEntryPrint.ascx" tagname="UC_GodownEntryPrint" tagprefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="headPlaceHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
   <uc1:UC_PrintTop ID="UC_PrintTop1" runat="server" />
   <uc2:UC_GodownEntryPrint ID="UC_GodownEntryPrint1" runat="server" />
</asp:Content>
View Code

 

//GodownEntryPrint.aspx.cs

技术分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JN.UI.InventoryAdmin
{
    public partial class GodownEntryPrint : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            this.UC_PrintTop1.PrintTitle = "物资入库单";
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}
View Code

 

//具体的实现代码放在用户控件中

//GodownEntryPrint.ascx

技术分享
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UC_GodownEntryPrint.ascx.cs" Inherits="JN.UI.InventoryAdmin.UserControls.UC_GodownEntryPrint" %>

<div class="prnTable">
    <div class="baseInfo">
        <table>
            <tr>
                <td class="baseTitle"><span>单据编号:</span></td>
                <td class="baseContent">
                    <span><asp:Label ID="lblGENum" runat="server" Text=""></asp:Label></span></td>
                <td class="baseTitle"><span>发票号:</span></td>
                <td class="baseContent">
                    <span><asp:Label ID="lblInvoNum" runat="server" Text=""></asp:Label></span>
                </td>
                <td class="baseTitle"><span>发票金额:</span></td>
                <td class="baseContent">
                    <span><asp:Label ID="lblInvoSum" runat="server" Text=""></asp:Label></span>
                </td>
            </tr>
            <tr>
                <td class="baseTitle"><span>供应商:</span></td>
                <td class="baseContent">
                    <span><asp:Label ID="lblSuppName" runat="server" Text=""></asp:Label></span>
                </td>
                <td class="baseTitle"><span>入库日期:</span></td>
                <td class="baseContent">
                    <span><asp:Label ID="lblCreateTime" runat="server" Text=""></asp:Label></span>
                </td>
                <td class="baseTitle"><span>库存状态:</span></td>
                <td class="baseContent">
                    <span><asp:Label ID="lblInveStatus" runat="server" Text=""></asp:Label></span>
                </td>
            </tr>
        </table>
    </div>
    <div class="detailInfo">
        <asp:Repeater ID="rptGEPrn" runat="server">
            <HeaderTemplate>
                <table>
                    <thead>
                        <tr>
                            <td class="detailTitle"><span>物资编码</span></td>
                            <td class="detailTitle"><span>物资名称</span></td>
                            <td class="detailTitle"><span>规格型号</span></td>
                            <td class="detailTitle"><span>单位</span></td>
                            <td class="detailTitle"><span>账务类型</span></td>
                            <td class="detailTitle"><span>入库数量</span></td>
                            <td class="detailTitle"><span>入库单价</span></td>
                            <td class="detailTitle"><span>入库金额</span></td>
                        </tr>
                    </thead>
                    <tbody>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td class="detailContent"><span><%# Eval("T_MaterialInfo.MaterialNO")  %></span></td>
                    <td class="detailContent"><span><%# Eval("T_MaterialInfo.MaterialName")  %></span></td>
                    <td class="detailContent"><span><%# Eval("T_MaterialInfo.MaterialSpec")  %></span></td>
                    <td class="detailContent"><span><%# Eval("T_Unit.UnitName")  %></span></td>
                    <td class="detailContent"><span><%# Eval("T_WareHouse.WHName")  %></span></td>
                    <td class="detailContent"><span><%# Eval("T_ZGEdownEntry.ZGEAmount")  %></span></td>
                    <td class="detailContent"><span><%# Eval("T_ZGEdownEntry.ZGEPrice")  %></span></td>
                    <td class="detailContent"><span>
                        <asp:Label ID="lblSumPrice" runat="server" Text=‘<%# Eval("T_ZGEdownEntry.ZGESumPrice")  %>‘></asp:Label></span>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="6"></td>
                        <td class="detailTitle"><span>总合计:</span></td>
                        <td class="detailContent"><span><asp:Label ID="lblTotalSum" runat="server" Text=""></asp:Label></span></td>
                    </tr>
                </tfoot>
                </table>
            </FooterTemplate>
        </asp:Repeater>
    </div>
    <div class="footInfo">
        <table>
            <tr>
                <td class="footTitle"><span>部门主管:</span></td>
                <td class="footContent">
                    <span><asp:Label ID="lblDepPrin" runat="server" Text=""></asp:Label></span></td>
                <td class="footTitle"><span>制单:</span></td>
                <td class="footContent">
                    <span><asp:Label ID="lblDocOpter" runat="server" Text=""></asp:Label></span></td>
                <td class="footTitle"><span>入库记账:</span></td>
                <td class="footContent">
                    <span><asp:Label ID="lblAccoClk" runat="server" Text=""></asp:Label></span></td>
            </tr>
        </table>
    </div>
</div>
View Code

 

//GodownEntryPrint.ascx.cs

技术分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using JN.BLL;
using JN.Model.Entity;
using JN.GTL;
using JN.Model.Enums;
using JN.BLL.Models;

namespace JN.UI.InventoryAdmin.UserControls
{
    public partial class UC_GodownEntryPrint : System.Web.UI.UserControl
    {
        #region 全局变量
        private BLLServices _baoSrv;
        private int _geNo = HttpContext.Current.Request.QueryString.AllKeys.Contains("geno") ? int.Parse(HttpContext.Current.Request.QueryString["geno"]) : -1; 
        #endregion

        #region 控件事件

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                InitData();
                //BindData();
            }
        }
        #endregion

        #region 绑定及初始化方法
        private void InitData()
        {
            if (this._geNo <= 0)
                throw new ArgumentException("无效的入库单编号!", "_geNo");

            this._baoSrv = new BLLServices();
            
            //读取入库单信息
            E_GodownEntry geInfo = this._baoSrv.GodownEntryBAO.GetGodownEntry(this._geNo);
            if(geInfo != null)
            {
                //处理入库单表头
                this.lblGENum.Text = geInfo.T_GodownEntry.GENumber;
                this.lblInvoNum.Text = geInfo.T_Invoice.InvoicenNumber;
                this.lblInvoSum.Text = geInfo.T_Invoice.InvoiceAmount.ToString();
                this.lblSuppName.Text = geInfo.T_Supplier.SupplierName;
                this.lblCreateTime.Text = GTLServices.DateTimeHelper.FormatDataStr(geInfo.T_GodownEntry.GECreateTime);
                //this.lblInveStatus.Text = Enum.GetName(typeof(GodownEntryStatus),geInfo.T_GodownEntry.GEStatus);
                this.lblInveStatus.Text = getEnumStatus((GodownEntryStatus)Enum.Parse(typeof(GodownEntryStatus),geInfo.T_GodownEntry.GEStatus.ToString()));

                //处理入库单表尾
                this.lblDocOpter.Text = (this.Session["userInfo"] as SessionUser).User.T_User.UserName;
                this.lblAccoClk.Text = geInfo.T_User.UserName;

                //处理入库单详情
                List<E_ZGEGodownEntry> detailLst = this._baoSrv.GodownEntryBAO.GetZGodownEntryList(geInfo.T_GodownEntry,null);
                this.rptGEPrn.DataSource = detailLst.Where(zg => zg.T_ZGEdownEntry.ZGENo == geInfo.T_GodownEntry.GENo).ToList();
                this.rptGEPrn.DataBind();

                //处理合计
                double total = 0.0;
                foreach(RepeaterItem ri in this.rptGEPrn.Controls)
                {
                    if(ri.ItemType == ListItemType.AlternatingItem || ri.ItemType == ListItemType.Item)
                    {
                        total += double.Parse((ri.FindControl("lblSumPrice") as Label).Text.Trim());
                    }
                    else if (ri.ItemType == ListItemType.Footer)
                    {
                        (ri.FindControl("lblTotalSum") as Label).Text = total.ToString("F2");
                    }
                }
            }
        }
        #endregion

        #region 私有方法
        private string getEnumStatus(GodownEntryStatus status)
        {
            string result = string.Empty;
            switch (status)
            {
                case GodownEntryStatus.Normal:
                    result = "正常";
                    break;
                case GodownEntryStatus.Delete:
                    result = "删除";
                    break;
                case GodownEntryStatus.CancellingStocks:
                    result = "退库";
                    break;
                default:
                    result = string.Empty;
                    break;
            }
            return result;
        }
        #endregion
    }
}
View Code

 

//公共的表头

//PrintTop.asxs

技术分享
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UC_PrintTop.ascx.cs" Inherits="JN.UI.InventoryAdmin.UserControls.UC_PrintTop" %>

<div class="prnTitle">
    <div>
        <h1>ZXXXX公司</h1>
    </div>
    <div>
        <h3><%= PrintTitle %></h3>
    </div>
</div>
View Code

 

//PrintTop.ascx.cs

技术分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JN.UI.InventoryAdmin.UserControls
{
    public partial class UC_PrintTop : System.Web.UI.UserControl
    {
        #region 全局变量
        private const string VIEWTITLE = "_subTitle";
        #endregion

        #region 控件事件
        protected void Page_Init(object sender, EventArgs e)
        {
            if (ViewState[VIEWTITLE] != null)
                this.PrintTitle = ViewState[VIEWTITLE].ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            

        }
        #endregion

        #region 属性
        /// <summary>
        /// 打印文件头副标题
        /// </summary>
        public string PrintTitle 
        {
            get
            {
                if (ViewState[VIEWTITLE] != null)
                    return ViewState[VIEWTITLE].ToString();
                else
                    return null;
            }
            set
            {
                if (value != null && value.Length > 0)
                {
                    ViewState[VIEWTITLE] = value;
                }
                else
                    ViewState[VIEWTITLE] = null;
            }
        }
        #endregion
    }
}
View Code

 

//print.js

技术分享
//以下是自己封装的JS打印、预览方法
//var LODOP = getLodop(document.getElementById(‘LODOP_OB‘), document.getElementById(‘LODOP_EM‘));
//var LODOP = getLodop();
var LODOP;  //声明为全局变量

//打印预览
function printPreview(prnContentId) {
    LODOP.PRINT_INIT("Lodop功能_预览");
    getPrintContent(prnContentId);
    LODOP.PREVIEW();
}

//打印
function print(prnContentId) {
    LODOP.PRINT_INIT("Lodop功能_打印");
    getPrintContent(prnContentId);
    LODOP.PRINT();
}

//获取打印内容
function getPrintContent(prnContentId) {
    LODOP = getLodop(document.getElementById(‘LODOP_OB‘), document.getElementById(‘LODOP_EM‘));
    //var cssRef = decodeURIComponent(document.getElementById(‘hidCssRef‘).value).replace(new RegExp(/\+/g)," ");
    var cssRef = document.getElementById(‘hidCssRef‘).value;

    //LODOP = getLodop();
    //初始化打印任务名
    //LODOP.PRINT_INIT("Lodop打印控件_打印表单");
    //打印预览设置
    var intDispMode = 2;             //预览比例: 0-适高, 1-正常大小, 2-适宽;
    var intToolMode = 0;             //工具条和按钮: 0-显示上方工具栏, 1-显示下方按钮兰, 3-两个都显示, 4-两个都不显示.
    var blDirectPrint = 0;           //打印按钮是否"直接打印": 1-是, 0-否(选取打印机)
    var intWidth = 1024;             //窗口的宽(单位:px)
    var intHeight = 680;             //窗口的高(单位:px)
    var strTitleButtonCaption = ‘‘;    //预览窗口和打印按钮的名称组合, 字符型, 用"点"分隔
    LODOP.SET_PREVIEW_WINDOW(intDispMode, intToolMode, blDirectPrint, intWidth, intHeight, strTitleButtonCaption);


    //设置打印纸张大小.
    var intOrient = 2;         //设置打印方向: 1-纵向(固定纸张), 2-横向(固定纸张), 3-纵向(宽度固定, 高度自适应), 0-方向不定(操作者自行设置). 
    var intPageWidth = 0;   //纸张宽度(单位0.1mm), 如:45表示4.5mm
    var intPageHeight = 0;    //纸张高度(单位0.1mm): 固定纸张时,表示纸张高; 自适应高度时, 表示纸张底边的空白高.  1480
    var strPageName = ‘A5‘;    //纸张类型: intPageWidth为0时才有效. 可使用"CreateCustomPage"在系统内建立名为"LKodopCustomPage"的自定义纸张类型.
    LODOP.SET_PRINT_PAGESIZE(intOrient, intPageWidth, intPageHeight, strPageName);
    //设置打印风格
    //LODOP.SET_PRINT_STYLE("FontSize", 11);
    //这里设置打印内容(Top,Left,Width,Height)

    LODOP.ADD_PRINT_HTM("5%", "5%", "100%", "100%", cssRef + ‘<body>‘ + document.getElementById(prnContentId).innerHTML + ‘</body>‘);
}
View Code

 

//项目添加了Lodop饮用后, 把自身的JS文件的修改下, 添加上未安装控件时引用自身目录下的控件文件

//LodopFuncs.js

技术分享
var CreatedOKLodop7766=null;

//====判断是否需要安装CLodop云打印服务器:====
function needCLodop(){
    try{
    var ua=navigator.userAgent;
    if (ua.match(/Windows\sPhone/i) !=null) return true;
    if (ua.match(/iPhone|iPod/i) != null) return true;
    if (ua.match(/Android/i) != null) return true;
    if (ua.match(/Edge\D?\d+/i) != null) return true;
    if (ua.match(/QQBrowser/i) != null) return false;
    var verTrident=ua.match(/Trident\D?\d+/i);
    var verIE=ua.match(/MSIE\D?\d+/i);
    var verOPR=ua.match(/OPR\D?\d+/i);
    var verFF=ua.match(/Firefox\D?\d+/i);
    var x64=ua.match(/x64/i);
    if ((verTrident==null)&&(verIE==null)&&(x64!==null)) 
        return true; else
    if ( verFF !== null) {
        verFF = verFF[0].match(/\d+/);
        if ( verFF[0] >= 42 ) return true;
    } else 
    if ( verOPR !== null) {
        verOPR = verOPR[0].match(/\d+/);
        if ( verOPR[0] >= 32 ) return true;
    } else 
    if ((verTrident==null)&&(verIE==null)) {
        var verChrome=ua.match(/Chrome\D?\d+/i);        
        if ( verChrome !== null ) {
            verChrome = verChrome[0].match(/\d+/);
            if (verChrome[0]>=42) return true;
        };
    };
        return false;
    } catch(err) {return true;};
};

//====页面引用CLodop云打印必须的JS文件:====
if (needCLodop()) {
    var head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
    //让其它电脑的浏览器通过本机打印(适用例子):
    var oscript = document.createElement("script");
    oscript.src ="/CLodopfuncs.js";
    head.insertBefore( oscript,head.firstChild );
    //让本机浏览器打印(更优先):
    oscript = document.createElement("script");
    oscript.src ="http://localhost:8000/CLodopfuncs.js?priority=1";
    head.insertBefore( oscript,head.firstChild );
    //本机浏览器的后补端口8001:
    oscript = document.createElement("script");
    oscript.src ="http://localhost:8001/CLodopfuncs.js?priority=2";
    head.insertBefore( oscript,head.firstChild );
};

//====获取LODOP对象的主过程:====
function getLodop(oOBJECT,oEMBED){
    var strHtmInstall="<br><font color=‘#FF00FF‘>打印控件未安装!点击这里<a href=‘/App_Libs/Lodop/6.203/install_lodop32.exe‘ target=‘_self‘>执行安装</a>,安装后请刷新页面或重新进入。</font>";
    var strHtmUpdate = "<br><font color=‘#FF00FF‘>打印控件需要升级!点击这里<a href=‘/App_Libs/Lodop/6.203/install_lodop32.exe‘ target=‘_self‘>执行升级</a>,升级后请重新进入。</font>";
    var strHtm64_Install = "<br><font color=‘#FF00FF‘>打印控件未安装!点击这里<a href=‘/App_Libs/Lodop/6.203/install_lodop64.exe‘ target=‘_self‘>执行安装</a>,安装后请刷新页面或重新进入。</font>";
    var strHtm64_Update = "<br><font color=‘#FF00FF‘>打印控件需要升级!点击这里<a href=‘/App_Libs/Lodop/6.203/install_lodop64.exe‘ target=‘_self‘>执行升级</a>,升级后请重新进入。</font>";
    var strHtmFireFox="<br><br><font color=‘#FF00FF‘>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
    var strHtmChrome="<br><br><font color=‘#FF00FF‘>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
    var strCLodopInstall = "<br><font color=‘#FF00FF‘>CLodop云打印服务(localhost本地)未安装启动!点击这里<a href=‘/App_Libs/Lodop/6.203/CLodopPrint_Setup_for_Win32NT.exe‘ target=‘_self‘>执行安装</a>,安装后请刷新页面。</font>";
    var strCLodopUpdate = "<br><font color=‘#FF00FF‘>CLodop云打印服务需升级!点击这里<a href=‘/App_Libs/Lodop/6.203/CLodopPrint_Setup_for_Win32NT.exe‘ target=‘_self‘>执行升级</a>,升级后请刷新页面。</font>";
    var LODOP;
    try{
        var isIE = (navigator.userAgent.indexOf(‘MSIE‘)>=0) || (navigator.userAgent.indexOf(‘Trident‘)>=0);
        if (needCLodop()) {
            try{ LODOP=getCLodop();} catch(err) {};
        if (!LODOP && document.readyState!=="complete") {alert("C-Lodop没准备好,请稍后再试!"); return;};
            if (!LODOP) {
         if (isIE) document.write(strCLodopInstall); else
         document.documentElement.innerHTML=strCLodopInstall+document.documentElement.innerHTML;
                 return;
            } else {

             if (CLODOP.CVERSION<"2.0.4.7") { 
            if (isIE) document.write(strCLodopUpdate); else
            document.documentElement.innerHTML=strCLodopUpdate+document.documentElement.innerHTML;
         };
         if (oEMBED && oEMBED.parentNode) oEMBED.parentNode.removeChild(oEMBED);
         if (oOBJECT && oOBJECT.parentNode) oOBJECT.parentNode.removeChild(oOBJECT);    
        };
        } else {
            var is64IE  = isIE && (navigator.userAgent.indexOf(‘x64‘)>=0);
            //=====如果页面有Lodop就直接使用,没有则新建:==========
            if (oOBJECT!=undefined || oEMBED!=undefined) {
                if (isIE) LODOP=oOBJECT; else  LODOP=oEMBED;
            } else if (CreatedOKLodop7766==null){
                LODOP=document.createElement("object");
                LODOP.setAttribute("width",0);
                LODOP.setAttribute("height",0);
                LODOP.setAttribute("style","position:absolute;left:0px;top:-100px;width:0px;height:0px;");
                if (isIE) LODOP.setAttribute("classid","clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
                else LODOP.setAttribute("type","application/x-print-lodop");
                document.documentElement.appendChild(LODOP);
                CreatedOKLodop7766=LODOP;
             } else LODOP=CreatedOKLodop7766;
            //=====Lodop插件未安装时提示下载地址:==========
            if ((LODOP==null)||(typeof(LODOP.VERSION)=="undefined")) {
                 if (navigator.userAgent.indexOf(‘Chrome‘)>=0)
                     document.documentElement.innerHTML=strHtmChrome+document.documentElement.innerHTML;
                 if (navigator.userAgent.indexOf(‘Firefox‘)>=0)
                     document.documentElement.innerHTML=strHtmFireFox+document.documentElement.innerHTML;
                 if (is64IE) document.write(strHtm64_Install); else
                 if (isIE)   document.write(strHtmInstall);    else
                     document.documentElement.innerHTML=strHtmInstall+document.documentElement.innerHTML;
                 return LODOP;
            };
        };
        if (LODOP.VERSION<"6.2.0.3") {
            if (needCLodop())
            document.documentElement.innerHTML=strCLodopUpdate+document.documentElement.innerHTML; else
            if (is64IE) document.write(strHtm64_Update); else
            if (isIE) document.write(strHtmUpdate); else
            document.documentElement.innerHTML=strHtmUpdate+document.documentElement.innerHTML;
            return LODOP;
        };
        //===如下空白位置适合调用统一功能(如注册语句、语言选择等):===

        //===========================================================
        return LODOP;
    } catch(err) {alert("getLodop出错:"+err);};
};
View Code

 

[原创]Lodop打印, 以及Lodop引用css文件控制打印样式的问题.

标签:

原文地址:http://www.cnblogs.com/cs_net/p/5435943.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!