留言板——来本博客逛过的朋友们,来留个言吧,谢谢啦!~

公孙羽 发表于 2012-12-12 00:00:00

My E-mail address:jeebillweng@163.com
收藏: QQ书签 del.icio.us 订阅: Google 抓虾

IE6 png 透明 (三种解决方法)(转来的哦)

天使不堕落 发表于 2009-06-15 14:57:46

 

FF和IE7已经直接支持透明的png图了,下面这个主要是解决IE6下透明PNG图片有灰底的

=============================================================================

此效果简单,。。。。相当不错 推荐

 

style="FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/fl.png')"

语法:
filter : progid:DXImageTransform.Microsoft.AlphaImageLoader ( enabled=bEnabled , sizingMethod=sSize , src=sURL )

enabled : 可选项。布尔值(Boolean)。设置或检索滤镜是否激活。true | false true : 默认值。滤镜激活。
false : 滤镜被禁止。

sizingMethod : 可选项。字符串(String)。设置或检索滤镜作用的对象的图片在对象容器边界内的显示方式。 crop : 剪切图片以适应对象尺寸。
image : 默认值。增大或减小对象的尺寸边界以适应图片的尺寸。
scale : 缩放图片以适应对象的尺寸边界。

src : 必选项。字符串(String)。使用绝对或相对 url 地址指定背景图像。假如忽略此参数,滤镜将不会作用。

特性:
Enabled : 可读写。布尔值(Boolean)。参阅 enabled 属性。
sizingMethod : 可读写。字符串(String)。参阅 sizingMethod 属性。
src : 可读写。字符串(String)。参阅 src 属性。

说明:
在对象容器边界内,在对象的背景和内容之间显示一张图片。并提供对此图片的剪切和改变尺寸的操作。如果载入的是PNG(Portable Network Graphics)格式,则0%-100%的透明度也被提供。
PNG(Portable Network Graphics)格式的图片的透明度不妨碍你选择文本。也就是说,你可以选择显示在PNG(Portable Network Graphics)格式的图片完全透明区域后面的内容。

实例:解决IE6下png透明失效的问题。

CSS样式:

.png{
_background: url(http://www.snowangel.cn/images/angel.png) no-repeat !important;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=noscale, src="http://www.snowangel.cn/images/angel.png");
background:none;
width:118px;height:133px;
}

.png div{position:relative;}

HTML代码:

<div class="png">
<div>
CSS 背景PNG透明 及 链接失效问题解决
</div>
</div>

 

/*
兼容IE6.0、IE7.0、FF,
IE7.0和新版的FF其实是可以不加filter滤镜直接透明的。
*/

=============================================================================

 

 

第 1 种方法:定义一个样式,给某个div应用这个样式后,div的透明png背景图片自动透明了。(注意两处图片的路径写法不一样,本例中,icon_home.png图片与html文件在相同目录)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
.qq {
height: 90px;
width: 90px;
background-image: url(icon_home.png)!important;/* FF IE7 */
background-repeat: no-repeat;

_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='icon_home.png'); /* IE6 */
_ background-image: none; /* IE6 */
}
-->
</style>
</head>

<body>

<div class="qq"></div>

</body>
</html>

 

 

第 2 种方法: 给img定义样式,页面上所有透明png即自动透明了。(这方法只对直接插入的图片有效,对背景图无效注意,要准备一个透明的小图片transparent.gif,大小不限。必须放在和html相同的目录
请勿大量使用,否则会导致页面打开很慢!!!)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
.mypng img {
azimuth: expression(
this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizingMethod='image')",
this.src = "transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')",
this.runtimeStyle.backgroundImage = "none")),this.pngSet=true);
}

</style>
</head>

<body>
换成你的png图片
<div class="mypng">
<img src="icon_face_07.png" width="30" height="30" />
<img src="icon_face_10.png" width="30" height="30" />
<img src="icon_face_08.png" width="30" height="30" />
</div>
</body>
</html>

 

第 3 种方法:用JS实现,加上一段js代码后,所有插入的透明png自动透明了.(注意,这方法也是只对直接插入的图片有效,对背景图无效

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="JavaScript">
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (document.body.filters))
    {
       for(var j=0; j<document.images.length; j++)
       {
          var img = document.images[j]
          var imgName = img.src.toUpperCase()
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
             var imgID = (img.id) ? "id='" + img.id + "' " : ""
             var imgClass = (img.className) ? "class='" + img.className + "' " : ""
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
             var imgStyle = "display:inline-block;" + img.style.cssText
             if (img.align == "left") imgStyle = "float:left;" + imgStyle
             if (img.align == "right") imgStyle = "float:right;" + imgStyle
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
             var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
             img.outerHTML = strNewHTML
             j = j-1
          }
       }
    }    
}
window.attachEvent("onload", correctPNG);
</script>
<style type="text/css">
<!--
body {
background-color: #9999CC;
}
-->
</style></head>

