Convert DOC to PDF Files (Convert Word To PDF Files) using Command in ASP.Net

I used http://www.softinterface.com/Convert-Doc/Features/Convert-DOC-to-PDF.htm and then Executed the command from Asp.Net to conver the MS Word files to PDF.

Code

        // write the command
        string exec = TextBox1.Text;

        // Create the ProcessInfo object
        System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardError = true;
       
        // The path where Application is installed
        psi.WorkingDirectory = "C:\\Program Files\\Softinterface, Inc\\Convert Doc";


        // Start the process
        System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);

        // Open the batch file for reading

        //System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath);
        System.IO.StreamReader strm = proc.StandardError;
        // Attach the output for reading
        System.IO.StreamReader sOut = proc.StandardOutput;
        // Attach the in for writing
        System.IO.StreamWriter sIn = proc.StandardInput;

        sIn.WriteLine(exec);

        strm.Close();

        sIn.WriteLine("EXIT");

        // Close the process
        proc.Close();

        // Close the io Streams;
        sIn.Close();
        sOut.Close();

ASPX File

             <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>


Commands ( Ref: http://www.softinterface.com/ )

Converting a Single File

To convert a single file, say D:\MyFolder\Doc1.DOC to C:\Results Folder\Doc1.PDF use the following syntax:

   ConvertDoc /S "D:\MyFolder\Doc1.DOC" /T "C:\Results Folder\Doc1.PDF" /F9 /C12 /M2 /V

  • The /S and /T switches above specify Source (input) and Target (output) path respectively and are both required when converting a single file.  It is always a good idea to use double quotes around the path especially if there are space characters within the path.

  • The /M2 switch tells 'Convert Doc' to use the 'Convert Doc' method (it is one of 3 different possible Conversion Methods). 

  • /F9 is the original (input) file type, which in this case is a word DOC file.  Looking up the file types within the File Type Constants Specification for the 'Convert Doc' method will show that the numeric value of 9 corresponds to a DOC file.

  • /C12 is the target (output) file type, which in this case is a PDF file.  Looking up the file types within the File Type Constants Specification for the 'Convert Doc' method will show that the numeric value of 12 corresponds to a PDF file.

  • Finally, the /V (for Verbose) switch is used to give instant feedback by having the program report the status of the conversion with a message box.  You can remove this once you have perfected your command line specification.  You can also (or instead of /V) create a Log file that will contain the results of the conversion by using the /L switch.

  • HINT: You may use the /W switch to specify a File Open password.  The Example below makes the word Apples the password to open the newly created PDF file:

         ConvertDoc.EXE     /S "c:\input files\tryme.doc" /T "c:\input files\tryme.pdf" /F9 /C12 /M2 /V /WApples

Note: It is highly encouraged that you use the Verbose (/V) switch initially to see what the status of your conversion is and to help you perfect your command line.  When in verbose mode the program will tell you what went wrong or right with your command line using message boxes.

Comments

Popular posts from this blog

Use configSource attribute to manage Web.Config sections in ASP.Net 2.0

DevOps - Key Concepts - Roles & Responsibilities - Tools & Technologies