C# print2flash3文件转化
1.下载print2flash3 并且安装print2flash3
2.转换工具类
(1)需要导入using Print2Flash3; 这个程序集
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Print2Flash3;
using System.IO;
using System.Collections.Generic; namespace WebThreadTest
{
public class FileConvertSwf
{
//保存所有文件名
private static List<string> fileList; //可以打印的文件格式
private List<string> printFileFormat = new List<string>() { ".doc", ".docx", ".xlsx", ".xls", ".ppt" }; public FileConvertSwf()
{
fileList = new List<string>();
} /// <summary>
/// 将文件转化为swf文件
/// 将swf文件保存到当前目录下
/// </summary>
/// <param name="filePath">原文件路径</param>
public void ConvertToSwf(string filename)
{
//获取文件后缀名
string fileExtension = Path.GetExtension(filename); //是否可以打印
if (fileExtension != null && printFileFormat.Contains(fileExtension.ToLower()))
{ int extensionIndex = filename.LastIndexOf(fileExtension); //获取文件前缀名
string fileBeforeExtension = filename.Remove(extensionIndex); //swf文件名
string targetFilename = fileBeforeExtension + ".swf"; FileInfo file = new FileInfo(targetFilename); //不存在才转化
if (!file.Exists)
{
//使用Print2Flash3服务
IServer server = new Server(); //设置默认打印机
server.SetP2FPrinterAsDefault(); //文件转化
server.ConvertFile(@filename, @targetFilename, null, null, null);
}
} } /// <summary>
/// 获取某个目录下的所有文件及子目录下的所有文件
/// </summary>
/// <param name="dirPath">目录路径</param>
public void GetFilename(string dirPath)
{
//当前目录
DirectoryInfo dir = new DirectoryInfo(dirPath); //当前目录下的所有文件
FileInfo[] files = dir.GetFiles(); foreach (var f in files)
{
//保存到文件名集合中
fileList.Add(f.FullName); //文件转换
ConvertToSwf(f.FullName);
} //获取当前目录下的子目录下的所有文件
DirectoryInfo[] dirs = dir.GetDirectories(); foreach (var d in dirs)
{
//递归获取文件名
GetFilename(d.FullName);
}
} public List<string> GetFileNameList()
{
return fileList;
} }
}
3.测试代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic; namespace WebThreadTest
{
public partial class testGetFile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string dirPath = Server.MapPath(@"/resource/UploadedFiles");
FileConvertSwf fcSwf = new FileConvertSwf();
fcSwf.GetFilename(dirPath);
List<string> fileList = fcSwf.GetFileNameList(); foreach (var f in fileList)
{
Response.Write(f);
Response.Write("<br />");
}
}
}
}
}
4.html页面显示swf格式
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="convertFileTest.aspx.cs" Inherits="WebThreadTest.print2flash.demo.convertFileTest" %> <!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 runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div> <object id="forfun" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="1000" height="600">
<param name="movie" value="/resource/ConvertedFiles/target.swf">
<param name="quality" value="high">
<param name="bgcolor" value="#F0F0F0">
<param name="menu" value="false">
<param name="wmode" value="opaque">
<param name="FlashVars" value="">
<param name="allowScriptAccess" value="sameDomain">
<embed id="forfunex" src="/resource/ConvertedFiles/target.swf"
width="1000"
height="600"
align="middle"
quality="high"
bgcolor="#f0fff8"
menu="false"
play="true"
loop="false"
FlashVars=""
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
</div>
</form>
</body>
</html>
C# print2flash3文件转化的更多相关文章
- Android学习---ListView和Inflater的使用,将一个布局文件转化为一个对象
本文将介绍ListView和Inflater的使用,将接上一篇文章内容. 一.什么是ListView? 在android开发中ListView是比较常用的控件,ListView 控件可使用四种不同视图 ...
- 将图片文件转化为字节数组字符串,并对其进行Base64编码处理,以及对字节数组字符串进行Base64解码并生成图片
实际开发中涉及图片上传并且量比较大的时候一般处理方式有三种 1.直接保存到项目中 最老土直接方法,也是最不适用的方法,量大对后期部署很不方便 2.直接保存到指定路径的服务器上.需要时候在获取,这种方式 ...
- matlab下将图片序列转化为视频文件 && 将为视频文件转化图片序列
将图片序列转化为视频文件 程序如下: framesPath = 'E:\img\';%图像序列所在路径,同时要保证图像大小相同 videoName = 'Bolt.avi';%表示将要创建的视频文件的 ...
- xls文件转化txt
xls文件转化txt # -*- coding:utf-8 -*- # 安装pywin32包 http://sourceforge.net/projects/pywin32/files/pywin32 ...
- Android开发之将图片文件转化为字节数组字符串,并对其进行Base64编码处理
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985, 转载请说明出处. /** * @将图片文件转化为字节数组字符串,并对其进行Base64编码处理 * ...
- C#中将图片文件转化为二进制数组-用于数据库存储
在项目开发中,使用SQL Server存储数据,数据类型image可以保存图片.但是在存储之前需要将图片转化为二进制数组的形式进行赋值. 将图片文件转换为二进制数组 /// <summary&g ...
- 如何把word ppt 思维导图这类文件转化为高清晰度的图片(要干货只看粗体黑字)
我使用思维导图做学习笔记,最终绘制了一张比较满意的思维导图,想要分享出去,但由于现在思维导图软件众多,成品文件格式差别蛮大,不利于传播和打开,所以需要转化为普通图片,但笔者使用的导图软件导出转化成的图 ...
- c#文件转化byte数组
public static byte[] ReadFile(string fileName) { if (!File.Exists(fileName)) { throw new Exception(& ...
- 【vim】把当前文件转化为网页
这会生成一个 HTML 文件来显示文本,并在分开的窗口显示源代码: :%TOhtml (译者注:原文是 :%Tohtml,但在我的电脑上是 :%TOhtml) 转载自:https://linux.cn ...
随机推荐
- KNN python实践
本文实现了一个KNN算法,准备用作词频统计改进版本之中,这篇博文是从我另一个刚开的博客中copy过来的. KNN算法是一个简单的分类算法,它的动机特别简单:与一个样本点距离近的其他样本点绝大部分属于什 ...
- shell if [[ ]]和[ ]区别 || &&
[]和test 两者是一样的,在命令行里test expr和[ expr ]的效果相同. test的三个基本作用是判断文件.判断字符串.判断整数.支持使用 ”与或非“ 将表达式连接起来. test中可 ...
- Windows server 2008 r2下载地址和激活破解方法
Windows 7发布了服务器版本——Windows Server 2008 R2.同2008年1月发布的Windows Server 2008相比,Windows Server 2008 R2继续提 ...
- BZOJ1782[USACO 2010 Feb Gold 3.Slowing down]——dfs+treap
题目描述 每天Farmer John的N头奶牛(1 <= N <= 100000,编号1…N)从粮仓走向他的自己的牧场.牧场构成了一棵树,粮仓在1号牧场.恰好有N-1条道路直接连接着牧场, ...
- 洛谷 P2158 [SDOI2008]仪仗队 解题报告
P2158 [SDOI2008]仪仗队 题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线 ...
- JNative 传递参数bug
下载JNative网址:http://sourceforge.net/projects/jnative/files/jnative/ 下载JNative版本:JNative_1.4RC3_bin.zi ...
- SDL源码阅读笔记(1) 基本模块
write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 前言 对于大牛来说,写关于阅读源码的文章都会叫源码剖析或者深入浅出啥的,对于我,自己阅读阅读源码,写 ...
- Ubuntu16.04创建electronic-wechat启动器图标
步骤 将最新的electronic-wechat二进制包,下载解压,并移动到/opt/下面.sudo cp -r electronic-wechat/ /opt/electronic-wechat/ ...
- Asp: 解决脚本输出网页出现乱码情况
很久没碰asp,都有点生疏了,唉... 今天写一个小程序,发现网页静态部分输出不会乱码,asp脚本部分输出在360浏览器上会显示乱码,但在firefox和chrome上测试却不会显示乱码,我已经在代码 ...
- 获取Methods成员方法类
位于java.lang.reflect.Method包中 getModifiers() 成员方法的修饰符 getName() 成员方法的名字 getReturnType() 成员方法的声明类型 get ...