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: [code] public static StringWriter MergeXSL_XML(string xml, string xsl) { try { XPathDocument xPath = new XPathDocument(xml); XslTransform xTrans = new XslTransform(); xTrans.Load(xsl); StringWriter strW = new StringWriter(); xTrans.Transform(xPath,null,strW); strW.Close(); return strW; } catch(Exception e) { MessageBox.Show(e.ToString()); return null; } } [/code] 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: [code] wbElement.QueryStatusWB(SHDocVw.OLECMDID.OLECMDID_PRINT); [/code] But that does not give any satisfying results. I already managed to place the HTML in the Active X component [code] wbCom.Navigate("about:blank"); mshtml.IHTMLDocument2 hDoc = (mshtml.IHTMLDocument2)wbCom.Document; hDoc.write(html); [/code] 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: [code] hDoc.execCommand("Print",false,0); [/code] 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: [code] MessageBox.Show(hDoc.ToString()); printDialog1.Document = (PrintDocument)hDoc; printDialog1.Document = (PrintDocument)hDoc; hDoc.execCommand("Print",false,0); [/code] 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: [code] for(int i=0; i < printDocument1.PrinterSettings.PaperSources.Count; i++) { MessageBox.Show(printDocument1.PrinterSettings.PaperSources[i].ToString()); } [/code] But I am not able to change them Can someone help me with this problem? Thanks in advance...
Don't see what you're looking for? Try a search.
|