<body>
把图片换成你自己的图片
<img src="img/icon_face_03.png" width="30" height="30" /><!--把图片换成你自己的图片 -->
<img src="img/icon_face_05.png" width="30" height="30" />
<img src="img/menu_title_over.png" width="130" height="36" />
</body>
</html>     




方法四

<script language="javascript">
// 修复 IE 下 PNG 图片不能透明显示的问题
function fixPNG(myImage) {
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
if ((version >= 5.5) && (version < 7) && (document.body.filters))
{
     var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
     var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
     var imgTitle = (myImage.title) ? "title='" + myImage.title   + "' " : "title='" + myImage.alt + "' ";
     var imgStyle = "display:inline-block;" + myImage.style.cssText;
     var strNewHTML = "<span " + imgID + imgClass + imgTitle

   + " style=\"" + "width:" + myImage.width

   + "px; height:" + myImage.height

   + "px;" + imgStyle + ";"

   + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

   + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
     myImage.outerHTML = strNewHTML;
} }

window.onload=function(){
         document.getElementById("top").style.height=screen.height/5+"px";
        
}//
</script>

用法如下:
<img src="logo.png" width="328" height="325" border="0" onload="fixPNG(this)" />
收藏: QQ书签 del.icio.us 订阅: Google 抓虾

用C#实现生成PDF文档

天使不堕落 发表于 2009-03-29 18:58:31

using System; 
using System.IO; 
using System.Text; 
using System.Collections; 

namespace PDFGenerator 


public class PDFGenerator 

static float pageWidth = 594.0f
static float pageDepth = 828.0f
static float pageMargin = 30.0f
static float fontSize = 20.0f
static float leadSize = 10.0f


static StreamWriter pPDF=new StreamWriter("E:\myPDF.pdf"); 

static MemoryStream mPDF= new MemoryStream(); 

static void ConvertToByteAndAddtoStream(string strMsg) 

Byte[] buffer
=null
buffer
=ASCIIEncoding.ASCII.GetBytes(strMsg); 
mPDF.Write(buffer,
0,buffer.Length); 
buffer
=null
}
 

static string xRefFormatting(long xValue) 

string strMsg =xValue.ToString(); 
int iLen=strMsg.Length; 
if (iLen<10

StringBuilder s
=new StringBuilder(); 
int i=10-iLen; 
s.Append(
'0',i); 
strMsg
=s.ToString() + strMsg; 
}
 
return strMsg; 
}
 

static void Main(string[] args) 

ArrayList xRefs
=new ArrayList(); 
//Byte[] buffer=null; 
float yPos =0f; 
long streamStart=0
long streamEnd=0
long streamLen =0
string strPDFMessage=null
//PDF文档头信息 
strPDFMessage="%PDF-1.1\n"
ConvertToByteAndAddtoStream(strPDFMessage); 

xRefs.Add(mPDF.Length); 
strPDFMessage
="1 0 obj\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
strPDFMessage
="<< /Length 2 0 R >>\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
strPDFMessage
="stream\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
////////PDF文档描述 
streamStart=mPDF.Length; 
//字体 
strPDFMessage="BT\n/F0 " + fontSize +" Tf\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
//PDF文档实体高度 
yPos = pageDepth - pageMargin; 
strPDFMessage
=pageMargin + " " + yPos +" Td\n" ; 
ConvertToByteAndAddtoStream(strPDFMessage); 
strPDFMessage
= leadSize+" TL\n" ; 
ConvertToByteAndAddtoStream(strPDFMessage); 

//实体内容 
strPDFMessage= "(http://www.wenhui.org)Tj\n" ; 
ConvertToByteAndAddtoStream(strPDFMessage); 
strPDFMessage
= "ET\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
streamEnd
=mPDF.Length; 

streamLen
=streamEnd-streamStart; 
strPDFMessage
= "endstream\nendobj\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
//PDF文档的版本信息 
xRefs.Add(mPDF.Length); 
strPDFMessage
="2 0 obj\n"+ streamLen + "\nendobj\n"
ConvertToByteAndAddtoStream(strPDFMessage); 

xRefs.Add(mPDF.Length); 
strPDFMessage
="3 0 obj\n<</Type/Page/Parent 4 0 R/Contents 1 0 R>>\nendobj\n"
ConvertToByteAndAddtoStream(strPDFMessage); 

