printpreview in a dialog

To get printpreview in a dialog, two global methods are needed:

function printPreviewInDialog(formName)
{
	if (application.getApplicationType() == 2) //webclient print == pdf is always opened separate tab/window by browser anyway
	{
		globals.startinprintpreview = formName
		application.showFormInDialog( forms[formName],  -1,  -1,  -1,  -1, "PRINT_TEST",  true,  false,  "printing",  true)
	}
	else
	{
		globals.startinprintpreview = null
		forms[formName].controller.showPrintPreview( true)
	}
}

function checkForPrintPreview()
{
	if (globals.startinprintpreview == currentcontroller.getName())
	{
		currentcontroller.showPrintPreview( true)
		globals.startinprintpreview = 'close_printpreview'
	}
	else if (globals.startinprintpreview == 'close_printpreview')
	{
		if (application.getApplicationType() == 2) 
		{
			application.closeFormDialog("printing")
		}
	}
}

If you want to show a printpreview in a dialog call for example: printPreviewInDialog(‘customer’) //customers is form name
In the forms you ever might want to show in printpreview, do in the onShow event a call to checkForPrintPreview()