Home All Groups Group Topic Archive Search About

Print pdf from Internet Explorer using VB .NET

Author
8 Mar 2006 11:19 PM
Wendy
Hello,

I have a program that does the following:
When a user clicks on a row in a VB.NET datagrid, it will open a web page in
Internet Explorer (that corresponds to that item in the selected row in the
datagrid).  It will automatically print that web page, and then it will close
the Internet Explorer window.  I have code that works perfectly when a
regular web page is opened, however when a pdf web page is opened the
printing never occurs.  Any help would be greatly appreciated.  The reason
for the datagrid is that ultimately the user should be able to select many
rows and have all the web pages print without any user intervention.  Thank
you!  Mrs_Mcse

My VB.NET code is:

If DataGrid1.IsSelected(0) = True Then

            Dim selectedItem As Object
            selectedItem = DataGrid1.Item(0, 4)
            'For testing purposes, just use the first row in the datagrid
and use column 4 that contains a web url
            Dim cellValue As String
            cellValue = selectedItem

            Dim Explorer As SHDocVw.InternetExplorer
            Explorer = New SHDocVw.InternetExplorer
            Explorer.Visible = True
            Explorer.Navigate(cellValue)
            Do

            Loop Until Explorer.Busy = False

            Explorer.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)

        End If

Author
8 Mar 2006 11:37 PM
Chris
Wendy wrote:
Show quoteHide quote
> Hello,
>
> I have a program that does the following:
> When a user clicks on a row in a VB.NET datagrid, it will open a web page in
> Internet Explorer (that corresponds to that item in the selected row in the
> datagrid).  It will automatically print that web page, and then it will close
> the Internet Explorer window.  I have code that works perfectly when a
> regular web page is opened, however when a pdf web page is opened the
> printing never occurs.  Any help would be greatly appreciated.  The reason
> for the datagrid is that ultimately the user should be able to select many
> rows and have all the web pages print without any user intervention.  Thank
> you!  Mrs_Mcse

> My VB.NET code is:
>
> If DataGrid1.IsSelected(0) = True Then
>
>             Dim selectedItem As Object
>             selectedItem = DataGrid1.Item(0, 4)
>             'For testing purposes, just use the first row in the datagrid
> and use column 4 that contains a web url
>             Dim cellValue As String
>             cellValue = selectedItem
>
>             Dim Explorer As SHDocVw.InternetExplorer
>             Explorer = New SHDocVw.InternetExplorer
>             Explorer.Visible = True
>             Explorer.Navigate(cellValue)
>             Do
>
>             Loop Until Explorer.Busy = False
>
>             Explorer.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW,
> SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)
>
>         End If

Why not host the page inside vb.net instead of launching IE?  Then you
can print it yourself.

Chris
Author
8 Mar 2006 11:59 PM
Wendy
Hi Chris,

Sorry, but this is the only way that I know.  Would you please tell me, at
least in general terms, how to accomplish what you suggest?

Thank you so much,

Wendy

Show quoteHide quote
"Chris" wrote:

> Wendy wrote:
> > Hello,
> >
> > I have a program that does the following:
> > When a user clicks on a row in a VB.NET datagrid, it will open a web page in
> > Internet Explorer (that corresponds to that item in the selected row in the
> > datagrid).  It will automatically print that web page, and then it will close
> > the Internet Explorer window.  I have code that works perfectly when a
> > regular web page is opened, however when a pdf web page is opened the
> > printing never occurs.  Any help would be greatly appreciated.  The reason
> > for the datagrid is that ultimately the user should be able to select many
> > rows and have all the web pages print without any user intervention.  Thank
> > you!  Mrs_Mcse
> > 
> > My VB.NET code is:
> >
> > If DataGrid1.IsSelected(0) = True Then
> >
> >             Dim selectedItem As Object
> >             selectedItem = DataGrid1.Item(0, 4)
> >             'For testing purposes, just use the first row in the datagrid
> > and use column 4 that contains a web url
> >             Dim cellValue As String
> >             cellValue = selectedItem
> >
> >             Dim Explorer As SHDocVw.InternetExplorer
> >             Explorer = New SHDocVw.InternetExplorer
> >             Explorer.Visible = True
> >             Explorer.Navigate(cellValue)
> >             Do
> >
> >             Loop Until Explorer.Busy = False
> >
> >             Explorer.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW,
> > SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)
> >
> >         End If
>
> Why not host the page inside vb.net instead of launching IE?  Then you
> can print it yourself.
>
> Chris
>
Author
9 Mar 2006 6:15 AM
Cor Ligthert [MVP]
Hi Wendy,

