using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; using System.Drawing.Printing; using System.Windows.Forms; using System.Drawing.Text; public partial class LandScapePrint : System.Web.UI.Page { private int fontcount; private int fontposition = 1; private float ypos = 1; private PrintPreviewDialog previewDlg = null; protected void Page_Load(object sender, EventArgs e) { //InstalledFontCollection ifc = new InstalledFontCollection(); ////Get font families //FontFamily[] ffs = ifc.Families; //Font f; } protected void Submit_Click(object sender, EventArgs e) { //PrintDocument pd = new PrintDocument(); ////Add print-page event handler //pd.PrintPage+=new PrintPageEventHandler(this.pd_PrintPage); //pd.DefaultPageSettings.Landscape = true; //pd.Print(); previewDlg = new PrintPreviewDialog(); //Create a PrintDocument object PrintDocument pd = new PrintDocument(); //Add print-page event handler pd.PrintPage +=new PrintPageEventHandler(this.pd_PrintPage); pd.Print(); } protected void pd_PrintPage(object sender, PrintPageEventArgs e) { ypos = 1; float pageheight = e.MarginBounds.Height; //Create a Graphics object Graphics g = e.Graphics; //Get installed fonts InstalledFontCollection ifc = new InstalledFontCollection(); //Get font families FontFamily[] ffs = ifc.Families; //Draw string on the paper while (ypos + 60 < pageheight && fontposition < ffs.GetLength(0)) { //Get the font name Font f = new Font(ffs[fontposition].GetName(0), 25); //if (ffs.ToString()=="Monotype Corsiva") //{ // ffs=FontStyle //} //Draw string g.DrawString(ffs[fontposition].GetName(0), f, new SolidBrush(Color.Black), 1, ypos); fontposition = fontposition + 1; ypos = ypos + 60; } if (fontposition < ffs.GetLength(0)) { //Has more pages?? e.HasMorePages = true; } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LandScapePrint.aspx.cs" Inherits="LandScapePrint" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><head> <title></title> <style type="text/css"> .style1 { font-family: Arial; } </style> </head> <body> <form id="Form1" runat="server"> <table> <tbody> <tr> <td colspan="2" class="style1"> <strong>Test Form</strong></td> </tr> <tr> <td class="style1"> First Name</td> <td class="style1"> </td> </tr> <tr> <td class="style1"> Last Name</td> <td class="style1"> </td> </tr> <tr> <td colspan="2"> <asp:Button id="Submit" onclick="Submit_Click" runat="server" Text="Submit" CssClass="style1"></asp:Button> </td> </tr> </tbody> </table> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)