xRefs.Add(mPDF.Length); 
strPDFMessage
="4 0 obj\n<</Type /Pages /Count 1\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
strPDFMessage
="/Kids[\n3 0 R\n]\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
strPDFMessage
="/Resources<</ProcSet[/PDF/Text]/Font<</F0 5 0 R>> >>\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
strPDFMessage
="/MediaBox [ 0 0 "+ pageWidth + " " + pageDepth + " ]\n>>\nendobj\n"
ConvertToByteAndAddtoStream(strPDFMessage); 

xRefs.Add(mPDF.Length); 
strPDFMessage
="5 0 obj\n<</Type/Font/Subtype/Type1/BaseFont/Courier/Encoding/WinAnsiEncoding>>\nendobj\n"
ConvertToByteAndAddtoStream(strPDFMessage); 

xRefs.Add(mPDF.Length); 
strPDFMessage
="6 0 obj\n<</Type/Catalog/Pages 4 0 R>>\nendobj\n"
ConvertToByteAndAddtoStream(strPDFMessage); 

streamStart
=mPDF.Length; 
strPDFMessage
="xref\n0 7\n0000000000 65535 f \n"
for(int i=0;i<xRefs.Count;i++

strPDFMessage
+=xRefFormatting((long) xRefs[i])+" 00000 n \n"
}
 
ConvertToByteAndAddtoStream(strPDFMessage); 
strPDFMessage
="trailer\n<<\n/Size "+ (xRefs.Count+1)+"\n/Root 6 0 R\n>>\n"
ConvertToByteAndAddtoStream(strPDFMessage); 

strPDFMessage
="startxref\n" + streamStart+"\n%%EOF\n"
ConvertToByteAndAddtoStream(strPDFMessage); 
mPDF.WriteTo(pPDF.BaseStream); 

mPDF.Close(); 
pPDF.Close(); 
}
 
}
 
}

收藏: QQ书签 del.icio.us 订阅: Google 抓虾

WORD文档转换成PDF格式

天使不堕落 发表于 2009-03-29 18:44:02

前言:由于一个客户的项目中需要将WORD文档转换成PDF格式,故写了本篇实站教程
需求分析:客户的项目以B/S结构为主,提供一个WORD文件在后台自动转换成PDF,经过实际测试,如果该篇WORD文档有100多页的话,转换需要20分钟左右的时间(环境:CPU是奔腾M 1.6G,512M内存),整个

CPU的占用率近乎95%~100%,此结果告诉客户以后,客户提议:到客户下班后,自动转换PDF,同时如果使用人确认要查看该PDF文档,如果没有转换,提供给客户选择,是现在转换成PDF,还是由服务器在客

户下班后,自动转换.

项目功能:按需求分析要写两个功能,
第一为:B/S结构后台转换,要提交给客户选择
第二为:Windows服务自动转换WORD文档到PDF

这两个分类:核心的转换程序都是采用线程的方式执行,只不过第一个功能是针对一个WORD文件,第二个功能针对所有未转换的WORD文档.

分析到现在:我们开始实战转换了!
一:必备工具 
安装必须的工具MS VS.Net2003,MS Office2003,Adobe Acrobat 
7.0 Professional,postscript.exe,gs811w32.exe 
MS VS.Net2003的安装不说明 
MS Office2003的安装不说明 

Adobe Acrobat 
7.0 Professional安装说明 
运行setup.exe文件,出现输入序列号,就运行注册机,用鼠标在第一行刷下就可以看见序列号,复制粘贴到Adobe Acrobat 
7.0 Professional安装程序对话框,安装到最后出现注册时,点击PHONE 

将安装程序中显示的第二行序列号(第一行是刚才注册机生成的序列号)复制粘贴到注册机的第二行,点击右边的按钮,再用鼠标刷第三行授权号就出来了,将其复制粘贴到安装程序的最后一行, 

完成安装注册! 

postscript.exe默认安装就可以了,它是一个PDF转换时所需要的脚本 
gs811w32.exe默认安装就可以,它其实是个PDF虚拟打印机的驱动 

二:配置虚拟打印机 
进入WINDOWS的控制面板,进入打印机,点击
"添加打印机"图标.在安装对话框上"按一步",出现选择打印机时,在制造商一栏中选择"Generic",在打印机一栏中,选择"MS Publisher Color Printer",然 

后一路按下一步,知道安装结束. 

三:开始写第一个程序(脚本程序) 
为什么要使用脚本程序进行转换呢,其实实际测试过程中,使用PDF Distiller的对象引用到C#后,转换成功,但整个PDF Distiller对象不能释放,第二次再转换时,就发生了错误,故此处使用脚本程序 

实现转换.这样我们只要在C#的程序中调用脚本程序就可以实现WORD到PDF的转换 

宿主脚本文件名:ConvertDoc2PDF.js 
------------------------------------------------ 
脚本文件内容: 

