Home All Groups Group Topic Archive Search About
Author
21 Mar 2006 9:30 PM
vul
My current VB 6 application uses pdf.ocx control to display pdf files.
I have some problems with this control :
1. It's not presented in versions later than 5.0, or I cannot find it.
2. Sometimes it crashes the application
3. Sometimes it displays some messages.

I decided to replace it with WebBrowser control.
While WebBrowser displays the other types of files (Word, Jpg ) inside of
it, pdf files are displayed in a separate window.
I tried to check and uncheck "Display In Browser" setting in Preferences of
Acrobat Reader, but it doesn't change anything.

Is it possible to display Pdf file inside of WebBrowser control placed on
the VB Form? If yes, then how?

Thank you
Al

Author
23 Mar 2006 5:47 PM
Schmidt
"vul" <a**@optonline.net> schrieb im Newsbeitrag
news:OswAu6STGHA.736@TK2MSFTNGP12.phx.gbl...
> My current VB 6 application uses pdf.ocx control to display pdf files.
> I have some problems with this control :
> 1. It's not presented in versions later than 5.0, or I cannot find it.
> 2. Sometimes it crashes the application
> 3. Sometimes it displays some messages.

You could try it with this Code (remove old References to PDF.OCX from your
Projects first).
The crashes were gone, since we've loaded the PDFs
like shown (look at the LoadPDF-Procedure).

'***Into a Form
Option Explicit

Private PDFExt As VBControlExtender, PDF As Object
Private WithEvents Command1 As VB.CommandButton

Private Sub Command1_Click()
  LoadPDF "c:\test.pdf"
End Sub

Public Sub LoadPDF(FName$)
  PDF.LoadFile vbNullString: DoEvents 'necessary since Version 6
  PDF.LoadFile FName
End Sub

Private Sub Form_Load()
  On Error Resume Next
  Set Command1  Controls.Add("vb.commandbutton", "Command1")
  Command1.Visible  True: Command1.Caption  "Load c:\test.pdf"
  Set PDFExt  Controls.Add("AcroPDF.PDF.1", "PDF") 'version 7
  If PDFExt Is Nothing Then
    Set PDFExt  Controls.Add("PDF.PdfCtrl.6", "PDF")
    If PDFExt Is Nothing Then
      Set PDFExt  Controls.Add("PDF.PdfCtrl.5", "PDF")
      If PDFExt Is Nothing Then
        Set PDFExt  Controls.Add("PDF.PdfCtrl.1", "PDF")
        If PDFExt Is Nothing Then
          MsgBox "PDF-OCX not found!" & vbCrLf & _
            "Please install Acrobat Reader!"
          Unload Me: Exit Sub
        End If
      End If
    End If
  End If
  PDFExt.Visible  True
  Set PDF  PDFExt.object
  Err.Clear
End Sub

Private Sub Form_Resize()
  If Not PDFExt Is Nothing Then
   PDFExt.Move 0, Command1.Height, ScaleWidth, ScaleHeight - Command1.Height
  End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
  On Error Resume Next
  If Not PDF Is Nothing Then
    PDF.LoadFile vbNullString: DoEvents 'necessary since Version 6
    Set PDF  Nothing
    Set PDFExt  Nothing
    Controls.Remove "PDF"
  End If
  Err.Clear
End Sub

Olaf