pdf to swf

使用swftoolspdf2swf.exe命令行来完成这项操作,转换效果理想,支持as3swftools官网:http://www.swftools.org/

下面是根据使用需要设计的2个方法:

/// <summary>

/// 获取pdf文件的页数

/// </summary>

public static int GetPageCount(string pdfPath)

{

try

{

byte[] buffer = File.ReadAllBytes(pdfPath);

int length = buffer.Length;

if (buffer == null)

return -1;

if (buffer.Length <= 0)

return -1;

string pdfText = Encoding.Default.GetString(buffer);

System.Text.RegularExpressions.Regex rx1 = new System.Text.RegularExpressions.Regex(@"/Type/s*/Page[^s]");

System.Text.RegularExpressions.MatchCollection matches = rx1.Matches(pdfText);

return matches.Count;

}

catch (Exception ex)

{

Util.WriteLog(ex);

}

return -1;

}

/// <summary>

/// 把指定的pdf页面转换成swf

/// </summary>

public static void ConvertToSwf(string pdfPath, string swfPath, int page)

{

try

{

string exe = Path.Combine(Application.StartupPath, "Tools//pdf2swf.exe");

if (!File.Exists(exe))

{

throw new ApplicationException("Can not find: " + exe);

}

//参考:http://www.swftools.org/pdf2swf.html

StringBuilder sb = new StringBuilder();

sb.Append(" -p " + page + "-" + page);//page range

sb.Append(" -j 100");//Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)

sb.Append(" -t");//The resulting SWF file will not turn pages automatically.

sb.Append(" -T 9");//flash version

sb.Append(" /"" + pdfPath + "/"");//input

sb.Append(" -o /"" + swfPath + "/"");//output

System.Diagnostics.Process proc = new System.Diagnostics.Process();

proc.StartInfo.FileName = exe;

proc.StartInfo.Arguments = sb.ToString();

proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

proc.Start();

proc.WaitForExit();

proc.Close();

}

catch (Exception ex)

{

Util.WriteLog(ex);

}

}

效果图

效果图

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值