Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 16th, 2008, 02:16 PM
Authorized User
Join Date: Apr 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Javascript print function

Does anyone know how to convert this code into javascript so I can print the document client-side?

        Dim WordObj As word.Application
        WordObj = CreateObject("Word.Application")
        Dim objWord As word.Document
        Dim FilePath As String = MapPath("TSPrintWeb.doc")
        objWord = WordObj.Documents.Open(FileName:=FilePath, ReadOnly:=True)
        WordObj.Visible = False

        With objWord.Bookmarks
            Select Case rdoEFF.SelectedItem.Value
                Case 3
                    .Item("EFF").Range.Text = txtEFF.Text

                Case 2
                    .Item("EFF").Range.Text = "Avio NG"

                Case 1
                    .Item("EFF").Range.Text = "Avidyne"

                Case 0
                    .Item("EFF").Range.Text = "All aircraft"
            End Select

            .Item("ATACHAP").Range.Text = txtChapter.Text
            .Item("ATASECT").Range.Text = txtSection.Text
            .Item("CAS").Range.Text = cboCAS.SelectedItem.Text
            .Item("FAULT").Range.Text = txtFAULT.Text
            .Item("CAUSE").Range.Text = txtCAUSE.Text
            .Item("STEP").Range.Text = txtSTEPS.Text
        End With

        objWord = Nothing

The code worked fine until the page it was in was deployed to the company network. It took awhile to figure out the code behind page (which is where this code originally was) is run at the server. So, I need it to run at the client for it to work.



Old September 17th, 2008, 05:40 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

You might be better off creating a document stream of the word doc on the server side, then sending the result to the browser. Typically a custom handler (ashx) would be the "page" that delivers this form of information.

You may also run into problems running office apps in a server environment. I'm not sure what the licensing rules about this are so you might want to check on that too.

Old September 27th, 2008, 12:56 PM
Authorized User
Join Date: Apr 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts

Problem solved. I abandoned the MS Word approach and just created a print web page with a dynamically created table. Doing that solved my original problem of how to automatically size fields to the respective text content (which was the reason I used Word in the first place). While it now requires an extra step at the client side to actually print the document the user now has the ability to choose which printer to use instead of only the default.

Thanks for the help, though.


Similar Threads
Thread Thread Starter Forum Replies Last Post
stop current javascript function using javascript sakthi Javascript 3 June 2nd, 2008 03:30 PM
javascript print in landscape vsr Javascript How-To 0 November 14th, 2007 05:23 PM
PRINT function kuku HTML Code Clinic 10 October 9th, 2006 07:02 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
How to use Print Hidden Function kiwibey Javascript 6 May 12th, 2005 11:38 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.