[novaPDF SDK] SetDefaultPrinter doesn't work after RestoreDefaultPrinter is called

This article applies only to novaPDF. If you don't have it yet, you must download it first.

DOWNLOAD novaPDF
Feb 21, 2019

novaPDF SDK

We strive to keep our articles as accurate as possible. If you notice any inconsistencies or outdated info please let us know.

[novaPDF SDK] SetDefaultPrinter doesn't work after RestoreDefaultPrinter is called

novaPDF isn't set as the default printer after calling RestoreDefaultPrinter() function.

I have set-up a workflow for novaPDF SDK that does this: first it calls SetDefaultPrinter() to set novaPDF as the default printer, then it sends a print job to it, and after that reverts back to the previous default printer calling the RestoreDefaultPrinter() function. However, after the first cycle of this workflow, novaPDF isn't set as the default printer anymore even if I use the SetDefaultPrinter() function again. Why?

Answer


This usually happens when the call to the RestoreDefaultPrinter() function is sent too fast, before the print job is actually assigned to a printer queue. In our samples (converter samples), we  wait for a message from novaPDF that the job was finished before calling the RestoreDefaultPrinter().

An easier way is to use some events from novaPDF. Before starting the print job, you have to inform novaPDF that you want to wait for an event so you should call:

pNova->RegisterNovaEvent("NOVAPDF_EVENT_FILE_SAVED");

After you send the job to the printer, call this function:

pNova->WaitForNovaEvent(ULONG p_nMiliseconds, BOOL* p_bTimeout);

This function will return when the event was signaled (which means the PDF is finished) or when the time was elapsed. After that you can call the RestoreDefaultPrinter() function.