// JP opened flex table

Click to See Complete Forum and Search --> : Printing: Form Size


dave2k
February 22nd, 2007, 04:12 AM
Hi,

I have for a while now been trying to set custom dimensions for the page size while printing. I previously for i could get away with setting the width/height fields of the DEVMODE structure, but then found that this doesn't work with the latest versions of windows, and have to create and set a custom form. I have done this, but when i send it to the printer the printer just doesn't pick up the new form dimensions.

There doesn't seem to be much on this around the web, so was wondering if anyone has any experience in this? My code below sets a custom form and sends a blank page to the printer. I am wondering why the printer doesn't pick up the page size:

#include "stdafx.h"
#include <windows.h>
#include "Winspool.h"

int _tmain(int argc, _TCHAR* argv[])
{
DWORD dw = 0;
DWORD size;
HDC hdcPrint;
HANDLE printerHandle;

dw=::GetLastError();
DOCINFO docInfo;
ZeroMemory(&docInfo, sizeof(docInfo));
docInfo.cbSize = sizeof(docInfo);
docInfo.lpszDocName = L"David Test";
dw=::GetLastError();

// Get the length of the printer name.
bool err= GetDefaultPrinter(NULL, &size);
dw=::GetLastError();
TCHAR* buffer = new TCHAR[size];

// Get the printer name.
if(!GetDefaultPrinter(buffer, &size))
{
printf("Failure");
}
else
{

hdcPrint = CreateDC(NULL, buffer, NULL, NULL);

OpenPrinter(buffer, &printerHandle, NULL);

FORM_INFO_1 fi1;

SIZEL sizel = {464, 464};
RECTL rectl = {0,0, 464, 464};
FORM_INFO_1 f = {NULL,TEXT("dude2"),sizel,rectl};
DWORD dr=sizeof(f);

BOOL bbbb= SetForm(
printerHandle, // handle to printer object
_T("dude2"), // form name
1, // information level
(LPBYTE)&f // form buffer
);

StartDoc(hdcPrint, &docInfo);
StartPage(hdcPrint);
EndPage(hdcPrint);
EndDoc(hdcPrint);

ClosePrinter(printerHandle);
DeleteDC(hdcPrint);

}

return 0;
}the code doesn't fail, but when it goes to my default printer (fine print program), the form is still of type A4.

Finding this really tricky!

//JP added flex table