How to add new paper form of custom size?

See “How to change current paper form on the printer?” article from following web page,

https://www.verypdf.com/wordpress/201109/how-to-change-current-paper-form-2423.html

Do you know how to add the new paper size or paper form of custom size to the printer? if not, please refer to the sample VC++ source code at below,

if (OpenPrinter(PRINTER_NAME, &hPrinter, NULL))
{
FORM_INFO_1 FormInfo = {0};
FormInfo.pName = (char*) &szFormName;
FormInfo.Size.cx = FormInfo.ImageableArea.right = nFormWidth*1000;
FormInfo.Size.cy = FormInfo.ImageableArea.bottom = nFormLength*1000;

if (AddForm(hPrinter, 1, (BYTE*) &FormInfo))
{
FillPrinterPapers();

// set new paper to the printer
for (int i=0; i<nVeryPDFPaperCount; i++)
{
if (lstrcmp(szFormName, &pPaperNames[i*64]) == 0)
{
SetPrinterPaper(lpPapers[i], szFormName);
FillPrinterPapers();
break;
}
}
}
else
{
// report error
}

ClosePrinter(hPrinter);
}

How to change print quality (resolution) and paper orientation to target printer?

HANDLE hPrinter = NULL;
PRINTER_DEFAULTS printerDef = { NULL, NULL, PRINTER_ALL_ACCESS };

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

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

// get current printer settings
if (GetPrinter(hPrinter, 2, lpPrinterInfo, dwNeeded, &dwNeeded))
{
DEVMODE* lpDevMode = ((PRINTER_INFO_2*) lpPrinterInfo)->lpDevMode;
lpDevMode->dmFields = lpDevMode->dmFields|DM_ORIENTATION |DM_PRINTQUALITY|DM_YRESOLUTION;

// change parameters
lpDevMode->dmOrientation = 1;    // Orientation: 1 - portrait; 2 - landscape.
lpDevMode->dmPrintQuality = 300; // Horizontal resolution value
lpDevMode->dmYResoultion = 300; // Vertical resoultion value

// save changed settings
if (!SetPrinter(hPrinter, 2, lpPrinterInfo, 0))
{
// report error
}
}
else
{
// report error
}

delete [] lpPrinterInfo;
}

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

You can also look at "Adding custom paper sizes to named printers" article at following web page,

http://www.codeproject.com/KB/printing/custom_paper_sizes.aspx

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)

Related Posts

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!