Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 01, 2010 03:54 PM by pnkmouli
Member
64 Points
17 Posts
Sep 01, 2010 03:54 PM|LINK
Hi,
Try this link http://www.vbgold.com/index.shtml#ASPPrinterCOM
Use JavaScript to print from client side. Pass document full path to JavaScript from C# or VB code.
Client has to install the ActiveX to perform any client side printing.
Add the ActiveX component to page, so client can download the .cab file from the website.
You have to add below code in .aspx page
*********************************************************************
<script language ="javascript" type ="text/javascript" >
var myArray = new Array();
function PrintFile() {
var Prn = new ActiveXObject('ASPPrinterCOM.ASPPrinter');
var listString = document.getElementById('PrintFiles').value;
var listArray = listString.split('~'); // Now you have an array in javascript of each value
for (var i = 0; i < listArray.length; i++) {
//alert(file_get_ext(listArray[i]));
switch (file_get_ext(listArray[i])) {
case "html":
Prn.PrintHTMLDocument(listArray[i]);
break;
case "pdf":
//Prn.PrintPDFFile(listArray[i]);
Prn.PrintHTMLDocument("http://localhost:1749/Print%20Test/PrinterCOM/demo.html");
case "txt":
case "rtf":
//Prn.PrintTextFile(listArray[i]);
default:
}
Prn.About();
Prn=null
function file_get_ext(filename) {
return typeof filename != "undefined" ? filename.substring(filename.lastIndexOf(".") + 1, filename.length).toLowerCase() : false;
</script>
<object id="ASPPrinter" classid="CLSID:48CB850F-41FF-4EE6-B87D-FB9EC26D193F" codebase="ASPPrinter.CAB#version=2,1,0,200"></object>
<asp:HiddenField ID="PrintFiles" runat="server" />
<asp:Button ID="PrintMe" Text="Print Now" runat ="server" />
***********************************************************************************************************************
Code behind
********************************************************
Add all the documents in Page_load. If you use check box, add all the documents in CheckBox OnChange event
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim _PrintFilesArray As New ArrayList
_PrintFilesArray.Add("http://localhost:1749/Print%20Test/PrinterCOM/demo.html")
_PrintFilesArray.Add("http://localhost:1749/Print%20Test/PrinterCOM/demo.pdf")
_PrintFilesArray.Add("http://localhost:1749/Print%20Test/PrinterCOM/demo.txt")
_PrintFilesArray.Add("http://localhost:1749/Print%20Test/PrinterCOM/demo.rtf")
PrintFiles.Value = getPrintFiles(_PrintFilesArray)
PrintMe.Attributes.Add("onClick", "PrintFile()")
Dim objP As New ASPPrinter
objP.PaperSize = 1
'it should print it from default printer
'objP.SetPrinter("Printer Name")
End Sub
Private ReadOnly Property getPrintFiles(ByVal _ArrayList As ArrayList) As String
Get
Dim intCount As Integer
Dim strFinal As String = ""
For intCount = 0 To _ArrayList.Count - 1
If intCount > 0 Then
strFinal += "~"
End If
strFinal += _ArrayList.Item(intCount).ToString
Next
Return strFinal
End Get
End Property
This is just an idia.
You have to update some of the bits in server side code.
Enjoy....
Regards,
Novel Kishore Mouli Padeti.
pnkmouli
Member
64 Points
17 Posts
Re: Automatic Batch Printing in ReportViewer Remote Mode
Sep 01, 2010 03:54 PM|LINK
Hi,
Try this link http://www.vbgold.com/index.shtml#ASPPrinterCOM
Use JavaScript to print from client side. Pass document full path to JavaScript from C# or VB code.
Client has to install the ActiveX to perform any client side printing.
Add the ActiveX component to page, so client can download the .cab file from the website.
You have to add below code in .aspx page
*********************************************************************
<script language ="javascript" type ="text/javascript" >
var myArray = new Array();
function PrintFile() {
var Prn = new ActiveXObject('ASPPrinterCOM.ASPPrinter');
var listString = document.getElementById('PrintFiles').value;
var listArray = listString.split('~'); // Now you have an array in javascript of each value
for (var i = 0; i < listArray.length; i++) {
//alert(file_get_ext(listArray[i]));
switch (file_get_ext(listArray[i])) {
case "html":
Prn.PrintHTMLDocument(listArray[i]);
break;
case "pdf":
//Prn.PrintPDFFile(listArray[i]);
Prn.PrintHTMLDocument("http://localhost:1749/Print%20Test/PrinterCOM/demo.html");
break;
case "txt":
Prn.PrintHTMLDocument("http://localhost:1749/Print%20Test/PrinterCOM/demo.html");
break;
case "rtf":
//Prn.PrintTextFile(listArray[i]);
Prn.PrintHTMLDocument("http://localhost:1749/Print%20Test/PrinterCOM/demo.html");
break;
default:
}
}
Prn.About();
Prn=null
}
function file_get_ext(filename) {
return typeof filename != "undefined" ? filename.substring(filename.lastIndexOf(".") + 1, filename.length).toLowerCase() : false;
}
</script>
<object id="ASPPrinter" classid="CLSID:48CB850F-41FF-4EE6-B87D-FB9EC26D193F" codebase="ASPPrinter.CAB#version=2,1,0,200"></object>
<asp:HiddenField ID="PrintFiles" runat="server" />
<asp:Button ID="PrintMe" Text="Print Now" runat ="server" />
***********************************************************************************************************************
Code behind
********************************************************
Add all the documents in Page_load. If you use check box, add all the documents in CheckBox OnChange event
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim _PrintFilesArray As New ArrayList
_PrintFilesArray.Add("http://localhost:1749/Print%20Test/PrinterCOM/demo.html")
_PrintFilesArray.Add("http://localhost:1749/Print%20Test/PrinterCOM/demo.pdf")
_PrintFilesArray.Add("http://localhost:1749/Print%20Test/PrinterCOM/demo.txt")
_PrintFilesArray.Add("http://localhost:1749/Print%20Test/PrinterCOM/demo.rtf")
PrintFiles.Value = getPrintFiles(_PrintFilesArray)
PrintMe.Attributes.Add("onClick", "PrintFile()")
Dim objP As New ASPPrinter
objP.PaperSize = 1
'it should print it from default printer
'objP.SetPrinter("Printer Name")
End Sub
Private ReadOnly Property getPrintFiles(ByVal _ArrayList As ArrayList) As String
Get
Dim intCount As Integer
Dim strFinal As String = ""
For intCount = 0 To _ArrayList.Count - 1
If intCount > 0 Then
strFinal += "~"
End If
strFinal += _ArrayList.Item(intCount).ToString
Next
Return strFinal
End Get
End Property
********************************************************
This is just an idia.
You have to update some of the bits in server side code.
Enjoy....
Regards,
Novel Kishore Mouli Padeti.
Durham,
United Kingdom.
Remember to click “Mark as Answer” on the post, if it helps you.