Print หน้าเว็บเพจล้นหน้ากระดาษมีวิธีย่อขนาดให้พอดีหน้ากระดาษได้อย่างไรครับ
ผมทำตามโค้ดดังนี้แต่ออกมาล้นหน้ากระดาษเวลาปริ้นครับ
หน้า class Code (VB.NET)
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports System.Text
Imports System.Web.SessionState
Public Class PrintHelper
Public Sub New()
End Sub
Public Shared Sub PrintWebControl(ByVal ctrl As Control)
PrintWebControl(ctrl, String.Empty)
End Sub
Public Shared Sub PrintWebControl(ByVal ctrl As Control, ByVal Script As String)
Dim stringWrite As StringWriter = New StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(stringWrite)
If TypeOf ctrl Is WebControl Then
Dim w As Unit = New Unit(100, UnitType.Percentage)
CType(ctrl, WebControl).Width = w
End If
Dim pg As Page = New Page()
pg.EnableEventValidation = False
If Script <> String.Empty Then
pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script)
End If
Dim frm As HtmlForm = New HtmlForm()
pg.Controls.Add(frm)
frm.Attributes.Add("runat", "server")
frm.Controls.Add(ctrl)
pg.DesignerInitialize()
pg.RenderControl(htmlWrite)
Dim strHTML As String = stringWrite.ToString()
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Write(strHTML)
HttpContext.Current.Response.Write("<script>window.print();</script>")
HttpContext.Current.Response.End()
End Sub
End Class
หน้าที่จะปริ้น Code (VB.NET)
Protected Sub imgBtnPrint_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgBtnPrint.Click
Session("ctrl") = Panel1
ClientScript.RegisterStartupScript(Me.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=300px,width=300px,scrollbars=1');</script>")
End Sub