A little example,

Open a new windows application project

In the toolbox rightclick and select add/Remove items

In the customize toolbox select Com and in that Microsoft Webbrowser (This
with 1.1 in 2.0 it is already in the toolbox)

When that is in the toolbox drag it to your form
Drag also a button to your form.

Then this code and you have a mini Webbrowser.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.AxWebBrowser1.Navigate2("www.google.com")
End Sub

Don't instance in 1.1 the webbrowser in code there is a lot placed in the
RESX file with that method.

I hope this helps a little bit?

Cor

Show quoteHide quote
"Wendy" <We***@discussions.microsoft.com> schreef in bericht
news:D7B4D07C-6587-4100-ACFC-14CE891BB4E9@microsoft.com...
> Hi Chris,
>
> Sorry, but this is the only way that I know.  Would you please tell me, at
> least in general terms, how to accomplish what you suggest?
>
> Thank you so much,
>
> Wendy
>
> "Chris" wrote:
>
>> Wendy wrote:
>> > Hello,
>> >
>> > I have a program that does the following:
>> > When a user clicks on a row in a VB.NET datagrid, it will open a web
>> > page in
>> > Internet Explorer (that corresponds to that item in the selected row in
>> > the
>> > datagrid).  It will automatically print that web page, and then it will
>> > close
>> > the Internet Explorer window.  I have code that works perfectly when a
>> > regular web page is opened, however when a pdf web page is opened the
>> > printing never occurs.  Any help would be greatly appreciated.  The
>> > reason
>> > for the datagrid is that ultimately the user should be able to select
>> > many
>> > rows and have all the web pages print without any user intervention.
>> > Thank
>> > you!  Mrs_Mcse
>> >
>> > My VB.NET code is:
>> >
>> > If DataGrid1.IsSelected(0) = True Then
>> >
>> >             Dim selectedItem As Object
>> >             selectedItem = DataGrid1.Item(0, 4)
>> >             'For testing purposes, just use the first row in the
>> > datagrid
>> > and use column 4 that contains a web url
>> >             Dim cellValue As String
>> >             cellValue = selectedItem
>> >
>> >             Dim Explorer As SHDocVw.InternetExplorer
>> >             Explorer = New SHDocVw.InternetExplorer
>> >             Explorer.Visible = True
>> >             Explorer.Navigate(cellValue)
>> >             Do
>> >
>> >             Loop Until Explorer.Busy = False
>> >
>> >             Explorer.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW,
>> > SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)
>> >
>> >         End If
>>
>> Why not host the page inside vb.net instead of launching IE?  Then you
>> can print it yourself.
>>
>> Chris
>>
Author
9 Mar 2006 6:43 AM
Homer J Simpson
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:OqrmsC0QGHA.4696@tk2msftngp13.phx.gbl...

> When that is in the toolbox drag it to your form
> Drag also a button to your form.
>
> Then this code and you have a mini Webbrowser.

But that still won't activate the pdf viewer inside IE and make it print.
That's the tricky part.
Author
9 Mar 2006 6:55 AM
Cor Ligthert [MVP]
Homer,

> But that still won't activate the pdf viewer inside IE and make it print.
> That's the tricky part.
>
But that was not the question from Wendy I was answered.

In here reply to Chris she asked how to create an inbuild webbrowswer.

So please read first before you write.

