Asp.net tool-PSD2swfHelper

Source: Internet
Author: User

Using System. Web;
Using System. Text;

Public static class PSD2swfHelper
{
/// <Summary>
/// Convert all pages with an image quality of 80%
/// </Summary>
/// <Param name = "pdfPath"> pdf file address </param>
/// <Param name = "swfPath"> the generated SWF file address </param>
Public static bool extends 2swf (string pdfPath, string swfPath)
{
Return ipv2swf (pdfPath, swfPath, 1, GetPageCount (HttpContext. Current. Server. MapPath (pdfPath), 80 );
}

/// <Summary>
/// N pages before conversion, image quality 80%
/// </Summary>
/// <Param name = "pdfPath"> pdf file address </param>
/// <Param name = "swfPath"> the generated SWF file address </param>
/// <Param name = "page"> page number </param>
Public static bool defaults 2swf (string pdfPath, string swfPath, int page)
{
Return limit 2swf (pdfPath, swfPath, 1, page, 80 );
}

/// <Summary>
/// Convert the PDF format to SWF
/// </Summary>
/// <Param name = "pdfPath"> pdf file address </param>
/// <Param name = "swfPath"> the generated SWF file address </param>
/// <Param name = "beginpage"> conversion start page </param>
/// <Param name = "endpage"> conversion end page </param>
Private static bool rj2swf (string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
{
String exe = HttpContext. Current. Server. MapPath ("~ /Bin/tools/pdf2swf-0.9.1.exe ");
PdfPath = HttpContext. Current. Server. MapPath (pdfPath );
SwfPath = HttpContext. Current. Server. MapPath (swfPath );
If (! System. IO. File. Exists (exe) |! System. IO. File. Exists (pdfPath) | System. IO. File. Exists (swfPath ))
{
Return false;
}
StringBuilder ** = new StringBuilder ();
**. Append ("\" "+ pdfPath + "\"");
**. Append ("-o \" "+ swfPath + "\"");
**. Append ("-s flashversion = 9 ");
If (endpage> GetPageCount (pdfPath) endpage = GetPageCount (pdfPath );
**. Append ("-p" + "\" "+ beginpage +" "+"-"+ endpage + "\"");
**. Append ("-j" + photoQuality );
String Command = **. ToString ();
System. Diagnostics. Process p = new System. Diagnostics. Process ();
P. StartInfo. FileName = exe;
P. StartInfo. Arguments = Command;
P. StartInfo. WorkingDirectory = HttpContext. Current. Server. MapPath ("~ /Bin /");
P. StartInfo. UseShellExecute = false;
P. StartInfo. RedirectStandardError = true;
P. StartInfo. CreateNoWindow = false;
P. Start ();
P. BeginErrorReadLine ();
P. WaitForExit ();
P. Close ();
P. Dispose ();
Return true;
}

/// <Summary>
/// Number of returned pages
/// </Summary>
/// <Param name = "pdfPath"> pdf file address </param>
Private static int GetPageCount (string pdfPath)
{
Byte [] buffer = System. IO. File. ReadAllBytes (pdfPath );
Int length = buffer. Length;
If (buffer = null)
Return-1;
If (buffer. Length <= 0)
Return-1;
String shorttext = 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 (plain Text );
Return matches. Count;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.