ConvertTo - Object reference not set to an instance of an object (C#.NET)


#1

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();
        }
    }

}
}


#2

Do you have any updates for this problem?
It is still the same in version 2.5.1 and 2.5.2.

Best regards,
Michael


#3

Sa c’est mon expérience :

The example provided with pdg creator for C # and Vb.Net is incorrect for all versions of it. Its validity stops at version 2.3.2 due to a likely error in the COM.UI interface. For version 2.3.2, reference should be made to the PdfCreator.Exe program

From version 2.4.0 onwards you have to use the code below, otherwise you will hardly see it running. Also, because this code function removes the references in the C # or Vb.Net project to PdfCreator.Exe y PdfCreator.Com.Dll

L’exemple donné par le créateur de C # GDP et Vb.Net n’est pas correct pour toutes les versions du même. Sa validité cessera à la version 2.3.2, en raison d’une erreur probable dans le COM.UI. Pour la 2.3.2 version est référencé dans le projet de programme PDFCreator.exe

Depuis la version 2.4.0, vous devez utiliser le code suivant, sinon difficile de voir le travail. Aussi parce que ce code de travail doivent être retirés des références dans le projet à C # ou Vb.Net PDFCreator.exe y PdfCreator.Com.Dll

El ejemplo dado por el creador de PDG para C # y Vb.Net no es correcto para todas las versiones de la misma. Su validez se detendrá en la versión 2.3.2, debido a un error probable en el COM.UI. Para se hace referencia a la versión 2.3.2 en el proyecto de programa de PdfCreator.Exe

A partir de la versión 2.4.0 en adelante, se debe utilizar el siguiente código, por lo demás difícil de ver el trabajo. También debido a que este código funcione ser necesario retirar las referencias en el proyecto a C # o Vb.Net PdfCreator.Exe y PdfCreator.Com.Dll

Sa, c’est le sample du PdfCreator modifié.

Private Sub testPage_btn_Click(sender As Object, e As EventArgs) Handles testPage_btn.Click

    Dim oPrintJob As System.Type = System.Type.GetTypeFromProgID("PDFCreator.PrintJob")
    Dim oPrintJobCom As Object

    Dim assemblyDir, fullPath As String

    Dim oJobQueue As System.Type = System.Type.GetTypeFromProgID("PDFCreator.JobQueue")
    Dim oJobQueueCom As Object = System.Activator.CreateInstance(oJobQueue)

    Dim oPdfCreatorDef As System.Type = System.Type.GetTypeFromProgID("PDFCreator.PdfCreatorObj")
    Dim oPdfCreatorObj As Object = System.Activator.CreateInstance(oPdfCreatorDef)

    Try
        assemblyDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
        assemblyDir = assemblyDir.Replace("\bin\Debug", "\Results")
        fullPath = Path.Combine(assemblyDir, "TestPage_2Pdf.pdf")

        oJobQueueCom.Initialize() 'MsgBox("Initializing PDFCreator queue...")

        printFile() 'MsgBox("Printing windows test page...")
        If Not oJobQueueCom.WaitForJob(10) Then
            MsgBox("The print job did not reach the queue within " & " 10 seconds")
        Else
            'MsgBox("Currently there are " & oJobQueueCom.Count & " job(s) in the queue")
            oPrintJobCom = oJobQueueCom.NextJob 'MsgBox("Getting job instance")
            oPrintJobCom.SetProfileByGuid("DefaultGuid")
            oPrintJobCom.ConvertTo(fullPath) 'MsgBox("Converting under ""DefaultGuid"" conversion profile")

            If (Not oPrintJobCom.IsFinished Or Not oPrintJobCom.IsSuccessful) Then
                MsgBox("Could not convert the file: " & fullPath)
            Else
                MsgBox("Job finished successfully")
            End If
        End If
    Catch Ex As Exception
        MessageBox.Show("Original error: " & Ex.Message)
    Finally
        MsgBox("Releasing the queue object")
        oJobQueueCom.ReleaseCom()
    End Try
End Sub