By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,868 Members | 1,765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,868 IT Pros & Developers. It's quick & easy.

Print pdf from Internet Explorer using VB .NET

P: n/a
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_PRINTPRE VIEW,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)

End If
Mar 8 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
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_PRINTPRE VIEW,
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
Mar 8 '06 #2

P: n/a
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_PRINTPRE VIEW,
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

Mar 9 '06 #3

P: n/a

"Wendy" <We***@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.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.

Mar 9 '06 #4

P: n/a
Your idea makes sense to me, but I don't know where to begin. Can you
suggest anything?

Thank you.

"Homer J Simpson" wrote:

"Wendy" <We***@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.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.

Mar 9 '06 #5

P: n/a

"Wendy" <We***@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.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.

Mar 9 '06 #6

P: n/a
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

"Wendy" <We***@discussions.microsoft.com> schreef in bericht
news:D7**********************************@microsof t.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_PRINTPRE VIEW,
> 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

Mar 9 '06 #7

P: n/a

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oq**************@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.

Mar 9 '06 #8

P: n/a
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
Mar 9 '06 #9

P: n/a
Homer J Simpson wrote:
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Oq**************@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
Mar 9 '06 #10

P: n/a

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
So please read first before you write.


You first.

Mar 10 '06 #11

P: n/a
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:
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_PRINTPRE VIEW,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER)

End If


Apr 7 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.