HighTechTalks DotNet Forums  

Printing HTML from memory (no user interaction)

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss Printing HTML from memory (no user interaction) in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Gertjan
 
Posts: n/a

Default Printing HTML from memory (no user interaction) - 05-03-2005 , 11:01 AM






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; } }

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);
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);

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);

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);

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()); }

But I am not able to change them

Can someone help me with this problem?

Thanks in advance...


Reply With Quote
  #2  
Old   
Richard
 
Posts: n/a

Default Re: Printing HTML from memory (no user interaction) - 06-07-2005 , 10:57 AM







I am trying to do something very similar - an automated proces
(unattended) that prints XML/XSLT documents to a file. So far I hav
not been able to find a solution. Did you manage to resolve you
problem - if so - how

--
Richar



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.