CirrusIT
asked on
How to open a .pdf document in Visual Basic
How do you open a .PDF document within Visual Basic?
I am using Adobe Acrobat Reader 7.0.8 and Visual Basic 6 - needs to be able to run on .NET as well.
I cant find this PDF.OCX file not that would do much good as according to other knowledgebase items this has to be dragged onto the form, I need an alternative solution to be able to open a .PDF document.
Please help...
Cheers.
JC.
I am using Adobe Acrobat Reader 7.0.8 and Visual Basic 6 - needs to be able to run on .NET as well.
I cant find this PDF.OCX file not that would do much good as according to other knowledgebase items this has to be dragged onto the form, I need an alternative solution to be able to open a .PDF document.
Please help...
Cheers.
JC.
Open it in a browser control.
Its a COM control down as 'Microsoft Internet Controls' or Interop.SHDocVw.dll
Greetings, CirrusIT.
If by "open a .PDF document within Visual Basic" means to have the item open in a VB form, then Kinger247 has already given you the answer. If instead you meant that you need a way to open a PDF document from within VB, but not in a VB form, then another option would be to use the Shell command and let Windows open the PDF in Acrobat Reader.
Cheers!
If by "open a .PDF document within Visual Basic" means to have the item open in a VB form, then Kinger247 has already given you the answer. If instead you meant that you need a way to open a PDF document from within VB, but not in a VB form, then another option would be to use the Shell command and let Windows open the PDF in Acrobat Reader.
Cheers!
sorry CirrusIT, thought you where using .net,
the answer I gave is till the same just not the Interop.bit ;)
the answer I gave is till the same just not the Interop.bit ;)
http://www.nero.com
Make Bootable CD (easyest way)
http://partners.adobe.com/public/developer/acrobat/sdk/index.html;jsessionid=AD81669D7C47F56EB1F90416B99DE97D#fs
Download the help file. ftp://ftp6.nero.com/tutorials/nero7prem/data/Nero7_Data_chm_tut_eng.zip
Make Bootable CD (easyest way)
http://partners.adobe.com/public/developer/acrobat/sdk/index.html;jsessionid=AD81669D7C47F56EB1F90416B99DE97D#fs
Download the help file. ftp://ftp6.nero.com/tutorials/nero7prem/data/Nero7_Data_chm_tut_eng.zip
Sorry for my post above i writed in the wrong post.
Good advice anyway :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Crikey, thanks for all the responses, even though some are a little off topic : )
I dont want to open the document in Visual Basic (i.e. in a form) i wish to open to the document in Adobe Acrobat reader but when i try the Shell ("Directory") command it errors saying invalid call or arguement.
Ill give jkaios code a try but the directory and file name is built up of Variables - 3 in total
DIRECTORY - contains the location
DATE - the date of the file
NUMBER - unique id
DATE and NUMBER make up the file name, so how do i write this command line so that is uses the variables?
oShell.Execute("C:\Temp\my File.PDF", me.hWnd)
Come to think of it i will have to do some TRIMM 'ing functions on the variables to make sure there are no unneccesary spaces....
Many thanks
JC.
I dont want to open the document in Visual Basic (i.e. in a form) i wish to open to the document in Adobe Acrobat reader but when i try the Shell ("Directory") command it errors saying invalid call or arguement.
Ill give jkaios code a try but the directory and file name is built up of Variables - 3 in total
DIRECTORY - contains the location
DATE - the date of the file
NUMBER - unique id
DATE and NUMBER make up the file name, so how do i write this command line so that is uses the variables?
oShell.Execute("C:\Temp\my
Come to think of it i will have to do some TRIMM 'ing functions on the variables to make sure there are no unneccesary spaces....
Many thanks
JC.
CirrusIT, I don't think anyone has been off topic ...
>>I dont want to open the document in Visual Basic (i.e. in a form) i wish to open to the document in Adobe Acrobat reader but when i try the Shell ("Directory") command it errors saying invalid call or arguement.
your original post was >How do you open a .PDF document within Visual Basic?
>>I dont want to open the document in Visual Basic (i.e. in a form) i wish to open to the document in Adobe Acrobat reader but when i try the Shell ("Directory") command it errors saying invalid call or arguement.
your original post was >How do you open a .PDF document within Visual Basic?
ASKER
Um......i was referring to NERO burning CD comment....
perhaps should have been clearer in making that joke....
perhaps should have been clearer in making that joke....
ah, I see .. , my apologises too :)
If your having problems with your file name, can you give an example it ?
Like : C:\Temp\20061122 12345.PDF
If your having problems with your file name, can you give an example it ?
Like : C:\Temp\20061122 12345.PDF
ASKER
No worries matey, at the moment my Shell command looks like this:
Shell("C:\Temp\List Building.pdf")
This was just to prove to myself that you can open a PDF document in Visual Basc, just to basically load a .PDF document at the moment when the code hits a certain point.
-Background-
I have a form which the user can press SHIFT + F8 (keypressed function) to which will bring up a validation message and ask if they wish to load the scanned document selected.
Once the IF statements check that no fields are missing / blank otherwise there's no point - if they are not blank it will then connect to a SQL database to retrieve the values to build the DIRECTORY, NUMBER & DATE values, then I wish to build the load .PDF line after the values have been retrieved - :
The naming convention of the file is : DDMMYYYYnnnnnnn
nnnnnnn being the unique id variable.
So DIRECTORY will = "C:\Temp\"
DATE will = "12/12/2006" - Although the alarm bells of doom are ringing in my head with this one cus of the \ \ charactors, not quite sure whether its possible to get rid of them.
NUMBER will = "1234567"
Then have to add ".PDF" to the end of the statement i presume.
JKAIOS solution looks very thorough- problem being that I cant build another form with command button - i need to load the document in the MODULE code once i have performed the validation mentioned above (checking for blanks and such) can this be done?
Many thanks for your help
JC.
Shell("C:\Temp\List Building.pdf")
This was just to prove to myself that you can open a PDF document in Visual Basc, just to basically load a .PDF document at the moment when the code hits a certain point.
-Background-
I have a form which the user can press SHIFT + F8 (keypressed function) to which will bring up a validation message and ask if they wish to load the scanned document selected.
Once the IF statements check that no fields are missing / blank otherwise there's no point - if they are not blank it will then connect to a SQL database to retrieve the values to build the DIRECTORY, NUMBER & DATE values, then I wish to build the load .PDF line after the values have been retrieved - :
The naming convention of the file is : DDMMYYYYnnnnnnn
nnnnnnn being the unique id variable.
So DIRECTORY will = "C:\Temp\"
DATE will = "12/12/2006" - Although the alarm bells of doom are ringing in my head with this one cus of the \ \ charactors, not quite sure whether its possible to get rid of them.
NUMBER will = "1234567"
Then have to add ".PDF" to the end of the statement i presume.
JKAIOS solution looks very thorough- problem being that I cant build another form with command button - i need to load the document in the MODULE code once i have performed the validation mentioned above (checking for blanks and such) can this be done?
Many thanks for your help
JC.
ASKER
After a bit of tinkering this is how I action without a command click:
Dim LoadDoc
LoadDoc = ("C:\Temp\MyFile.PDF")
oShell.Execute (LoadDoc)
MsgBox oShell.ErrorMsg
Just now need to figure out the syntax for using variables in the string, and how to remove the '/'s from a date field.......
Dim LoadDoc
LoadDoc = ("C:\Temp\MyFile.PDF")
oShell.Execute (LoadDoc)
MsgBox oShell.ErrorMsg
Just now need to figure out the syntax for using variables in the string, and how to remove the '/'s from a date field.......
ASKER
For the people looking to remove the '/' from dates this how to do it:
Dim SDay, SMonth, SYear, FileDate 'Document properties
SDay = Day(YourDate)
SMonth = Month(YourDate)
SYear = Year(YourDate)
FileDate = (SDay & SMonth & SYear)
Will add the syntax for using variables in a string to this thread when ive figured it out for other peoples reference.
However the original query was solved by the marvellous post by JKAIOS - your a legend, much obliged.
Cheers,
JC
Dim SDay, SMonth, SYear, FileDate 'Document properties
SDay = Day(YourDate)
SMonth = Month(YourDate)
SYear = Year(YourDate)
FileDate = (SDay & SMonth & SYear)
Will add the syntax for using variables in a string to this thread when ive figured it out for other peoples reference.
However the original query was solved by the marvellous post by JKAIOS - your a legend, much obliged.
Cheers,
JC
ASKER
The missing piece of the puzzle, this is how you declare variables and use them in a string:
VarNumber = Trim(VarNumber)
LoadDoc = (Directory & FileDate & VarNumber & ".PDF")
oShell.Execute (LoadDoc)
VarNumber = Trim(VarNumber)
LoadDoc = (Directory & FileDate & VarNumber & ".PDF")
oShell.Execute (LoadDoc)