How to change current paper form?

You can use following VC++ source code to retrieve paper size information from a special printer,

// Function that enumerates all available paper forms or paper size:
void FillPrinterPapers()
{
int nPaperCount = 0;
WORD* lpPapers = NULL;
char* lpPaperNames = NULL;
POINT* lpPaperSizes = NULL;

HANDLE hPrinter = NULL;

if (OpenPrinter(PRINTER_NAME, &hPrinter, NULL))
{
DWORD dwNeeded = 0;

// get printer forms
nPaperCount = DeviceCapabilities(PRINTER_NAME, NULL, DC_PAPERS, NULL, NULL);
if (nPaperCount)
{
lpPapers = new WORD[nPaperCount];
ZeroMemory(lpPapers, sizeof(WORD)*nPaperCount);
DeviceCapabilities(PRINTER_NAME, NULL, DC_PAPERS, (LPSTR) lpPapers, NULL);

lpPaperNames = new char[nPaperCount*64];
ZeroMemory(lpPaperNames, sizeof(char)*64*nPaperCount);
DeviceCapabilities(PRINTER_NAME, NULL, DC_PAPERNAMES, lpPaperNames, NULL);

lpPaperSizes = new POINT[nPaperCount];
ZeroMemory(lpPaperSizes, sizeof(POINT)*nPaperCount);
DeviceCapabilities(PRINTER_NAME, NULL, DC_PAPERSIZE, (LPSTR) lpPaperSizes, NULL);
}

ClosePrinter(hPrinter);
}
else
{
// report error
}
}

// Function that sets current paper form:
BOOL SetPrinterPaper(short dmPaperSize, const char* pszFormName)
{
BOOL bResult = FALSE;
HANDLE hPrinter = NULL;

if (OpenPrinter(PRINTER_NAME, &hPrinter, NULL))
{
DWORD dwNeeded = 0;
GetPrinter(hPrinter, 2, NULL, 0, &dwNeeded);
if (dwNeeded > 0)
{
BYTE* lpPrinterInfo = new BYTE[dwNeeded];

if (GetPrinter(hPrinter, 2, lpPrinterInfo, dwNeeded, &dwNeeded))
{
DEVMODE* pDevMode = ((PRINTER_INFO_2*) lpPrinterInfo)->pDevMode;
pDevMode->dmPaperSize = dmPaperSize;
lstrcpy((char*) &pDevMode->dmFormName, pszFormName);
SetPrinter(hPrinter, 2, lpPrinterInfo, 0);
bResult = TRUE;
}
else
{
// report error
}

delete [] lpPrinterInfo;
}

ClosePrinter(hPrinter);
}
else
{
// report error
}

return bResult;
}

VeryPDF

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Random Posts

This entry was posted in @VeryPDF News, PDF Print. Bookmark the permalink.

One Response to How to change current paper form?

  1. Pingback: How to add new paper form of custom size? | VeryPDF Knowledge Base

Leave a Reply

Your email address will not be published. Required fields are marked *


Verify Code   If you cannot see the CheckCode image,please refresh the page again!