Display novaPDF for SDK printing preferences from code
-
- Posts: 15
- Joined: Tue Nov 30, 2010 11:40 am
Display novaPDF for SDK printing preferences from code
Hi,
Is there a way to display (call) the "Printing Preferences" dialog, for the "novaPDF for SDK" printer, from my code using the SDK?
-zarko
Is there a way to display (call) the "Printing Preferences" dialog, for the "novaPDF for SDK" printer, from my code using the SDK?
-zarko
-
- Posts: 286
- Joined: Wed Dec 16, 2009 12:46 pm
Re: Display novaPDF for SDK printing preferences from code
Hello,
The "Printing Preferences" dialog for a printer can be opened by calling the DocumentProperties Windows API function. Here is the C++ code for this:
BOOL bPrinterOpened = OpenPrinter(pwszPrinterName, &hPrinter, NULL);
if (!bPrinterOpened)
{
wsprintf(wsMsg, L"Could not open printer (%s)", pwszPrinterName);
MessageBox(wsMsg);
}
else
{
// get the number of bytes required for the full DEVMODE structure by
// calling DocumentProperties and specifying zero in the fMode parameter
HWND hwndActiveWindow = ::GetActiveWindow();
LONG nBytesNeeded = ::DocumentPropertiesW(hwndActiveWindow, hPrinter, pwszPrinterName, NULL, NULL, 0);
pDevMode = (LPDEVMODE)malloc(nBytesNeeded);
// get in pDevMode the changes made by user to printer settings
LONG nReturnValue = ::DocumentPropertiesW(hwndActiveWindow, hPrinter, pwszPrinterName, pDevMode, NULL, DM_IN_PROMPT | DM_OUT_BUFFER);
if (nReturnValue < 0)
{
wsprintf(wsMsg, L"The printer is unavailable (%s)", pwszPrinterName);
MessageBox(wsMsg);
}
else if (IDOK == nReturnValue)
{
// if the user clicked on OK button, save the new printer settings
nReturnValue = ::DocumentPropertiesW(hwndActiveWindow, hPrinter, pwszPrinterName, pDevMode, pDevMode, DM_IN_BUFFER | DM_OUT_BUFFER);
if (IDOK != nReturnValue)
{
wsprintf(wsMsg, L"Could not save printer settings (%s)", pwszPrinterName);
MessageBox(wsMsg);
}
}
}
if (NULL != pDevMode)
{
free(pDevMode);
}
if (NULL != hPrinter)
{
ClosePrinter(hPrinter);
}
Thank you.
The "Printing Preferences" dialog for a printer can be opened by calling the DocumentProperties Windows API function. Here is the C++ code for this:
BOOL bPrinterOpened = OpenPrinter(pwszPrinterName, &hPrinter, NULL);
if (!bPrinterOpened)
{
wsprintf(wsMsg, L"Could not open printer (%s)", pwszPrinterName);
MessageBox(wsMsg);
}
else
{
// get the number of bytes required for the full DEVMODE structure by
// calling DocumentProperties and specifying zero in the fMode parameter
HWND hwndActiveWindow = ::GetActiveWindow();
LONG nBytesNeeded = ::DocumentPropertiesW(hwndActiveWindow, hPrinter, pwszPrinterName, NULL, NULL, 0);
pDevMode = (LPDEVMODE)malloc(nBytesNeeded);
// get in pDevMode the changes made by user to printer settings
LONG nReturnValue = ::DocumentPropertiesW(hwndActiveWindow, hPrinter, pwszPrinterName, pDevMode, NULL, DM_IN_PROMPT | DM_OUT_BUFFER);
if (nReturnValue < 0)
{
wsprintf(wsMsg, L"The printer is unavailable (%s)", pwszPrinterName);
MessageBox(wsMsg);
}
else if (IDOK == nReturnValue)
{
// if the user clicked on OK button, save the new printer settings
nReturnValue = ::DocumentPropertiesW(hwndActiveWindow, hPrinter, pwszPrinterName, pDevMode, pDevMode, DM_IN_BUFFER | DM_OUT_BUFFER);
if (IDOK != nReturnValue)
{
wsprintf(wsMsg, L"Could not save printer settings (%s)", pwszPrinterName);
MessageBox(wsMsg);
}
}
}
if (NULL != pDevMode)
{
free(pDevMode);
}
if (NULL != hPrinter)
{
ClosePrinter(hPrinter);
}
Thank you.
Follow us to stay updated:
- Newsletter (get a discount for subscribing): https://www.novapdf.com/newsletter.html
- Facebook: https://www.facebook.com/novapdf
- Twitter: https://twitter.com/novapdf
- Linkedin: https://www.linkedin.com/showcase/novapdf
-
- Posts: 15
- Joined: Tue Nov 30, 2010 11:40 am
Re: Display novaPDF for SDK printing preferences from code
Great, thanks!
Here's Delphi version:
-zarko
Here's Delphi version:
Code: Select all
const
PRINTER_NAME = 'novaPDF for SDK v7';
var
hPrinter : Cardinal;
hwndActiveWindow : HWND;
nBytesNeeded, nReturnValue : integer;
pDevMode : PDeviceMode;
begin
if OpenPrinter(PRINTER_NAME, hPrinter, nil) then
try
// get the number of bytes required for the full DEVMODE structure by
// calling DocumentProperties and specifying zero in the fMode parameter
hwndActiveWindow := GetActiveWindow();
nBytesNeeded := DocumentProperties(hwndActiveWindow, hPrinter, PRINTER_NAME, nil, nil, 0);
pDevMode := AllocMem(nBytesNeeded);
try
// get in pDevMode the changes made by user to printer settings
nReturnValue := DocumentProperties(hwndActiveWindow, hPrinter, PRINTER_NAME, pDevMode, nil, DM_IN_PROMPT OR DM_OUT_BUFFER);
if nReturnValue < 0 then
begin
MessageDlg('Printer unavailable', mtError, [mbOK], -1);
end
else if nReturnValue = IDOK then
begin
// if the user clicked on OK button, save the new printer settings
nReturnValue := DocumentProperties(hwndActiveWindow, hPrinter, PRINTER_NAME, pDevMode, pDevMode, DM_IN_BUFFER OR DM_OUT_BUFFER);
end;
finally
FreeMem(pDevMode, nBytesNeeded);
end;
finally
ClosePrinter(hPrinter);
end
else
MessageDlg('Could not open printer', mtError, [mbOK], -1);
end;
-zarko