II: a virtual printer configuration WINDOWS into the control panel, enter the printer, click on the "Add Printer" icon. In the installation dialog box on the "step", there choose the printer, the manufacturer of the column in the select "Generic", a column in the printer, Select "MS Publisher Color Printer", and then by the next step along the way until the end of the installation.
three: the first began to write a program (script) Why should we use the conversion script does, in fact, the actual testing process, the use of PDF Distiller of the object reference to C # after a successful conversion, the PDF Distiller of the object can not be released, the second re-conversion, it took place error, so use the script here
achieve the conversion. so that we as long as the procedures in C # script in the call can be achieved WORD to PDF conversion
script host file name: ConvertDoc2PDF.js ------------------------------------------------ The contents of script file:
var files = WScript.Arguments; var fso = new ActiveXObject ( "Scripting.FileSystemObject"); var word = new ActiveXObject ( "Word.Application"); var PDF = new ActiveXObject ( "PDFDistiller.PDFDistiller.1"); word.ActivePrinter = "MS Publisher Color Printer";
//files (0) as a WORD document file name //files (1) for the conversion after the need to preserve the path //Call fso.GetBaseName (files (0)), to no path, no extension, the file name //files.length to document the number of parameters, the use of the cycle can support more than conversion WORD document
var docfile = files (0); var psfile = files (1) + fso.GetBaseName (files (0)) + ". ps"; var pdffile = files (1) + fso.GetBaseName (files (0)) + ". pdf"; var logfile = files (1) + fso.GetBaseName (files (0)) + ". log";
try ( var doc = word.Documents.Open (docfile); //WORD documents into PS documents; word.PrintOut (false, false, 0, psfile); doc.Close (0);
//PS files into PDF documents; PDF.FileToPDF (psfile, pdffile ,"");
fso.GetFile (psfile). Delete ();//delete the PS script file fso.GetFile (logfile). Delete ();//convert to delete the log file
word.Quit (); WScript.Echo ( "isuccess ");//successful WScript.Quit (0); ) catch (x) ( word.Quit (); WScript.Echo ( "isfail ");//failure WScript.Quit (0); )
procedures and then test the script Start MS-DOS, type the following command: c: \> cscript//nologo c: \ ConvertDoc2PDF.js c: \ test.doc c: \
Description: Test.pdf will see the successful operation of the document c: \ test.doc parameter is the corresponding script in the files (0) c: \ parameters corresponding process is script files (1) According to
you be able to read the script to support multiple parameters, use the FOR cycle, more than a conversion WORD document here do not use more than one file conversion is taken into account, the above C # script on the line the implementation process, so WORD can convert multiple documents.
|