hi devs, my problem is that i can print a multiple page but what i'm gonna do is that i will download it as pdf first and print it all, i did a one click button using javascript but i can't do a multiple page here's my code below.
protected void Page_Load(object sender, EventArgs e)
{
try
{
Session["pager"] = ((DataTable)Session["table"]).Rows.Count;
rptDoc.Load(Server.MapPath(Session["path"].ToString()));
string aaa = Session["path"].ToString();
rptDoc.SetDataSource((DataTable)Session["table"]);
reportViewer.ReportSource = rptDoc;
reportViewer.RefreshReport();
if (!IsPostBack)
{
Session["index"] = 1;
lblback.Text = Session["back"].ToString();
}
}
catch (Exception ex)
{
error.ErrorLogs(Session["UserName"].ToString(), url, ex);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertmessage", "alert('" + ConString.ErrorMessage() + "')", true);
}
}
<input id="btnPrint" type="button" value="Print" onclick="Print()" />
<div id="dvReport">
<CR:CrystalReportViewer ID="reportViewer" runat="server" AutoDataBind="true"
BestFitPage="False" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" PrintMode="ActiveX" HasGotoPageButton="False" HasPageNavigationButtons="False" />
</div>
<script type="text/javascript">
function Print() {
var dvReport = document.getElementById("dvReport");
var frame1 = dvReport.getElementsByTagName("iframe")[0];
if (navigator.appName.indexOf("Internet Explorer") != -1 || navigator.appVersion.indexOf("Trident") != -1) {
frame1.name = frame1.id;
window.frames[frame1.id].focus();
window.frames[frame1.id].print();
}
else {
var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
frameDoc.print();
}
}
</script>
What I have tried:
my original code is this.
protected void btnPrint_Click(object sender, EventArgs e)
{
Session["pager"] = ((DataTable)Session["table"]).Rows.Count;
rptDoc.Load(Server.MapPath(Session["path"].ToString()));
string aaa = Session["path"].ToString();
rptDoc.SetDataSource((DataTable)Session["table"]);
reportViewer.ReportSource = rptDoc;
reportViewer.RefreshReport();
PrinterSettings printerSettings = new PrinterSettings();
PrintDocument localPrinter = new PrintDocument();
printerSettings.PrinterName = localPrinter.PrinterSettings.PrinterName;
rptDoc.PrintToPrinter(printerSettings, new PageSettings(), false);
}
i change it to javascript because of some printer problem on my side i can use this and print a multiple page but whenever i launched this an the client tried to used my website
PrintDocument localPrinter = new PrintDocument();
this is throwing an error that i can't detect the client print but when i tried it work's perfectly that's why i tried javascript.