var files 
= WScript.Arguments; 
var fso 
= new ActiveXObject("Scripting.FileSystemObject"); 
var word 
= new ActiveXObject("Word.Application"); 
var PDF 
= new ActiveXObject("PDFDistiller.PDFDistiller.1"); 
word.ActivePrinter 
= "MS Publisher Color Printer"

//files(0) 为WORD文档文件名 
//files(1) 为,转换后需要保存的路径 
//调用fso.GetBaseName(files(0))后,为无路径,无扩展名,的文件名 
//files.length为文件参数的个数,使用循环可以支持多个WORD文档的转换 

var docfile 
= files(0); 
var psfile 
= files(1+ fso.GetBaseName(files(0)) + ".ps"
var pdffile 
= files(1+ fso.GetBaseName(files(0)) + ".pdf"
var logfile 
= files(1+ fso.GetBaseName(files(0)) + ".log"

try
var doc 
= word.Documents.Open(docfile); 
//WORD文件转成PS文件; 
word.PrintOut(falsefalse0, psfile); 
doc.Close(
0); 

//PS文件转成PDF文件; 
PDF.FileToPDF(psfile,pdffile,""); 

fso.GetFile(psfile).Delete();
//删除PS脚本文件 
fso.GetFile(logfile).Delete();//删除转换的日志文件 

word.Quit(); 
WScript.Echo(
"isuccess");//成功 
WScript.Quit(0); 
}
 
catch(x) 

word.Quit(); 
WScript.Echo(
"isfail");//失败 
WScript.Quit(0); 
}
 

然后测试该脚本程序 
启动MS
-DOS,输入如下命令: 
c:\
>cscript //nologo c:\ConvertDoc2PDF.js c:\test.doc c:\ 

说明: 
运行成功后将看到test.pdf文档了 
c:\test.doc参数对应的是脚本程序中的files(
0
c:\参数对应的是脚本程序中的files(
1

你可以安照该脚本改写成,支持多个参数,使用FOR循环,一次转换多个WORD文档,此处没有使用多个文件转换功能,是考虑到,该段脚本放在C#的线程中执行,这样一来也可以转换多个WORD文档. 
四:使用C#调用ConvertDoc2PDF.js脚本 
新建一个C#的WINDOWS应用程序,添加一个按钮button1 
添加一个函数,函数名StartConvertPDF 
public void StartConvertPDF() 

Process proc 
= new Process(); 
proc.StartInfo.FileName 
= "cmd.exe"
proc.StartInfo.WorkingDirectory 
= @"c:\"
proc.StartInfo.CreateNoWindow 
= true
proc.StartInfo.UseShellExecute 
= false
proc.StartInfo.RedirectStandardInput 
= true//输入重定向 

proc.Start(); 
proc.StandardInput.WriteLine(
@"cscript //nologo c:\ConvertDoc2PDF.js c:\test.doc c:\"); 
proc.StandardInput.WriteLine(
"exit"); 
proc.WaitForExit(); 
}
 

然后在按钮的CLICK事件中添加调用线程的代码 
private void button1_Click(object sender, System.EventArgs e) 

//定义线程序 
Thread thConvert = new Thread(new ThreadStart(StartConvertData)); 
thConvert.Start(); 
}
 

注意:在测试上面的C#程序时,必须添加如下命名空间 
using System.Diagnostics; 
using System.Threading; 



五:健壮的C#调用代码(实际考虑,可放在B
/S系统中) 
完成第4步的C#测试后,细心的读者,可能看到一点问题,那就是如何得到脚本运行后输出的结果,如何给线程中调用的StartConvertData方法传递参数 
1:传递参数,此话说来也可用一篇教程告诉大家线程中方法如何来传递参数,现在就讲一个方案,此种方案很多,我采用一个类,初始化这个类,然后调用该类的方法作为线程执行的方法 
2:得到脚本的输出结果,使用Process对象的输出重定向,就是说改变输出方向,使脚本不输出到控制台(MS-DOS窗口),而是重定向输出到C#程序中,并采用线程的异步回调方法,显示脚本运行结果 

添加一个新类,类名为ToPdf 
using System; 
using System.Diagnostics; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Data; 

namespace Doc2Pdf 

public class ToPdf 

private string strWord = "";//此处的WORD文件不含路径 
private string sPath = ""
public string sExecResult = ""
public bool bSuccess = false

public ToPdf(string sParamWord,string sParamPath) 

strWord 
= sParamWord; 
sPath 
= sParamPath; 
}
 

public void StartConvertPDF() 

Process proc 
= new Process(); 
   proc.StartInfo.FileName 
= "cmd.exe"
   proc.StartInfo.WorkingDirectory 
