472,799 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

Printing HTML from memory (no user interaction)

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:

Expand|Select|Wrap|Line Numbers
  1. public static StringWriter MergeXSL_XML(string xml, string xsl)
  2. {
  3. try
  4. {
  5. XPathDocument xPath = new XPathDocument(xml);
  6. XslTransform xTrans = new XslTransform();
  7. xTrans.Load(xsl);
  8. StringWriter strW = new StringWriter();
  9. xTrans.Transform(xPath,null,strW);
  10. strW.Close();
  11. return strW;
  12. }
  13. catch(Exception e)
  14. {
  15. MessageBox.Show(e.ToString());
  16. return null;
  17. }
  18. }
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:
Expand|Select|Wrap|Line Numbers
  1. 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

Expand|Select|Wrap|Line Numbers
  1. wbCom.Navigate("about:blank");
  2. mshtml.IHTMLDocument2 hDoc = (mshtml.IHTMLDocument2)wbCom.Document;
  3. 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:

Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. MessageBox.Show(hDoc.ToString());
  2. printDialog1.Document = (PrintDocument)hDoc;
  3. printDialog1.Document = (PrintDocument)hDoc;
  4. 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:

Expand|Select|Wrap|Line Numbers
  1. for(int i=0; i < printDocument1.PrinterSettings.PaperSources.Count;
  2. i++)
  3. {
  4. MessageBox.Show(printDocument1.PrinterSettings.PaperSources[i].ToString());
  5. }
But I am not able to change them

Can someone help me with this problem?

Thanks in advance...

Jul 21 '05 #1
0 1198

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: prakash.guru | last post by:
Hi Friends . I try to do a javascript program which automatically fire an event or redirects to a page when there is no user interaction between user & browser for 15 minutes. Is it possible in...
by: Aaron Queenan | last post by:
I have a form which performs some asynchronous code. I want to display a wait cursor when it starts, and hide the wait cursor when it has completed. This part works fairly well, using: ...
by: EvanK | last post by:
Is there a way to display a message box and have it close after a certain amount of time w/o user interaction?
by: news.ntlworld.com | last post by:
How do I print HTML documents using vb.NET Cheers SteveJ
by: sheldonlg | last post by:
I don't think my last attempt posted so here it is again. This is a bit off-topic, but it does relate to php. This is the most active related group that I can find, so even if it is off-topic I...
by: Thinker | last post by:
Hi I am currently creating a web bot that simulates a user interaction with a webpage. The Bot's functionality would be similar to what an end user does on a data entry webpage Any...
by: ext237 | last post by:
hello. I'm trying to halt a function's execution while waiting for user interaction. For example, I have a function called getUserValue() that pops up a hidden div containing several buttons....
by: dwij2u | last post by:
Hi All, Can someone guide me on how we can modify the below script so that no user interaction is required to feed the password when the script is run, current scenario is like if I try to login...
by: nelsonbrodyk | last post by:
Hey All, I can't see to find a nice solution to this. I have a textbox, and a button. When the textbox text is set by the user, I want the button to enable. When the text is set through code (ie....
by: =?Utf-8?B?RmlsaXBwbw==?= | last post by:
The idea is to have a SERVICE that receives a request to print an HTML string (could be saved as file if needed). What is the recommended way to print an HTML string on the server, where there...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.