private void button1_Click(object sender, EventArgs e)
{
try
{
string fileName = Application.StartupPath.Replace(@"\bin\Debug", "") + @"\tools\pdf2swf.exe";
string pdfFile = Application.StartupPath.Replace(@"\bin\Debug", "") + @"\files\pdf\124.pdf";
string swfFIle = Application.StartupPath.Replace(@"\bin\Debug", "") + @"\files\swf\124.swf";
swfFIle = @"d:\111.swf";
StringBuilder sb = new StringBuilder();
sb.Append(" -t \"" + pdfFile + "\"");//input
sb.Append(" -o \"" + swfFIle + "\"");//output
sb.Append(" -s flashversion=9");//flash version
sb.Append(" -p" + " 1" + "-" + GetPageCount(pdfFile));//page range
Process proc = new Process();
proc.StartInfo.FileName = fileName;
proc.StartInfo.Arguments = sb.ToString();
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
proc.Close();
}
catch (Exception ex)
{ }
}
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(@"/Types*/Page[^s]");
System.Text.RegularExpressions.MatchCollection matches = rx1.Matches(pdfText);
return matches.Count;
}
catch (Exception ex)
{
throw ex;
}
}