= sPath; 
   proc.StartInfo.CreateNoWindow 
= true
   proc.StartInfo.UseShellExecute 
= false
   proc.StartInfo.RedirectStandardInput 
= true;//标准输入重定向 
proc.StartInfo.RedirectStandardOutput = true;//标准输出重定向 

   proc.Start(); 
proc.StandardInput.WriteLine(
"cscript //nologo "+sPath+"ConvertDoc2PDF.js "+sPath+strWord+ " "+sPath); 
proc.StandardInput.WriteLine(
"exit"); 
sExecResult 
= proc.StandardOutput.ReadToEnd();//返回脚本执行的结果 
proc.WaitForExit(); 
proc.Close(); 

}
 

public void EndConvertPDF(System.IAsyncResult ar)//ar参数必须写,是线程执行完成后的回调函数 

if(sExecResult.IndexOf("isuccess")!=-1)bSuccess=true
else if(sExecResult.IndexOf("isfail")!=-1)bSuccess=false
//如果放在B/S系统,你可以在此处写数据库,是成功还是失败,并用一个WEBService程序不断检查数据库,此WEBService程序不放在该回调用函数中 
//如果放在C/S系统,回调函数可以不放在类中,以便在窗体程序中调用结果 
}
 
}
 
}
 


改写原来的button1_Click事件中的代码 
------------------------------------------------------------- 
private void button1_Click(object sender, System.EventArgs e) 

ToPdf my2Pdf 
= new ToPdf("test.doc","c:\"); 
ThreadStart thStartConvert 
= new ThreadStart(my2Pdf.StartConvertPDF); //开始异步调用线程 
thStartConvert.BeginInvoke(new AsyncCallback(my2Pdf.EndConvertPDF),null);//设置异步线程的回调函数 

//如果需要转换多个WORD,你可以用循环 
//如果是B/S系统,可以将本段代码放在ASPX中,并结合客户端的无刷新显示数据的技术,不断访问WEBService程序,以确定PDF是否转换成功或失败 
}
 

六:编写更加健壮的C#调用代码(实际考虑,可放在WINDOWS的服务程序中) 
--------------------------------------------------------------- 
实际使用时,由于转化PDF时CPU的占用率很高,考虑只在同一时间转换一篇WORD文档,放弃异步线程的回调函数的使用,考虑一个WINDOWS的服务程序. 
写一个函数CheckData2Convert(),不断的检查没有转换的WORD文档,并使用循环调用ToPdf类中执行转换方法StartConvertPDF 

//以下给出,泛代码,用户按照自己的需求,填写完整即可 
//bool bStart为全局变量,控制循环的进入与退出 
//例:18:30开始检查并转换,那么18:30时,bStart=true;并启动转换线程 
//6:30停止转换线程,bStart=fasle; 

private void CheckData2Convert() 

//检查指定目录下的没有转换的WORD文档,你同样可以检查数据库中记录的没有转换的WORD文档 
string sPath = System.Threading.Thread.GetDomain().BaseDirectory; //当前的路径 
while(bStart) 

int iFileCount = CheckWord(); //CheckWord为一个方法,检查当前没有转换的WORD文档,返回没有转换的文件数,该方法的代码由读者自己编写 
for(int i=0;i<iFileCount;i++

string sWord = GetWordFileName(i) //GetWordFileName为一个方法,返回一个不带路径的WORD文件名,该方法的代码由读者自己编写 
//ToPdf类中的StartConvertPDF()方法使用的是不带路径的WORD文件名 
ToPdf my2Pdf = new ToPdf(sWord ,sPath); 
my2Pdf.StartConvertPDF(); 

if(my2Pdf.sExecResult.IndexOf("isuccess")!=-1

//成功,写日志,或回写数据库 
}
 
else if(my2Pdf.sExecResult.IndexOf("isfail")!=-1

//失败,写日志,或回写数据库 
}
 

}
 

if(!bStart)break
Thread.Sleep(
1000); 
}
 
}
 

然后在服务的开始事件中,启动线程 
protected override void OnStart(string[] args) 

//可以使用一个开始定时器,检查是否到开始时间,时间一到,就开始执行线程,此处的开始执行线程可以放在开始定时事件中 
//可以使用一个结束定时器,检查是否到结束时间,时间一到,就结束线程,结束线程的代码可以放在结束定时事件中 
//注意:应该使用组件中的定时器,而不是Windows的FORMS中的定时器 
//该定时器的类名为System.Timers.Timer,千万别搞错,不然执行不会正常的 
bStart = true
Thread thConvert 
= new Thread(new ThreadStart(StartConvertData)); 
thConvert.Start(); 
}
 



然后在服务的结束事件中,设置停止线程的标识bStart
= false 
protected override void OnStop() 

