dataset to RTF format in browser and then javascript print

R

Richard

in a previous aspx page i got a few records printed throu window.print()
function in javascript.

but now i have the records in a to RTF and i want to run the same function
print, which ofcourse wont work
since the page isnt HTML anymore. Is there some other way to print
automaticly.

i used to have this function to print automaticly from a browser to client.
------------------

<BODY onload="doPrint()">
<object id="WBControl" width="0" height="0"
classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>

<script language="VBScript"><!--
Sub VBPrint() On Error Resume Next
WBControl.ExecWB 6,1
End Sub
//--></script>

<script language=JavaScript><!--
function doPrint()
{
if(self.print)
{
self.print();
self.close();
return false;

}
else if (navigator.appName.indexOf('Microsoft') != -1)
{
VBPrint();
self.close();
}
else
{
alert("To print this document, you will need to\nclick the Right Mouse
Button and select\n'Print'");
}
}
//-->
</script>

--------------
which made sure the page is printed without having a user asked for a
confirmation but i want the same this but for an RTF document.
my code is:
-------------------
Dim myConnection As OleDBConnection = New
OleDBConnection(AppSettings("DigifanDatabaseCon"))
myConnection.Open()

Dim ds As DataSet
Dim sXSL As String

ds = New DataSet("klantenkaart")
Dim ContactsDA As OleDBDataAdapter = New OleDBDataAdapter("SELECT *
FROM Klantenbestand WHERE klantnummer="& Request.QueryString("ID") & "",
myConnection)
ContactsDA.Fill(ds, "Klantenbestand")
' XSLT to use for transforming this dataset.
sXSL = "klantenkaart.xslt"

' Close the connection to the data source.
myConnection.Close()
' Transform the dataset by using the appropriate stylesheet.
Dim xmlDoc As XmlDataDocument = New XmlDataDocument(ds)
Dim xslTran As XslTransform = New XslTransform
xslTran.Load(Server.MapPath(sXSL))

' Stream the results of the transformation to Word.
Response.ContentType = "application/msword"
Response.Charset = ""
Response.ContentEncoding = System.Text.Encoding.Default
xslTran.Transform(xmlDoc, Nothing, Response.Output)

-------------------
and i want to print it then but how. I am kinda stuck.
i hope it makes sence to the person reading it and thx in advance if you can
help me out.

Richard
 
S

Steven Cheng[MSFT]

Hi Richard,

From your description, you output a Word Document to the client user in a
certain web page's response stream. And you found you're unable to use
window.print() script code to print the page now, yes?

As for this problem, it is because when you render out a page as a word
document, the contenttype is changed to "application/msword" rather than
the standard "text/html" , so there is no html also script code in the
response content. And we can't call the script code to print the page from
itself. However, I think we can use another means to workaround this, we
can define a container page which contains a <iframe > element (set width
and height to 100%) , and set the iframe's src attribute to the page which
return the Word document. Then, we can use script code in the container
page to print the iframe page(which is host the word document). For
example, in the container page we define the following iframe:

<iframe id="innerFrame" src="worddoc.aspx"/>

Then, we can provide the following script function:
function printInnerDoc()
{
window.frames[0].print();
}

And use it in the container page's onload event, such as
<body onload="printInnerDoc()">

Please have a try and if you have any other ideas, please also feel free
to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
R

Richard

Holy crap, that actually worked, thx Steven you rock. This helps me solve a
lot of printing issue's! thx a lot :D

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top