View PDF in VFP Form
can be used to display contents of different type of files, including PDF.
Note 1 If PDF is displayed in the separate window outside of the Web Browser control, launch Adobe Acrobat/Reader and check 'Display PDF in Browser' under Internet in the Preferences. To fix the same problem for other file types (.DOC, .XLS, etc.) go to Folder Options -> File Types -> DOC-> Click Advanced button -> Choose Action: open and uncheck 'Confirm open after download' and check 'Browse in same window'.
Note 2 There are other ways to view a PDF:
- You can open PDF in the default PDF viewer using code from Opening URL in default Web Browser and putting PDF file name into lcUrl.
- Alternatively, you can use IE instead of Web Browser Control
1 2 3 4 5 loIE = Createobject("internetexplorer.application") loIE.Visible = .T. loIE.Navigate("file://" + lcPdfFileName) ...
Note 3 Optionally, PDF display can be adjusted by calling methods of PDF ActiveX control after PDF is loaded as shown in AdjustPdfView method posted separately after sample form. More info on PDF ActiveX control can be found in Interapplication Communication API Reference from Acrobat 8.1 SDK or Acrobat 9.0 SDK at http://www.adobe.com/devnet/acrobat.html?navID=downloads.
Note 4 The code below has been generated by Class Browser from a form. To create a form (.SCX) use following steps
- Create a form
- Add Property cPdfFileName to the form and assign empty string (=SPACE(0)) to it.
- Drop olecontrol on the form and pick Microsoft Web Browser.
- Change its name to oWB.
- Create method ShowPdf on the form and copy code from PROCEDURE ShowPdf there.
- Drop a command button on the form and copy code from command1.Click into its click method.
- In VFP8 and earlier put NODEFAULT into REFRESH event to prevent an error.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 PUBLIC oform1 oForm1=NEWOBJECT("form1") oForm1.Show() RETURN DEFINE CLASS form1 AS form Autocenter = .T. Height = 520 Width = 741 Caption = "Form1" Name = "Form1" * PDF file name cPdfFileName = "=SPACE(0)" * How long to wait for PDF to load nPdfLoadTimeout = 30 ADD OBJECT txtpdfname AS textbox WITH ; Top = 471, Left = 108, Height = 23, Width = 492, ; ReadOnly = .T., Name = "txtPdfName" ADD OBJECT command1 AS commandbutton WITH ; Top = 469, Left = 623, Height = 27, Width = 84, ; Caption = "View PDF", Name = "Command1" ADD OBJECT owb AS olecontrol WITH ; Top = 24, Left = 12, Height = 433, Width = 709, ; OleClass = "Shell.Explorer.2", Name = "oWB" ADD OBJECT label1 AS label WITH ; Height = 17, Left = 36, Top = 474, Width = 63, ; Caption = "PDF Name", Name = "Label1" PROCEDURE Refresh * Required in VFP8 and earlier to prevent an error NODEFAULT ENDPROC PROCEDURE ShowPdf LOCAL lnSeconds * Clear Web browser control by loading blank page Thisform.oWB.OBJECT.Navigate2("About:Blank") * Wait for load to complete lnSeconds = SECONDS() DO WHILE (Thisform.oWB.OBJECT.Busy OR Thisform.oWB.OBJECT.ReadyState <> 4) ; AND (SECONDS() - lnSeconds) < This.nPdfLoadTimeout DOEVENTS ENDDO * Load PDF WAIT WINDOW NOWAIT "Loading PDF ..." Thisform.oWB.OBJECT.Navigate2(Thisform.cPdfFileName) * Wait for PDF to load lnSeconds = SECONDS() DO WHILE (Thisform.oWB.OBJECT.Busy OR Thisform.oWB.OBJECT.ReadyState <> 4) ; AND (SECONDS() - lnSeconds) < This.nPdfLoadTimeout DOEVENTS ENDDO WAIT CLEAR * PDF display can be adjusted as shown in AdjustPdfView method * Uncomment next line if you want to do that and add AdjustPdfView method to the form/class *This.AdjustPdfView() ENDPROC PROCEDURE command1.Click * Get PDF file name Thisform.cPdfFileName = GETFILE("pdf") * Display the name in the textbox Thisform.txtPdfName.Value = Thisform.cPdfFileName IF NOT EMPTY(Thisform.cPdfFileName) * Display PDF Thisform.ShowPdf() ENDIF ENDPROC ENDDEFINE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 PROCEDURE AdjustPdfView * PDF control PEMs can only be accessed after it's loaded * TRY...ENDTRY will prevent crash in case when it's not loaded TRY loDoc = Thisform.oWB.oBJECT.Document WITH loDoc * PageMode: * none — does not display bookmarks or thumbnails (default) * bookmarks — displays the document and bookmarks * thumbs — displays the document and thumbnails .setPageMode("none") * LayoutMode: * DontCare — use the current user preference * SinglePage — use single page mode (as it would have appeared in pre-Acrobat 3.0 viewers) * OneColumn — use one-column continuous mode * TwoColumnLeft — use two-column continuous mode with the first page on the left * TwoColumnRight — use two-column continuous mode with the first page on the right .setLayoutMode("OneColumn") * ViewMode: * Fit — Fits the entire page within the window both vertically and horizontally. * FitH — Fits the entire width of the page within the window. .setView("FitH") * Zoom %, overrides ViewMode and vise verse. .setZoom(50) * Toolbar On/Off .setShowToolbar(.F.) * Scrollbars On/Off .setShowScrollbars(.T.) ENDWITH CATCH TO oErr FINALLY loDoc = null ENDTRY ENDPROC
Comments
Where is the location of the documentation ?
Interapplication Communication API Reference from Adobe
See <b><i>Note 3</i></b> above the code.
Sure 'nuf
Adobe Reader Methods
Where did you find you find the Methods to call. I am looking to select all text on a pdf and copy it to clipboard so that I can extact the text I need.
Thanks,
Bill
Nice bit of code
Thanks
John
Congratulations very intersting information
ole control owb
I am just wondering what else have to be pre-installed on the computer running this code above.
I mean: if it is an XP, Vista, 7 does it need Acrobat Reader to be installed in order to work?
If it is clean operating system, not having any Adobe stuff, do I need to copy, or register something, somewhere in order to work?
Thank you very much for your response!
Yes it requires Acrobat PDF
RE - html
My program will be used by users, so I just wanted to be sure that they will not have any problems at installation and running the .exe,
in fact I dont want any further ocx or dll registrations in Windows in order to work. (these registrations might be "complex" operations for them...)
THNX!
The Web Browser control is
OLE error code 0x80004005: unspecified error
thanks
Iam use Vfp 7
Re: OLE error code 0x80004005: unspecified error
I had tried with NOTE2 above,
Thanks so much sergey, I wait you response for solve this. thanks
It looks like you didn't put
I have also this error
PROCEDURE errhand PARAMETER
PARAMETER merror, mess, mess1, mprog, mlineno
IF merror = 1426 &&--OLE error code 0x"name".
*--Ignore and CONTINUE
ENDIF
PDF suddenly in separate Adobe window (not inside form)
Thanks!
Re: PDF suddenly in separate Adobe window (not inside form)
See <b>Note 1</b> in the article
Adobe Reader Methods
This is great, I am trying to select text from PDF and copy to clipboard for further processing. I am new to OLE Automation and having trouble finding Methods to call. I've tried note 3 and looked through the api documentation but did not see what I needed or even the navigate2 Method that you used. Any help with selecting all the text on pdf and copying to clipboard would be great.
Thanks,
Bill
Re: Copy to clipboard
You can use Acrobat Reader toolbar to select and copy text to clipboard.
How to print PDF file in VFP form
Re: How to print PDF file in VFP form
Display in browser checked programmatically
Very much needed stuff for me. Thank you
But, now, I need to make programmatically to make Display in Browser checked.
How can I do this?
I use both IE and FF
Sincerely,
This worked perfectly. I've
Doesnt Work
Windows7 64bit
Scanner ActiveX Control in VFP6
Many thanks for the helps you've rendered to many people. Am new into VFP6 programming. Can you give me a details explanation on how to use the Scanner activeX Control in VFP6? I suppose it is meant to be used to control a TWAIN scanner from within a VFP6 form. Please help.
Regards
Afunmai
html5 solution
thisform.txdat.Value = GETFILE("PDF","Open pdf","Open",1,"Open pdf")
View PDF in VFP Form
Not sure if you are receiving comments/questions?
Jeff
Very good code: View PDF in VFP Form
Work instantly with Adobe 11 + Windows 7.
Copy & Paste
Step 5, copy code from Procedure ShowPdf, is it copy the whole text starting: Public oforml?
I tried to paste it to oWB.init and got an error Methods and events cannot contain nested procedures or class definitions
Step 6, copy code from command1.Click, is it means copy the whole text starting: PROCEDURE AdjustPdfView...
Thanks for the help