I am using the example code in the directory ‘PDFCreator\COM Scripts\C#.Net\COM_TestForm\COM_TestForm.sln’, and for some reason I am getting an error on the line ‘printJob.ConvertTo(convertedFilePath);’ saying “Object reference not set to an instance of an object”. This error occurs when you click each of the 5 buttons, the code for the ‘TestPage2PDF’ is shown below.
I have seen a couple of other threads having the same issue, and I have tried the suggestion from another thread of changing the file path to My Documents with no sucess, is there a known fix for this yet?
using pdfforge.PDFCreator.UI.COM;
namespace COM_TestForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void testPage_btn_Click(object sender, EventArgs e) { var jobQueue = new Queue();
var assemblyDir = Assembly.GetExecutingAssembly().Location; var resultsDir = assemblyDir.Replace("\\bin\\Debug\\COM_TestForm.exe", "\\Results"); var convertedFilePath = Path.Combine(resultsDir, "TestPage_2PDF.pdf");
try { MessageBox.Show("Initializing the job queue"); jobQueue.Initialize();
MessageBox.Show("Printing windows test page..."); PrintWindowsTestPage();
if (!jobQueue.WaitForJob(10)) { MessageBox.Show("The job didn't arrive within 10 seconds"); } else { MessageBox.Show("Currently there are " + jobQueue.Count + " job(s) in the queue"); MessageBox.Show("Getting job instance"); PrintJob printJob = jobQueue.NextJob;
printJob.SetProfileByGuid("DefaultGuid");
MessageBox.Show("Converting under DefaultGuid"); printJob.ConvertTo(convertedFilePath);
if (!printJob.IsFinished || !printJob.IsSuccessful) { MessageBox.Show("Could not convert: "); } else { MessageBox.Show("The conversion was succesful!"); } } } catch (Exception err) { MessageBox.Show("An error occured: " + err.Message); } finally { MessageBox.Show("Releasing the queue object"); jobQueue.ReleaseCom(); } }
}
}