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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| // 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.
try {
var fs = new ActiveXObject("Scripting.FileSystemObject");
var a = fs.CreateTextFile("c:\\test02.txt", true, true);
a.WriteLine("Debut");
var maxTime = 30 // in seconds
var sleepTime = 250 // in milliseconds
var objArgs, ifname, dirname, fso, PDFCreator, DefaultPrinter, ReadyState,
i, c, Scriptname;
a.WriteLine("Var OK");
fso = new ActiveXObject("Scripting.FileSystemObject");
Scriptname = fso.GetFileName(WScript.ScriptFullname);
a.WriteLine("fso OK");
if (WScript.Version < 5.1)
{
WScript.Echo("You need the \"Windows Scripting Host version 5.1\" or greater!");
WScript.Quit();
}
a.WriteLine("WScript.Version OK");
if (WScript.arguments.length == 0)
{
WScript.Echo("Syntax: \t" + Scriptname + " <Filename> <Dirname>");
WScript.Quit();
}
a.WriteLine("Arguments OK");
PDFCreator = WScript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_");
a.WriteLine("PDFCreator create OK");
PDFCreator.cStart("/NoProcessingAtStartup");
a.WriteLine("PDFCreator start OK");
PDFCreator.cOption("UseAutosave") = 1;
PDFCreator.cOption("UseAutosaveDirectory") = 1;
PDFCreator.cOption("AutosaveFormat") = 0; // 0 = PDF
//DefaultPrinter = PDFCreator.cDefaultprinter;
PDFCreator.cDefaultprinter = "PDFCreator";
PDFCreator.cClearcache();
a.WriteLine("Options OK");
ifname = WScript.arguments.item(0)
dirname = WScript.arguments.item(1)
if (!fso.FileExists(ifname)) {
WScript.Echo("Can't find the file: " + ifname);
}
else {
a.WriteLine("FileExists OK");
if (!PDFCreator.cIsPrintable(ifname)) {
WScript.Echos("Converting: " + ifname + "\r\n\r\nAn error is occured: File is not printable!");
PDFCreator.cClose();
a.Close();
WScript.Quit();
}
a.WriteLine("IsPrintable OK");
ReadyState = 0
PDFCreator.cOption("AutosaveDirectory") = dirname;
PDFCreator.cOption("AutosaveFilename") = fso.GetBaseName(ifname);
a.WriteLine("avt impression");
PDFCreator.cPrintfile(ifname);
PDFCreator.cPrinterStop = false;
a.WriteLine("apres impression");
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();
a.WriteLine("Fin");
a.Close();
}catch(err){a.WriteLine("Error:");a.WriteLine(err.description);}
//--- PDFCreator events ---
function PDFCreator_eReady()
{
var fs2 = new ActiveXObject("Scripting.FileSystemObject");
var a2 = fs.CreateTextFile("c:\\test2.txt", true, true);
ReadyState = 1;
a2.WriteLine("ReadyState OK");
a2.Close();
}
function PDFCreator_eError()
{
var fs3 = new ActiveXObject("Scripting.FileSystemObject");
var a3 = fs.CreateTextFile("c:\\test3.txt", true, true);
a3.WriteLine("PDFCreator_eError");
a3.Close();
WScript.Echo("An error is occured!\r\n\r\n" +
"Error [" + PDFCreator.cErrorDetail("Number") + "]: " + PDFCreator.cErrorDetail("Description"));
WScript.Quit();
} |
Partager