Convert a single file

This section describes the conversion of a single file to a pdf file using the COM interface of PDFCreator.

Note

The provided code snippets have been written in JavaScript and can be found in the PDFCreator directory under COMScripts/JS Scripts/Basics. The following code lines have been taken out ouf the TestPage2PDF.js script and can be found and executed there. The line numbers refer to the this file as well.

Getting started

When you create the COM Object basically you will get a reference to the PDFCreator job queue, which collects all incoming print jobs. In order to create a workflow follow these steps:

  1. 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("PDFCreatorBeta.JobQueue");
PDFCreatorQueue.Initialize();

//Sets up the path where the converted pdf file should be saved in
var fullPath = objFSO.GetParentFolderName(WScript.ScriptFullname) + "\\TestPage.pdf";
  1. Call WaitForJob(int timeOut) if you are waiting for one print job to get in the queue. The parameter timeOut specifies the maximum time in seconds 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");
}
  1. 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
  1. Setup the profile of the job with SetProfileByGuid(guid). The guid parameter is a string type that is used to assign the apropriate conversion profile(see enumeration below). Alternatively, you can use SetProfileByName(“MyNameForACertainProfile”). For the standard profiles it holds that their guids are equal to their names.
job.SetProfileByGuid("DefaultGuid"); //Alternative: job.SetProfileByName("DefaultGuid");
  1. Start the conversion on your print job with ConvertTo(string path). The path parameter includes the full path to the location where the converted file should be saved and its full name.
job.ConvertTo(fullPath); //the variable fullPath was introduced in line 31
  1. 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.

    It returns true if the job was converted successfully otherwise false.

if(!job.IsFinished || !job.IsSuccessful)
{
     WScript.Echo("Error in process");
}
  1. 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();

Predefined GUIDs

PDFCreator comes with a set of predefined profiles which have human-readable GUIDs. Even though they do not look like usual GUIDs, they are uniquely identifying the profiles. You should only use them, if you intend to use the predefined profiles.

GUID Description
DefaultGuid Creates PDF files
PdfaGuid Creates PDF/A files
PrintGuid Sends output to a printer after conversion
HighCompressionGuid PDFs with high compression images
HighQualityGuid PDFs with high quality images
JpegGuid Creates JPEG files
PngGuid Creates PNG files
TiffGuid Creates TIFF files

Warning

If you delete a profile with one of these GUIDs and create a profile with the same name, the GUIDs will not match.

Note

For more information on the queue or the job and its methods/properties see the corresponding chapter in References. 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 manual.