bStart 
= false
//为何次处不停止线程呢,因为考虑到,现在线程正在转换WORD文档,但没有结束,所以只设置停止标识,转换完成后,线程也执行结束了. 
}
 

结束语: 
Adobe Acrobat 
7.0 Professional,postscript.exe,gs811w32.exe这三个文件可以在itbaby.jss.cn下载,都包含在同一个RAR的压缩文件中了 
itbaby.jss.cn是动态域名,主机在作者家里,如果网站不能访问,说明电脑没有开,请稍后几天再试. 
作者:javasuki 
联系邮件:zerodj@
163.com,javasuki@itbaby.jss.cn 
个人主页:itbaby.jss.cn
收藏: QQ书签 del.icio.us 订阅: Google 抓虾

WebBrowser

天使不堕落 发表于 2009-03-29 17:25:14

IE内置的WebBrowser控件,无需用户下载和安装。WebBrowser有很多功能,除打印外的其他功能就不再赘述了,你所能用到的打印功能也几乎全部可以靠它完成,下面的问题就是如何使用它了。先说显示后打印,后面说后台打印。

1.首先引入一个WebBrowser在需要打印的页面,可以直接添加: 
 
<object id="WebBrowser" classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height="0" width="0">
</object>

到页面,或者使用JavaScript在需要的时候临时添加也可以:

document.body.insertAdjacentHTML("beforeEnd",

    "<object id=\"WebBrowser\" width=0 height=0 \

classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\">");

2 .页面设置和打印预览

如下所示,直接调用即可

document.all.WebBrowser.ExecWB(6,6)   直接打印
document.all.WebBrowser.ExecWB(8,1)   页面设置
document.all.WebBrowser.ExecWB(7,1)   打印预览

或者:

execScript("document.all.WebBrowser.ExecWB 7, 1","VBScript");

3 隐藏不打印的页面元素和分页

 CSS 有个Media 属性,可以分开设置打印和显示的格式。

如 <style media="print" type="text/css"> …</style> 中间的格式将只在打印时起作用,不会影响显示界面。
所以可以设定
<style media="print" type="text/css">
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style>

然后给不想打印的页面元素添加: class="Noprint" ,那就不会出现在打印和打印预览中了。
想分页的地方添加:  <div class="PageNext"></div> 就可以了。


4.打印页面的特定部分

我是通过将需要打印的特定部分另建一个页面,然后装入主页面的一个IFrame中,再调用IFrame的打印方法,只打印IFrame中的内容实现的。
如:
<iframe style="visibility: visible" name="FrameId" width="100%" height="30%" src="NeedPrintedPage.asp"></iframe>
下面的pringFrame  js函数将只打印Iframe中的内容,可以直接引用使用,如printFrame(FrameId);


window.print = printFrame;

// main stuff
function printFrame(frame, onfinish) {
  if ( !frame ) frame = window;

  function execOnFinish() {
    switch ( typeof(onfinish) ) {
      case "string": execScript(onfinish); break;
      case "function": onfinish();
    }
    if ( focused && !focused.disabled ) focused.focus();
  }

  if (( frame.document.readyState !== "complete") &&( !frame.document.confirm("The document to print is not downloaded yet! Continue with printing?") ))
  {
    execOnFinish();
    return;
  }

 
  var eventScope = printGetEventScope(frame);
  var focused = document.activeElement;
 
  window.printHelper = function() {
    execScript("on error resume next: printWB.ExecWB 6, 1", "VBScript");
    printFireEvent(frame, eventScope, "onafterprint");
    printWB.outerHTML = "";
    execOnFinish();
    window.printHelper = null;
  }
 
  document.body.insertAdjacentHTML("beforeEnd",
    "<object id=\"printWB\" width=0 height=0 \
    classid=\"clsid:8856F961-340A-11D0-A96B-00C04FD705A2\">");
 
  printFireEvent(frame, eventScope, "onbeforeprint");
  frame.focus();
  window.printHelper = printHelper;
  setTimeout("window.printHelper()", 0);
}


// helpers
function printIsNativeSupport() {
  var agent = window.navigator.userAgent;
  var i = agent.indexOf("MSIE ")+5;
  return parseInt(agent.substr(i)) >= 5 && agent.indexOf("5.0b1") < 0;
}

function printFireEvent(frame, obj, name) {
  var handler = obj[name];
  switch ( typeof(handler) ) {
    case "string": frame.execScript(handler); break;
    case "function": handler();
  }
}

function printGetEventScope(frame) {
  var frameset = frame.document.all.tags("FRAMESET");
  if ( frameset.length ) return frameset[0];
  return frame.document.body;
}

