{oapdf_gg}
Office software is closely linked to the PDF,the PDF is also must have to control!      Set home Page  Add to Favorites  
You are here:Home > PDF Application > PDF Development
PDF Development
C# language or ASP.Net combat: convert PDF to Word format
Finishing by: Date:2009-04-20 21:54:47 Popularity: Tags:

Five: robust call C # code (the actual consideration, can be placed on B/S system)
to complete step 4 of the C # tests, careful readers may see that the problem of how to get a script that is running the results of the output, how to thread the StartConvertData method call passing parameters
1: transmission parameters, this can also be said to tell you a tutorial thread on how to pass method parameters, now talk about a program, a lot of such programs, I use a class, initialize the class, and then call such the implementation of the method as a method thread
2: get the script output, use the Process object to redirect the output, that is the direction of change in output, so that the script does not output to the console (MS-DOS window), but redirect the output to the C # program, and the use of thread The asynchronous callback method, the results show the script

add a new category, called type ToPdf
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Doc2Pdf
(
public class ToPdf
(
private string strWord = "";//here WORD document does not contain the path
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;//Redirect standard input
proc.StartInfo.RedirectStandardOutput = true;//Redirect standard output

proc.Start ();
proc.StandardInput.WriteLine ( "cscript//nologo" + sPath + "ConvertDoc2PDF.js" + sPath + strWord + "" + sPath);
proc.StandardInput.WriteLine ( "exit");
sExecResult = proc.StandardOutput.ReadToEnd ();//return to the implementation of the outcome of the script
proc.WaitForExit ();
proc.Close ();

)

public void EndConvertPDF (System.IAsyncResult ar)//ar parameters must write is thread after the completion of the implementation of the callback function
(
if (sExecResult.IndexOf ( "isuccess ")!=- 1) bSuccess = true;
else if (sExecResult.IndexOf ( "isfail ")!=- 1) bSuccess = false;
//If on the B/S system, you can write a database here is the success or failure of WEBService procedures with a database continuously to check that procedures are not on the WEBService call back function
//If on the C/S system, the callback function can not be placed on class in order to form the outcome of the procedure call
)
)
)


Rewrite the original code in the button1_Click event
-------------------------------------------------- -----------
private void button1_Click (object sender, System.EventArgs e)
(
ToPdf my2Pdf = new ToPdf ( "test.doc", "c: \ \");
ThreadStart thStartConvert = new ThreadStart (my2Pdf.StartConvertPDF);//asynchronous call to start the thread
thStartConvert.BeginInvoke (new AsyncCallback (my2Pdf.EndConvertPDF), null);//Set the callback function asynchronous thread

//If you need to convert a number of WORD, you can cycle
//If it is B/S system can be on the ASPX code of this paragraph, combined with the non-client technology refresh display data continuously visit WEBService procedures to determine whether PDF conversion success or failure of
)

there isArticle InformationsComment Information
Category column

Site Help | Site Map | Feedback |
OAPDF.COM Copyright 2009 V1.1