The next release of OpenInsight (version 10.1) includes a couple of updates to the FILEPREVIEW control as a result of using it extensively “out in the field”, and in this post we thought we’d look at these changes and why we made them in case you encounter the same issues yourself.
The Adobe problem
As mentioned in this previous post, the FILEPREVIEW control relies on third-party DLLs to provide “preview handlers” that OpenInsight uses to display the contents of files such as Word or PDF documents. However, what we found is that not all of these handlers are created equal and some can be quite problematic – in our case the Adobe PDF preview handler (supplied with the Adobe PDF Reader) proved to be one of these.
When the handler is loaded by OpenInsight one of the things that must be specified is the context in which it is created – this can be “in-process” (which means it runs in the same address space as OpenInsight) or “out-of-process” (which runs as a separate executable). This is done internally by a set of flags, and when you use the FILENAME property these flags are set to their default values which, until recently, had proved sufficient. However, extensive testing (by Martyn at RevSoft) found that the Adobe PDF preview handler had stopped working, and further investigation revealed that at some point recent versions of this had become sensitive to these context flags, so the first change we made was to provide a new SETFILENAME method, which allows you to set the flags yourself if need be:
The SETFILENAME method
RetVal = Exec_Method( CtrlEntID, "SETFILENAME", FileName, FileExtn, | ContextFlags )
|FileName||No||Contains the name and path of the file to preview (can be null to remove the preview).|
|FileExtn||No||Specifies an explicit extension to use, overriding the extension passed in the FileName parameter.|
|ContextFlags||No||Specifies a bit-mask of “CLSCTX_” flags used to create the preview handler. Defaults to:|
BitOr( CLSCTX_INPROC_SERVER$, CLSCTX_LOCAL_SERVER$ )
(Equates for these flags can be found in the MSWIN_CLSCTX_EQUATES insert record)
If the returned value is 0 then the operation was successful, otherwise this is an error code reported from Windows and can be passed to the RTI_ErrorText stored procedure to get the details:
// Load the PDF in an out-of-process context $Insert MSWin_ClsCtx_Equates RetVal = Exec_Method( CtrlEntID, "SETFILENAME", "C:\Temp\Test.PDF", "", CLSCTX_LOCAL_SERVER$ ) If RetVal Then // Problem... ErrorText = RTI_ErrorText( "WIN", RetVal ) End
Even with this you may still find problems, as the above code was fine for me, but not for Martyn, even though the PDF preview handler worked fine in Windows Explorer itself for both of us! So, we could only conclude that Adobe made sure that the handler worked with the Windows Explorer, but they were less concerned about third party applications (Per-monitor DPI settings are also not supported by the preview handler which is disappointing as well).
The Foxit solution
After some more testing we decided to switch to the Foxit PDF reader which worked as expected, so we would recommend using this for PDF previewing in future if needed.
Removing the FILENAME property at design-time
One other change we made was to remove the FILENAME property from the Form Designer so that it could not be set at design-time due to the following reasons:
- We had reports that once it had been set it was very difficult to select the control again in the Form Designer, because it basically takes over mouse handling!
- Document previewing is deemed to more of a run-time operation than a design-time operation.
- The FILENAME property is deprecated in favor of the SETFILENAME method because the latter provides a more complete API. The FILENAME property is still supported however, and will be going forwards.
So, for v10.1 we have provided a new SETFILENAME method to provide a better interface for file-previewing which gives more feedback and more control, and you should use this in preference to the FILENAME property.
We have also found the Adobe PDF preview handler to be somewhat temperamental in use so would recommend the Foxit preview handler instead if you have problems with the former (Note however, that other preview handlers we use regularly, such as Word, Excel and PowerPoint have all worked well without any issues so far).