Access – Display PDF inline in a Form

Access PDF In A Form

I was recently asked how one could display a PDF directly within an Access form, so I thought I’d shared how this can be done.

Limitations of Internet Explorer!

The first hurdle we have to get around is the fact that with the Web Browser control we are dealing with is in fact automating Internet Explorer (IE) and as such, it does not have native PDF capabilities like pretty much all modern web browsers (Yay Microsoft!).

So what is one to do?  The same thing we have always done, that is, install Adobe Reader.  Adobe Reader will then give us the ability to display PDF within IE and thus within our Web Browser control.

So, if you do not already have Adobe Reader installed, turn to ftp://ftp.adobe.com/pub/adobe/reader/ and get a copy of Adobe Reader for your PC.

Be Careful!
I tried installing the latest version from https://get.adobe.com/reader, Adobe Reader DC and it would simply never get recognized by IE.  I ended up installing the 2017 version with success.

Once you have it properly installed, we are then ready to implement it within Access itself, read on!

PDFs in an Access Form

So once again, the trick here, since Microsoft hasn’t given us the ability to display such file natively is to merely turn towards web functionalities that have enabled this for decades.

So we will create a form, embed a WebBrowser control that calls some simple HTML.  Below is an example html page that will display a PDF.

<!DOCTYPE html>
<!-- saved from url=(0016)http://localhost -->
<html>
   <head>
       <meta charset="UTF-8">
       <meta http-equiv="X-UA-Compatible" content="IE=edge" />
       <title>Inline Documents</title>
       <style>html, body, iframe { height: 100%; width: 100%; }</style>
   </head>
   <body>
       <object data="C:\Temp\PDFInWebBrowserControl\Documents\1.PDF#zoom=50&scrollbar=1&toolbar=0&navpanes=0" type="application/pdf" width="400" height="500">
           <p>It appears you don't have Adobe Reader or PDF support in this web browser. <a href="C:\Temp\PDFInWebBrowserControl\Documents\1.PDF">Click here to download the PDF</a>.</p>
           <embed src="C:\Temp\PDFInWebBrowserControl\Documents\1.PDF#zoom=50&scrollbar=1&toolbar=0&navpanes=0" type="application/pdf" width="400" height="500"/>
       </object>
   </body>
</html>

Now, normally I try to do all my web control HTML in memory to reduce I/O calls, but for some reason this does not work here. So we have to always deal with a dynamically created HTML page.

So, using the above as a starting point, we simply use “Open sFile For Output” approach to create an HTML page based on the current record and refresh the webbrowser.

Disclaimer/Notes:

If you do not have Microsoft Access, simply download and install the freely available runtime version (this permits running MS Access databases, but not modifying their design):

Microsoft Access 2010 Runtime
Microsoft Access 2013 Runtime
Microsoft Access 2016 Runtime
Microsoft 365 Access Runtime

All code samples, download samples, links, ... on this site are provided 'AS IS'.

In no event will Devhut.net or CARDA Consultants Inc. be liable to the client/end-user or any third party for any damages, including any lost profits, lost savings or other incidental, consequential or special damages arising out of the operation of or inability to operate the software which CARDA Consultants Inc. has provided, even if CARDA Consultants Inc. has been advised of the possibility of such damages.

Download a Demo Database

The download include an Access 2010 x32 accdb.

Feel free to download a 100% unlocked demo copy by using the link provided below:

Download “Access - PDF in Form (x32 accdb)” PDFInWebBrowserControl_V1.000.zip – Downloaded 10029 times – 1.12 MB

Version History

Version Date Changes
V1.000 2020-08-02 Initial Release

What about displaying other documents?

Although there are a couple ways to display other type of files: Word documents, Excel Workbooks, … these only work with online files and cannot work with local files!  I am still investigating if I can figure out any workarounds and will post back should I manage to do so.

4 responses on “Access – Display PDF inline in a Form

  1. Montaser

    The application is great, but I encountered a minor issue: if the file path contains Arabic characters, the PDF does not appear in the form.
    I checked the final HTML code, and it looked like this:

    Inline Documents
    html, body, object { height: 100%; width: 100%; }

    It appears you don’t have Adobe Reader or PDF support in this web browser. Click here to download the PDF.

    I noticed that the Arabic characters appeared normally and did not appear as strange symbols, so that cannot be the reason for the path not being recognized.

    So what is the reason for the path not being recognized, and can it be fixed?

    Best regards.