1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| // Convert2PDF.js script
// Part of PDFCreator
// License: GPL
// Homepage: http://www.pdfforge.org/products/pdfcreator
// Windows Scripting Host version: 5.1
// Homepage: http://www.sf.net/projects/pdfcreator
// Version: 1.0.0.0
// Date: March, 15. 2007
// Author: Frank Heindörfer
// Comments: This script convert a printable file in a pdf-file using
// the com interface of PDFCreator.
var maxTime = 30 // in seconds
var sleepTime = 250 // in milliseconds
var objArgs, ifname, dirname, fso, PDFCreator, DefaultPrinter, ReadyState,
i, c, Scriptname;
fso = new ActiveXObject("Scripting.FileSystemObject");
Scriptname = fso.GetFileName(WScript.ScriptFullname);
if (WScript.Version < 5.1)
{
WScript.Echo("You need the \"Windows Scripting Host version 5.1\" or greater!");
WScript.Quit();
}
if (WScript.arguments.length == 0)
{
WScript.Echo("Syntax: \t" + Scriptname + " <Filename> <Dirname>");
WScript.Quit();
}
PDFCreator = WScript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_");
PDFCreator.cStart("/NoProcessingAtStartup");
PDFCreator.cOption("UseAutosave") = 1;
PDFCreator.cOption("UseAutosaveDirectory") = 1;
PDFCreator.cOption("AutosaveFormat") = 0; // 0 = PDF
//DefaultPrinter = PDFCreator.cDefaultprinter;
PDFCreator.cDefaultprinter = "PDFCreator";
PDFCreator.cClearcache();
ifname = WScript.arguments.item(0)
dirname = WScript.arguments.item(1)
if (!fso.FileExists(ifname)) {
WScript.Echo("Can't find the file: " + ifname);
}
else {
if (!PDFCreator.cIsPrintable(ifname)) {
WScript.Echos("Converting: " + ifname + "\r\n\r\nAn error is occured: File is not printable!");
WScript.Quit();
}
ReadyState = 0
PDFCreator.cOption("AutosaveDirectory") = dirname;
PDFCreator.cOption("AutosaveFilename") = fso.GetBaseName(ifname);
PDFCreator.cPrintfile(ifname); //-----------RESTE BLOQUE ICI
PDFCreator.cPrinterStop = false;
a.WriteLine("Dir et Filename OK");
c = 0
while ((ReadyState == 0) && (c < (maxTime * 1000 / sleepTime)))
{
c = c + 1;
WScript.Sleep(sleepTime);
a.WriteLine(c);
}
if (ReadyState == 0)
{
WScript.Echo("Converting: " + ifname + "\r\n\r\nAn error is occured: Time is up!");
}
}
//PDFCreator.cDefaultprinter = DefaultPrinter
PDFCreator.cClearcache();
WScript.Sleep(200);
PDFCreator.cClose();
//--- PDFCreator events ---
function PDFCreator_eReady()
{
ReadyState = 1;
}
function PDFCreator_eError()
{
WScript.Echo("An error is occured!\r\n\r\n" + "Error [" +
PDFCreator.cErrorDetail("Number") + "]: " + PDFCreator.cErrorDetail("Description"));
WScript.Quit();
} |
Partager