This section describes how to change the order of actions that where added either by the pre existing profile or through COM.
Note
The provided code snippets have been written in JavaScript and can be found in the PDFCreator directory under “COMScripts/JS Scripts/How To”. The following code lines have been taken out of the ActionOrderManagment.js script which can be found and executed there.
Get a reference to the job queue with the ActiveXObject(“ProgID”) method. Then call the Initialize() method with your COM Object(which is actually the job queue).
var PDFCreatorQueue = new ActiveXObject("PDFCreator.JobQueue");
PDFCreatorQueue.Initialize();
//Sets up the path where the converted pdf file should be saved in
var fullPath = objFSO.GetParentFolderName(WScript.ScriptFullname) + "\\TestPage.pdf";
Call WaitForJob(int timeOut) to wait for one print job to get in the queue. The parameter timeOut specifies the maximum time in seconds that the queue waits for the print job to arrive. This method is very important because each newly triggered print job will take some time until it gets from the printer queue to the PDFCreator job queue. If you call the NextJob property without waiting for the job it may happen that you get null although the print job was triggered some lines before.
if(!PDFCreatorQueue.WaitForJob(10))
{
WScript.Echo("The print job did not reach the queue within " + 10 + " seconds");
}
Now you are able to get the next job in the queue by using the property NextJob. With that you receive the topmost job of the queue.
var job = PDFCreatorQueue.NextJob;
Setup the profile of the job with SetProfileByGuid(guid). The guid parameter is a string type that is used to assign the appropriate conversion profile (see Predefined GUIDs for available GUIDs).
Note: Alternatively, you can use SetProfileByName(“MyNameForACertainProfile”).
job.SetProfileByGuid("DefaultGuid");
Set up the cover page and background page. We are using the AddAction method. The order in which you add those action also determines the order of execution during conversion. If you use the alternative way of adding by actions by just enabling the setting it will cause all the actions to be ordered to a default order.
// add action using the addAction
WScript.Echo("Applying cover page settings...");
job.AddAction("CoverPage");
job.SetProfileSetting("CoverPage.File", objFSO.GetParentFolderName(WScript.ScriptFullname) + "\\CoverPage.pdf");
WScript.Echo("Applying background page settings...");
job.AddAction("BackgroundPage");
job.SetProfileSetting("BackgroundPage.File", objFSO.GetParentFolderName(WScript.ScriptFullname) + "\\BackgroundPage.pdf");
// an alternative way to add an action. It will automatically add the action into the real ActionOrder list; but might cause an order change.
job.SetProfileSetting("AttachmentPage.Enabled", true);
job.SetProfileSetting("AttachmentPage.File", objFSO.GetParentFolderName(WScript.ScriptFullname) + "\\AttachmentPage.pdf");
For more information on cover page, background page or attachment page settings see COM Interface Settings.
You can list all active actions by requesting the “ActionOrder” list from the job.
// getting a copied list of all active job in the selected profile, the list elements will be string
// keep in mind this list is a copy of the "real" actionOrder list, changes will not have any
// effect on the profile itself
var activeActionOrder = job.GetProfileListSetting("ActionOrder");
listActions(activeActionOrder);
The list has methods that can change its entry (see ArrayList) however the changes will only come into effect when the list is given to the job by using the “SetProfileListSetting(String, Arraylist)” method.
// you can change an manipulate the order by changing the list
// it will have no effect unless you use SetProfileList with your local list
activeActionOrder.RemoveAction("AttachmentPage");
listActions(activeActionOrder);
listActions(job.GetProfileListSetting("ActionOrder"));
// an important step to make sure you changes to your list will also be in the creator profile
job.SetProfileListSetting("ActionOrder", activeActionOrder);
Now you are ready to start the converting process.
//fullPath was introduced above
job.ConvertTo(fullPath);
The property IsFinished informs about the conversion state. If the print job is done, IsFinished returns true. If you want to know whether the job was successfully done, consider the property IsSuccessful. IsSuccessful returns true if the job was converted successfully otherwise false.
if(!job.IsFinished || !job.IsSuccessful)
{
WScript.Echo("Error in process");
}
After having used the COM object do not forget to release it by using ReleaseCom() otherwise no other PDFCreator instances will be able to work.
PDFCreatorQueue.ReleaseCom();