473,388 Members | 1,215 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Printing HTML from memory (no user interaction)

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:

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. }
  19.  
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);
  2.  
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);
  4.  
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);
  2.  
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);
  5.  
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. }
  6.  
But I am not able to change them

Can someone help me with this problem?

Thanks in advance...

Jul 21 '05 #1
0 1215

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

Similar topics

2
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...
3
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: ...
4
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?
2
by: news.ntlworld.com | last post by:
How do I print HTML documents using vb.NET Cheers SteveJ
3
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...
2
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...
2
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....
1
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...
3
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....
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.