Iframe中所装载页面的打印效果在所装载页面设置就可以了,如分页等。

5.后台打印

我是通过建一个隐藏Iframe实现的,当然仍然会有页面装载的过程。
下面的函数创建Iframe装载页面并打印。如 printHidden(url)  //url为页面地址

function printHidden(url) {
  document.body.insertAdjacentHTML("beforeEnd",
    "<iframe name=printHiddenFrame width=0 height=0></iframe>");
  var doc = printHiddenFrame.document;
  doc.open();
  doc.write("<body onload=\"parent.onprintHiddenFrame()\">");
  doc.write("<iframe name=printMe width=0 height=0 src=\"" +
      url + "\"></iframe>");
  doc.write("</body>");
  doc.close();
}

function onprintHiddenFrame() {
  function onfinish() {
    printHiddenFrame.outerHTML = "";
    if ( window.onprintcomplete ) window.onprintcomplete();
  }
  printFrame(printHiddenFrame.printMe, onfinish);
}

它用到了printFrame,所以别忘了引用前面的函数。

收藏: QQ书签 del.icio.us 订阅: Google 抓虾

js 关联数组 详解

天使不堕落 发表于 2009-02-09 21:16:33

标准javascript 是内含支持hash关联数组,经查找资料并测试,有关标准javascript内含的hash关联数组操作备忘如下(乔东 慢客 slowke.com):

1。Hash关联数组定义

// 定义空数组 (乔东 慢客 slowke.com)
myhash = { }

// 直接定义数组 (乔东 慢客 slowke.com)
myhash = {”key1″:”val1″, “key2″:”val2″ }

// 用Array 定义数组 (乔东 慢客 slowke.com)
myhash = new Array();
myhash[”key1″] = “val1″;
myhash[”key2″] = “val2″;

2。向Hash关联数组添加键值

// 添加一个新键 newkey ,键值为 newval (乔东 慢客 slowke.com)
myhash[”newkey”] = “newval”;

3。删除Hash关联数组已有键值

// 删除一个键 newkey ,同时,该键值对应的 newval 也就消失了。(乔东 慢客 slowke.com)
delete myhash[”newkey”];

4。遍历Hash关联数组

// 遍历整个hash 数组 (乔东 慢客 slowke.com)
for (key in myhash) {
val = myhash[key];
}

5。Hash关联数组简易使用示例

// 转向脚本 (乔东 慢客 slowke.com)
<script type=”text/javascript”>
urlhash = { “yahoo”:”www.yahoo.cn“,
“baidu”:”www.baidu.com“,
“google”:”www.google.cn” };

