I have Window Client , and server
Client call server to get html (by string).
Client edit html file, and want to PRINT IT. Real print- paper, offline.
=> almost everyone said, for html printing, use WebBrowser.
At first, I want to print html string directly, by using WebBrowser.DocumentText.
It didn't work.
=>
WebBrowser webBrowserForPrinting = new WebBrowser();
WebBrowser.DocumentText = (my html strings. like "contents";)
WebBrowser.Print();
so I'm trying to write html string to text and create aaa.html
I made it Successfully, but then..
I tried to use
private void PrintHelpPage()
{
// Create a WebBrowser instance.
WebBrowser webBrowserForPrinting = new WebBrowser();
// Add an event handler that prints the document after it loads.
webBrowserForPrinting.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(PrintDocument);
// Set the Url property to load the document.
webBrowserForPrinting.Url = new Uri(@"\\myshare\help.html");
}
private void PrintDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
// Print the document now that it is fully loaded.
((WebBrowser)sender).Print();
// Dispose the WebBrowser now that the task is complete.
((WebBrowser)sender).Dispose();
}
I don't know how I get Uri(@"\myshare\help.html" );
my file's uri...
somebody helps... i searched and searched, but I can't find anything.
I tried to take it on my desktop and do for test
Uri(@"file:\\C:\Users\Mine\Desktop\aaa1.html" ); and it's not working...
I did one more try
using System.Net;
using System.IO;
using System.Drawing.Printing;
private Font printFont;
private StreamReader reader;
string url = "http://www.google.com";
WebResponse response = null;
private void pd_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;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
// Print each line of the file.
while (count < linesPerPage &&
((line = reader.ReadLine()) != null))
{
yPos = topMargin + (count *
printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
private void printButton_Click(object sender, EventArgs e)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
response = request.GetResponse();
reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);
pd.Print();
}
finally
{
reader.Close();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
and on paper it shows html all lines.
like this- < html > blah blah < / html >