Converting multiple files is nearly as simple as converting one file. It is recommended to read Convert a single file before going through this section.
For this example we will create 4 print jobs and merge job 2 and 3 together.
Note
The example can be found in the PDFCreator directory under COMScripts/JS Scripts. The following code lines have been taken out ouf the TestPageMergeTarget.js script and therefore can be found and executed there.
Get a reference to the PDFCreator job queue by calling the ActiveXObject(“ProgID”) method. Then call the Initialize() method with your COM Object.
var PDFCreatorQueue = new ActiveXObject"PDFCreator.JobQueue");
PDFCreatorQueue.Initialize();
//Sets up the path where the converted files should be saved in
var fullPath = objFSO.GetParentFolderName(WScript.ScriptFullname) + "\\TestPage.pdf";
Call WaitForJobs(4, int timeOut) if you are waiting for 4 print jobs to get in the queue. The parameter timeOut specifies the maximum time in seconds the queue waits for the print jobs to arrive. Why it is important to call this method is described in detail in the section SingleFileConversion(see Convert a single file) .
if(!WaitForJobs(4, 10))
{
WScript.Echo("4 print jobs did not reach the queue within 10 seconds.");
}
Call MergeJobs(PDFCreatorQueue.GetJobByIndex(1), PDFCreatorQueue.GetJobByIndex(2)) to merge the second and third job together.
PDFCreatorQueue.MergeJobs(PDFCreatorQueue.GetJobByIndex(1), PDFCreatorQueue.GetJobByIndex(2));
Start the conversion on one print job with ConvertTo(string path). You can use a loop to start the conversion on each job while the Count property does not return 0. Everything within the while loop works the same as described in the section SingleFileConversion.
while(PDFCreatorQueue.Count > 0)
{
var job = PDFCreatorQueue.NextJob;
job.SetProfileByGuid("DefaultGuid");
job.ConvertTo(fullPath);
if(!job.IsFinished || !job.IsSuccessful)
{
WScript.Echo("Could not convert the file: " + fullPath);
}
}
After having used the COM object do not forget to release it by using ReleaseCom().
PDFCreatorQueue.ReleaseCom();
Note
For more different and detailed examples take a look at the COM Scripts folder delivered with PDFCreator or take a look at the How To chapter of this user guide.