Как получить документ printdocument to ASP.NET
привет, у меня есть страница, которую я хотел распечатать в pdf-файл.не в конкретной настройке устройства, а для печати его в виде PDF-файла ... есть хоть одна идея?
я уже пробовал этот код. но это только освежает мою страницу ... ничего не происходит. пожалуйста, поправьте меня, если это подходящий код или нет.. Спасибо, что поделились своими идеями.
Что я уже пробовал:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Web.UI; using System.Web.UI.WebControls; using MySql.Data.MySqlClient; using MySql.Web; using MySql.Data; using System.IO; using System.Drawing; using System.Drawing.Printing; using System.Windows.Forms; using System.ComponentModel; namespace SchoolPortal { public partial class nmb : System.Web.UI.Page { public Font printFont; public StreamReader streamToPrint; static string filePath; MySqlConnection conn = new MySqlConnection(@"Data Source =localhost; port=3306;Initial Catalog=mysql_testing;Uid=root;Pwd=secret;Database=payroll_system;"); MySqlCommand cmd; MySqlDataReader mdr; protected void Page_Load(object sender, EventArgs e) { txte.Text = Session["e"].ToString(); } protected void btnView_Click(object sender, EventArgs e) { conn.Open(); string SelectQuery = "SELECT * From info_info WHERE employee_ID='" + txte.Text + "' AND month='" + txtmonth.Text + "' AND days='" + txtday.Text + "' AND year ='" + txtyear.Text + "'"; cmd = new MySqlCommand(SelectQuery, conn); mdr = cmd.ExecuteReader(); if (mdr.Read()) { lblemployee.Text = mdr.GetString("employee_ID"); lblmonth.Text = mdr.GetString("month"); lbldays.Text = mdr.GetString("days"); lblyear.Text = mdr.GetString("year"); lbllast.Text = mdr.GetString("Name"); lblLast1.Text = mdr.GetString("Name"); lblposition.Text = mdr.GetString("position"); lblregular.Text = mdr.GetString("regular"); lbltotal.Text = mdr.GetString("totalday"); lblGen.Text = mdr.GetString("month1"); lblStat.Text = mdr.GetString("day1"); lblCon.Text = mdr.GetString("month2"); lblperm.Text = mdr.GetString("day2"); lblcent.Text = mdr.GetString("percent"); lblamount.Text = mdr.GetString("amount"); lblcent1.Text = mdr.GetString("percent1"); lblamount1.Text = mdr.GetString("amount1"); lblcent2.Text = mdr.GetString("percent2"); lblamount2.Text = mdr.GetString("amount2"); lblcent3.Text = mdr.GetString("percent3"); lblamount3.Text = mdr.GetString("amount3"); lblholiday.Text = mdr.GetString("holiday"); lblspecial.Text = mdr.GetString("special"); //lbltotal.Text = mdr.GetString("total"); lbldeduction.Text = mdr.GetString("deduction"); lblholds.Text = mdr.GetString("date1"); lblCash.Text = mdr.GetString("cash_advance"); lblnet.Text = mdr.GetString("net"); lbllate.Text = mdr.GetString("late"); lblundertime.Text = mdr.GetString("under_time"); lblabsent.Text = mdr.GetString("absent"); lblmess.Text = ""; } else { lblmess.Text = "no record found please check your ID number as well as month, day, and year then TRY AGAIN"; } conn.Close(); } protected void Button1_PrintPage(object sender, PrintPageEventArgs ev) { float linesPerPage = 0; float yPos = 0; int count = 0; float leftMargin = ev.MarginBounds.Left; float topMargin = ev.MarginBounds.Top; String line = null; linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); while (count < linesPerPage && ((line = streamToPrint.ReadLine()) != null)) { yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat()); count++; } if (line != null) ev.HasMorePages = true; else ev.HasMorePages = false; } public void Printing() { try { streamToPrint = new StreamReader(filePath); try { PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(Button1_PrintPage); pd.Print(); } finally { streamToPrint.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public static void Main(string[] args) { string sampleName = Environment.GetCommandLineArgs()[0]; if (args.Length != 1) { Console.WriteLine("Usage : " + sampleName + "<file path>"); return; } filePath = args[0]; new PrintingPermissionLevel(); } } }