Cor
Author
10 Mar 2006 2:23 AM
Homer J Simpson
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%234tMKZ0QGHA.3192@TK2MSFTNGP09.phx.gbl...

> So please read first before you write.

You first.
Author
9 Mar 2006 6:27 PM
Chris
Homer J Simpson wrote:
Show quoteHide quote
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:OqrmsC0QGHA.4696@tk2msftngp13.phx.gbl...
>
>
>>When that is in the toolbox drag it to your form
>>Drag also a button to your form.
>>
>>Then this code and you have a mini Webbrowser.
>
>
> But that still won't activate the pdf viewer inside IE and make it print.
> That's the tricky part.
>
>
>

The system should detect that a PDF has been asked for and handle that
seperate from a web page.

Chris
Author
9 Mar 2006 1:15 AM
Homer J Simpson
"Wendy" <We***@discussions.microsoft.com> wrote in message
news:4594A7D5-B129-4F18-B5CE-47156569E0AD@microsoft.com...

> I have code that works perfectly when a
> regular web page is opened, however when a pdf web page is opened the
> printing never occurs.

Isn't that because you need to use the pdf printing function and not the IE
printing function? Perhaps you need to find a way to send that message to
the pdf display addon.
Author
9 Mar 2006 2:21 AM
Wendy
Your idea makes sense to me, but I don't know where to begin.  Can you
suggest anything?

Thank you.

Show quoteHide quote
"Homer J Simpson" wrote:

>
> "Wendy" <We***@discussions.microsoft.com> wrote in message
> news:4594A7D5-B129-4F18-B5CE-47156569E0AD@microsoft.com...
>
> > I have code that works perfectly when a
> > regular web page is opened, however when a pdf web page is opened the
> > printing never occurs.
>
> Isn't that because you need to use the pdf printing function and not the IE
> printing function? Perhaps you need to find a way to send that message to
> the pdf display addon.
>
>
>
>
Author
9 Mar 2006 4:56 AM
Homer J Simpson
"Wendy" <We***@discussions.microsoft.com> wrote in message
news:9A0B3CE9-2DEE-4AD6-87E5-0DA4CC9A4EB3@microsoft.com...

> Your idea makes sense to me, but I don't know where to begin.  Can you
> suggest anything?

I would explore to see if you can find a way to link to the Adobe software.
Try add a reference, COM, and look for Adobe stuff.

You could also use

SendKeys.Send("^P")

from your program but it's not always reliable and you may need to figure
out how to activate the webrowser app first.
Author
7 Apr 2006 12:37 PM
nirav
hi
actually i want to know that can i open the same vb.net application
means windows application in the internet explorer?
if yes then say me how ?
i have urgent need for this answer .

Wendy wrote:
Show quoteHide quote
> Hello,
>
> I have a program that does the following:
> When a user clicks on a row in a VB.NET datagrid, it will open a web page in
> Internet Explorer (that corresponds to that item in the selected row in the
> datagrid).  It will automatically print that web page, and then it will close
> the Internet Explorer window.  I have code that works perfectly when a
> regular web page is opened, however when a pdf web page is opened the
> printing never occurs.  Any help would be greatly appreciated.  The reason
> for the datagrid is that ultimately the user should be able to select many
> rows and have all the web pages print without any user intervention.  Thank
> you!  Mrs_Mcse
>
> My VB.NET code is:
>
> If DataGrid1.IsSelected(0) = True Then
>
>             Dim selectedItem As Object
>             selectedItem = DataGrid1.Item(0, 4)
>             'For testing purposes, just use the first row in the datagrid
> and use column 4 that contains a web url
>             Dim cellValue As String
>             cellValue = selectedItem
>
>             Dim Explorer As SHDocVw.InternetExplorer
>             Explorer = New SHDocVw.InternetExplorer
>             Explorer.Visible = True
>             Explorer.Navigate(cellValue)
>             Do
>
>             Loop Until Explorer.Busy = False
>
>             Explorer.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW,
> SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)
>
>         End If