Print pdf from Internet Explorer using VB .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Wendy said:
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
 
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
 
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.
 
Your idea makes sense to me, but I don't know where to begin. Can you
suggest anything?

Thank you.
 
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.
 
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
 
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.
 
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
 
Homer said:
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
 
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 .
 
Back
Top