// 交互式使用示例 (乔东 慢客 slowke.com)
userinfo = prompt(”请输入您最想去的搜索引擎:(yahoo|baidu|google)”, “yahoo”);
document.write (”您的选择:” + userinfo + “,<a href=http://” _fcksavedurl="http://”" + getURL(userinfo) + ” target=_blank>” + “按此即可进入” + “</a>” + userinfo + “。”);

// getURL (乔东 慢客 slowke.com)
// 如果参数未定义,默认返回 www.yahoo.cn 网址
// @param choice 选择名称
// @return url 实际的URL
function getURL(choice) {
url = urlhash[choice];
if (typeof(urlhash[choice]) == “undefined”)
url = “www.yahoo.cn“;
return url;
}

// 获得hash列表的所有 keys
// @param hash hash数组
// @return keys 键名数据
function array_keys(hash) {
keys = [];
for (key in hash)
keys.push(key);
return keys;
}
</script>

+参考网址:

1. Javascript Hash关联数组操作备忘
http://www.slowke.com/boke/internet_2007-10-07_53.html

2. netscape javascript guide
http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/
收藏: QQ书签 del.icio.us 订阅: Google 抓虾

清除从word粘贴过来的多余html代码的ClearWord函数

天使不堕落 发表于 2009-02-09 13:21:05

<!—
/***********************************************************
* 頁面功能 : 清除從word粘貼過來多餘html代碼
* 作者 : 子心(方曉恩)
* 版本 : 1.0
* 創建時間 : 2005-11-29
* 作者主頁 : http://www.cfcodes.com
* 聯繫郵箱 : chinavane@msn.com
* Msn號碼 : chinavane@msn.com
* Oicq號碼 : 13525442
* 歷史版本 :

* 參數 :

帶有Word冗餘代碼的html內容
***********************************************************/
—>
<cfscript>
function CleanWord(html)
{
html = REReplaceNocase(html,’<o:p>\s*<\/o:p>’,”,’all’);
html = REReplaceNocase(html,’<o:p>.*?<\/o:p>’,'&nbsp;’,'all’);
html = REReplaceNocase(html,’\s*mso-[^:]+:[^;"]+;?’,”,’all’);
html = REReplaceNocase(html,’\s*MARGIN: 0cm 0cm 0pt\s*;’,”,’all’);
html = REReplaceNocase(html,’\s*MARGIN: 0cm 0cm 0pt\s*"’,'\"’,'all’);
html = REReplaceNocase(html,’\s*TEXT-INDENT: 0cm\s*;’,”,’all’);
html = REReplaceNocase(html,’\s*TEXT-INDENT: 0cm\s*"’,'\"’,'all’);
html = REReplaceNocase(html,’\s*TEXT-ALIGN: [^\s;]+;?"’,'\"’,'all’);
html = REReplaceNocase(html,’\s*PAGE-BREAK-BEFORE: [^\s;]+;?"’,'\"’,'all’);
html = REReplaceNocase(html,’\s*FONT-VARIANT: [^\s;]+;?"’,'\"’,'all’);
html = REReplaceNocase(html,’\s*tab-stops:[^;"]*;?’,”,’all’);
html = REReplaceNocase(html,’\s*tab-stops:[^"]*’,”,’all’);
html = REReplaceNocase(html,’\s*face="[^"]*"’,”,’all’);
html = REReplaceNocase(html,’\s*face=[^ >]*’,”,’all’);
html = REReplaceNocase(html,’\s*FONT-FAMILY:[^;"]*;?’,”,’all’);
html = REReplaceNocase(html,’<(\w[^>]*) class=([^ |>]*)([^>]*)’,'<′,’all’);
html = REReplaceNocase(html,’<(\w[^>]*) style="([^\"]*)"([^>]*)’,'<′,’all’);
html = REReplaceNocase(html,’\s*style="\s*"’,”,’all’);
html = REReplaceNocase(html,’<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>’,'&nbsp;’,'all’);
html = REReplaceNocase(html,’<SPAN\s*[^>]*><\/SPAN>’,”,’all’);
html = REReplaceNocase(html,’<(\w[^>]*) lang=([^ |>]*)([^>]*)’,'<′,’all’);
html = REReplaceNocase(html,’<SPAN\s*>(.*?)<\/SPAN>’,'′,’all’);
html = REReplaceNocase(html,’<FONT\s*>(.*?)<\/FONT>’,'′,’all’);
html = REReplaceNocase(html,’<\?\?xml[^>]*>’,”,’all’);
html = REReplaceNocase(html,’<\/?\w+:[^>]*>’,”,’all’);
html = REReplaceNocase(html,’<H\d>\s*<\/H\d>’,”,’all’);
html = REReplaceNocase(html,’<H1([^>]*)>’,'<div><b><font size="6">’,'all’);
html = REReplaceNocase(html,’<H2([^>]*)>’,'<div><b><font size="5">’,'all’);
html = REReplaceNocase(html,’<H3([^>]*)>’,'<div><b><font size="4">’,'all’);
html = REReplaceNocase(html,’<H4([^>]*)>’,'<div><b><font size="3">’,'all’);
html = REReplaceNocase(html,’<H5([^>]*)>’,'<div><b><font size="2">’,'all’);
html = REReplaceNocase(html,’<H6([^>]*)>’,'<div><b><font size="1">’,'all’);
html = REReplaceNocase(html,’<\/H\d>’,'</font></b></div>’,'all’);
html = REReplaceNocase(html,’<(U|I|STRIKE)>&nbsp;<\/>’,'&nbsp;’,'all’);
html = REReplaceNocase(html,’<([^\s>]+)[^>]*>\s*<\/>’,”,’all’);
html = REReplaceNocase(html,’<([^\s>]+)[^>]*>\s*<\/>’,”,’all’);
html = REReplaceNocase(html,’<([^\s>]+)[^>]*>\s*<\/>’,”,’all’);
html = REReplaceNocase(html,’(<P)([^>]*>.*?)(<\/P>)’,'<div</div>’,'all’);
return html;
}
</cfscript>

function REReplaceNocase(str,reg,replace,value)
{
if ( value==&#34;all&#34; )
{
Reg1 = new RegExp(reg,&#34;gi&#34;);
return str.replace(Reg1,replace);
}
else
{
return str;
}
}

收藏: QQ书签 del.icio.us 订阅: Google 抓虾

兼容FireFox

天使不堕落 发表于 2009-02-07 23:15:22

...
收藏: QQ书签 del.icio.us 订阅: Google 抓虾

C#实现上传WORD文档并另存为WEB页面

天使不堕落 发表于 2008-12-28 20:25:00

转载自:http://blog.csdn.net/banmuhuangci/archive/2008/02/19/2107009.aspx
收藏: QQ书签 del.icio.us 订阅: Google 抓虾