+1 800 256 3608 (toll-free in North America) or +49 7531 90 60 10| service@combit.com

Controlling Printed Image Size and Relative Offset


(Guest) #1

I am using LL v13 and its .NET component with C# .NET. Also, I am implementing a custom print loop.

As part of the print and preview processes, I would like to control both the size of the printed image, as well as the offset of said image on the physical paper.

Here is an example of what we used to do in C++:

int CALLBACK LLCallback(INT wParam, LONG lParam, LONG lUserParam)
{
	switch (wParam)
	{
	case LL_CMND_PAGE:
		{
			scLlPage * p = (scLlPage *)lParam;
			if ((p->_nSize == sizeof(scLlPage)) && (p->_bPreDraw) && (lUserParam != NULL))
			{
				LLCALL_INFO_REPORT * pLLInfo = (LLCALL_INFO_REPORT *)lUserParam;

				// move over, and center by percent
				CDC dc;
				dc.Attach(p->_hPaintDC);
				int md = 1000;
				double m_Percent = (double)pLLInfo->Percent / 100.0;
				CSize cs = dc.GetViewportExt();
				int ox = (int)((1-m_Percent)*cs.cx/2);
				ox = MulDiv((int)(pLLInfo->OffsetX*1000),dc.GetDeviceCaps(LOGPIXELSX),md)+ox;
				int oy = (int)((1-m_Percent)*cs.cy/2);
				oy = MulDiv((int)(pLLInfo->OffsetY*1000),dc.GetDeviceCaps(LOGPIXELSY),md)+oy;

				// actual dc changes here ...
				dc.OffsetViewportOrg(ox,oy);
				dc.ScaleViewportExt((int)(m_Percent*md),md,(int)(m_Percent*md),md); 	

				dc.Detach();
			}

			{
				CDC dc;
				dc.Attach(p->_hPaintDC);

				CPen * pPen = (CPen *)dc.SelectStockObject(BLACK_PEN);
				CPoint p1(dc.GetWindowOrg());
				CPoint p2(dc.GetWindowExt());
				dc.MoveTo(p1);
				dc.LineTo(p2);
				dc.MoveTo(p2.x,p1.y);
				dc.LineTo(p1.x,p2.y);
				dc.SelectObject(pPen);

				dc.Detach();
			}*/
		}
		break;
}
return 0;
}

I am porting our C++ code into C# .NET, but this operation I cannot convert. I have attempted to use events such as LL_DrawPage, ChangeDCPropertiesCreate, etc. where a DC is provided, but I receive access violations when I attempt to make use of them (such as by create P/Invoke methods of those used in the C++ code).

Could someone please help me to understand how I can achieve the control in .NET that we previously enjoyed in C++?

Thank you,

Don Boitnott