Discussion:
Adobe PDF ActiveX in VB6
(too old to reply)
Darren
2006-11-28 16:54:18 UTC
Permalink
Has anyone tried to do this recently? (Yes, unfortunately there are
still many live systems written in VB6 ;) )

All the sample code I can find, dating from 2005 seems to be using the
wrong library:-

http://www.codenewsgroups.net/group/microsoft.public.vb.general.discussion/topic3577.aspx


Private mobjPDF As AcroPDFLibCtl.AcroPDF

Sub Form_Load()
Set mobjPDF = Controls.Add("AcroPDF.PDF.1", "Test")
mobjPDF.LoadFile DrawingName
End Sub

Private Sub Form_Unload(Cancel As Integer)
mobjPDF.LoadFile ""
End Sub

etc



'AcroPDFLibCtl' is invalid. V7 of the Browser Control actually has a
library of 'AcroPDFLib'

Even so, modifying the code to use the correct reference :-

Private mobjPDF As AcroPDFLib.AcroPDF

Sub Form_Load()
Set mobjPDF = Controls.Add("AcroPDF.PDF.1", "Test")
mobjPDF.LoadFile "sample.pdf"
End Sub

Private Sub Form_Unload(Cancel As Integer)
mobjPDF.LoadFile ""
End Sub


still brings back a 'Type Mismatch' error at the 'controls.add...'
line.


Thanks in advance.

D.
Schmidt
2006-11-28 17:52:24 UTC
Permalink
Post by Darren
Has anyone tried to do this recently? (Yes, unfortunately there are
still many live systems written in VB6 ;) )
What about this one?

***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
Darren
2006-11-29 08:55:38 UTC
Permalink
Brilliant !

Thanks Olaf, that works.

MikeD
2006-11-29 00:49:01 UTC
Permalink
Post by Darren
Has anyone tried to do this recently? (Yes, unfortunately there are
still many live systems written in VB6 ;) )
Most of us in THIS newsgroup wouldn't consider that to be unfortunate. What
we'd consider unfortunate was being forced to write the same application,
with all the same functionality, in VB.NET (or any .NET language for that
matter).
--
Mike
Microsoft MVP Visual Basic
Darren
2006-11-29 08:50:43 UTC
Permalink
I say unfortunate from a career perspective, ie missing out on all the
.net glory. I've developed systems in asp.net/vb.net, but far too much
still remains in vb, without a practicable business plan for being
rewritten.
Loading...