I am working on an application for which requires the following functionality: The user clicks a button on the web page and this causes a document to be printed without any further user intervention.
The approach I am using to deliver this functionality is to embed a Windows Control (using a Windows Control Library) in the web-page. (A tutorial on doing this is available here.) I worked through a similar tutorial and the Windows Control was properly created and displayed.
The next step was to try actually printing. I first tested the printing code is a stand-alone application to make sure that it functions properly. It does. I have provided a simplified version of that code (see below) for those who are interested.
The specific manner in which the code gets activated is this: This line of code, .Attributes.Add("OnClick", "myPrintFunction();") appears in Page_Load to associate a JavaScript function with the button. This JavaScript function is quite simple:
function myPrintFunction() {
var winCtrl = document.getElementById("MyWinControl");
winCtrl.doMyPrintFunction();
}
The problem is this: The code throws the following error:
mscorlib: Request for the permission of type 'System.Drawing.Printing.PrintingPermission, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.
What permissions do I need to change to make this work? One web-page I found seemed to suggest that setting Trust=Full might help, but it was not clear a) if this would help, or b) how to do this.
Thanks for your help!
Printing code:
Public Class MyWinControl
Public Sub doMyPrintFunction()
Dim prtMyDoc As PrintDocument = printerSetup()
If (Not prtMyDoc Is Nothing) Then prtMyDoc.Print()
End Sub
Private Function printerSetup() As PrintDocument
Dim prtMyDoc As New PrintDocument
AddHandler prtMyDoc.PrintPage, AddressOf prtMyDoc_PrintPage
prtMyDoc.PrinterSettings.PrinterName = "<my default printer>"
Return prtMyDoc
End Function
Private Sub prtMyDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
' use graphics native call to build up page to be printed
' it is accessed via e.Graphics
End Sub
End Class