Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
GeneralRe: RichTextControl and Unicode problems with russian characters Pin
Judah Gabriel Himango3-May-05 8:10
sponsorJudah Gabriel Himango3-May-05 8:10 
GeneralRe: RichTextControl and Unicode problems with russian characters Pin
Uwe Keim3-May-05 8:44
sitebuilderUwe Keim3-May-05 8:44 
GeneralRe: RichTextControl and Unicode problems with russian characters Pin
mav.northwind3-May-05 23:41
mav.northwind3-May-05 23:41 
GeneralRe: RichTextControl and Unicode problems with russian characters Pin
Uwe Keim4-May-05 0:39
sitebuilderUwe Keim4-May-05 0:39 
QuestionProcedure line separator? Pin
Carl Mercier3-May-05 6:22
Carl Mercier3-May-05 6:22 
GeneralManaging controls added at runtime Pin
Anonymous3-May-05 5:07
Anonymous3-May-05 5:07 
GeneralRe: Managing controls added at runtime Pin
MoustafaS3-May-05 5:18
MoustafaS3-May-05 5:18 
GeneralPrinting HTML from memory no User interaction Pin
gjvh3-May-05 4:29
gjvh3-May-05 4:29 
Hello,


I hope you can help me with this issue. I am trying to build an application in C# that converts text from XML with an XSL to a HTML file and prints it according to some printersettings that can be made by an user interface. This application needs to run as an automatic process, so user intervention is not preferred.


I managed to get the XML+XSL->HTML conversion working with the following code:

public static StringWriter MergeXSL_XML(string xml, string xsl)<br />
		{<br />
			try<br />
			{<br />
				XPathDocument xPath = new XPathDocument(xml);<br />
				XslTransform xTrans = new XslTransform();<br />
				xTrans.Load(xsl);<br />
				StringWriter strW = new StringWriter();<br />
				xTrans.Transform(xPath,null,strW);<br />
				strW.Close();<br />
				return strW;<br />
			}<br />
			catch(Exception e)<br />
			{<br />
				MessageBox.Show(e.ToString());<br />
				return null;<br />
			}<br />
		}<br />



The XML and XSL are read from a file or database. This is working correct. The string writer contains the information I wanted as HTML. But now the bottleneck, I cannot print the HTML.

On some sites and newsgroups people run a command through the shell that executes the printer option. But this needs a temporary file on the server, but that’s not what I want. Some also use:

<br />
wbElement.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT);<br />

But that does not give any satisfying results.


I already managed to place the HTML in the Active X component

<br />
			wbCom.Navigate("about:blank");<br />
			mshtml.IHTMLDocument2 hDoc = (mshtml.IHTMLDocument2)wbCom.Document; <br />
			hDoc.write(html);<br />


The item shows the HMTL, but I cannot request the data later (when requesting wbCom.Document I won’t get my edited document), but that is not the real problem. The real problem is that I cannot parse the document to the printer. There is a print document method in the item:

<br />
			hDoc.execCommand("Print",false,0); <br />


But calling it shortly after the placement of the HTML in the document will cause a empty document to be print out. But by pressing a button to start the print will print out a document. I already tried to insert a small sleep, but how long the sleep does not matter, an empty document will be printed.

The thing that I want is that the document can be parsed to a printable document so I can print it with the default print components of C#/.NET. Casting does not work, I tried all the IHTMLDocument* classes to find something useful, but none of them seem to have a usable function to create a printable document for the printer components in .NET. One of the casts I tried:
<br />
			MessageBox.Show(hDoc.ToString());<br />
			printDialog1.Document = (PrintDocument)hDoc;<br />
			printDialog1.Document = (PrintDocument)hDoc;<br />
			hDoc.execCommand("Print",false,0);<br />


Another problem is that it seems I cannot change the printer settings, I need to change the default printer settings in windows. For example, I need to change the paper source, I can request the sources via:

<br />
for(int i=0; i < printDocument1.PrinterSettings.PaperSources.Count; i++)<br />
			{<br />
				MessageBox.Show(printDocument1.PrinterSettings.PaperSources[i].ToString());<br />
			}<br />


But I am not able to change them

Can someone help me with this problem?

Thanks in advance…
GeneralDouble buffering an entire form... Pin
MynaBay3-May-05 4:23
MynaBay3-May-05 4:23 
GeneralRe: Double buffering an entire form... Pin
Gil.Schmidt3-May-05 4:57
Gil.Schmidt3-May-05 4:57 
GeneralBeginner Problems Pin
dbuggerusa3-May-05 3:57
dbuggerusa3-May-05 3:57 
GeneralRe: Beginner Problems Pin
Dwayner793-May-05 4:34
Dwayner793-May-05 4:34 
GeneralHighlight listbox item on mouseover Pin
Dwayner793-May-05 3:55
Dwayner793-May-05 3:55 
GeneralRe: Highlight listbox item on mouseover Pin
keith maddox4-May-05 10:15
keith maddox4-May-05 10:15 
GeneralSummary question Pin
Pauwl3-May-05 2:54
Pauwl3-May-05 2:54 
GeneralRe: Summary question Pin
MoustafaS3-May-05 5:28
MoustafaS3-May-05 5:28 
GeneralRe: Summary question Pin
Pauwl3-May-05 20:22
Pauwl3-May-05 20:22 
GeneralRe: Summary question Pin
Pauwl4-May-05 2:44
Pauwl4-May-05 2:44 
Generalconvert VB.net into C# Pin
anj19833-May-05 2:48
anj19833-May-05 2:48 
GeneralRe: convert VB.net into C# Pin
MoustafaS3-May-05 5:38
MoustafaS3-May-05 5:38 
GeneralRe: convert VB.net into C# Pin
Dave Doknjas3-May-05 14:12
Dave Doknjas3-May-05 14:12 
GeneralTapi Pin
SujithNarayanannair3-May-05 2:41
SujithNarayanannair3-May-05 2:41 
GeneralCustom extention in C# Pin
Navees Ahmed3-May-05 1:57
Navees Ahmed3-May-05 1:57 
GeneralRe: Custom extention in C# Pin
Roger Stewart3-May-05 3:17
professionalRoger Stewart3-May-05 3:17 
GeneralHelp -- Tool Bar Control Pin
Umair Tariq3-May-05 1:05
Umair Tariq3-May-05 1:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.