How to set programmatically the page related settings (page size, layout) via novaPDF SDK

The page related settings have a different behavior than the other settings (save, compression, fonts, security,...). While the last are specific to the novaPDF printer driver, the page related settings are used for all printer drivers and can be set by system calls (check the DEVMODE Windows structure).

For example, if you start to print a document from an application, you can usually set the page size, page layout, scale and resolution from a Page setup dialog in that specific application. These settings (read from the application that initiates the printing) are shown on the Page tab on novaPDF printer and they are used also when generating the PDF document.

To change this behavior and use the specific settings set by the novaPDF printer interface (or novaPDF SDK), you can check the Profile settings override paper settings option from the printing application check box on the Profiles tab. This flag is saved separately for each profile. To change programmatically the flag add the next line:
pNova.SetOptionLong2(NOVAPDF_PAPER_OVERRIDE, 1, PROFILE_NAME);

But a better approach is to change page settings in this DEVMODE structure, because in this way both the printing application and the printer driver will be informed about this new page. It is better that the application knows this page, so it sends the information formatted to this size.

Here is the Hello World C++ sample, modified to set page width and height:

HANDLE hPrinter;
PDEVMODEW pDevmode = NULL;
PRINTER_DEFAULTS pd = { NULL, NULL, PRINTER_ACCESS_USE };
//start print job
if (OpenPrinter(PRINTER_NAME, &hPrinter, &pd))
{
//get default printer DEVMODE
int nSize = DocumentProperties(NULL, hPrinter, PRINTER_NAME, NULL, NULL, 0);
pDevmode = (PDEVMODEW)LocalAlloc(LPTR, nSize);
DocumentProperties(NULL, hPrinter, PRINTER_NAME, pDevmode, NULL, DM_OUT_DEFAULT);
//set page size in DEVMODE
pDevmode->dmPaperSize = DMPAPER_USER;
pDevmode->dmPaperLength = 1000;
pDevmode->dmPaperWidth = 1000;
pDevmode->dmFields = DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH;
DocumentProperties(NULL, hPrinter, PRINTER_NAME, pDevmode, pDevmode, DM_IN_BUFFER | DM_OUT_BUFFER);

//Print a page (use modified DEVMODE)
HDC hDC = CreateDC(L"", PRINTER_NAME, NULL, pDevmode);
DOCINFO docInfo = {sizeof(DOCINFO)};
// PDF document name and path
docInfo.lpszDocName = PDF_FILE_NAME;
StartDoc(hDC,&docInfo);
StartPage(hDC);
// Draw text on page
TextOut(hDC, 100, 80, PDF_TEXT, (int) wcslen(PDF_TEXT));
EndPage(hDC);
EndDoc(hDC);
DeleteDC(hDC);
//print job sent to printer
LocalFree(pDevmode);
ClosePrinter(hPrinter);
}

Comments


NEW: novaPDF 8.8.945