If you ever need to generate PDF reports, Excel files, or Word documents based on data from your APEX application (or from within your Oracle database) APEX Office Print (AOP) is the tool for you. If you’ve never used or heard of AOP before you should review it before continuing with this article.
This is the desired outcome of the article below. To summarize the solution will allow me to quickly edit a Word template using Office 365. Then view the generated PDF in APEX with a minimal amount of effort.

Background
AOP has two common uses cases (personal opinion). The first is providing users the ability to download their reports exactly as they’re shown in any format they’d like. For example if they build an Interactive Report (IR) with row highlighting etc and click “Download”, AOP will make the report look exactly as the user defined it. The second, which this article focuses on, is to create customizable documents based on data in Oracle. A good example of this is generating a invoice for a customer.
Problem
Using the later case, to generate a PDF invoice you need to create a Word or Excel file and use substitution string for AOP to replace data with. For example, to show the Invoice Number based on the column invoice_num
you would reference {invoice_num}
in your Word document. AOP with then “fill in” the substitution strings with your data. In this case the process is as follows:
- Define your query (with all the data)
- One time task unless more data is required
- Upload Word template file
- They’re various options as to where to store a file (more on this later)
- Generate the PDF
- This will involved downloading and then opening the PDF on your laptop
When initially building a template file the last two steps can happen many times. I.e. I want to see what the invoice would look like if I move some text over a bit. I’d need to re-upload the file then re-generate and download the PDF. This process has a few problems:
- It’s not good for multiple people working on the same template at the same time
- There’s lots of steps involved once making a change to the template to see the resulting PDF
Solution
To resolve the issues described above I created the following process to allow me to quickly build and view invoices using AOP and APEX. These steps require that you have an Office 365 account. (Note: if using a coporate Office 365 you’ll need the ability to share files with people outside of your organization. If you’re not allowed to use a personal account to host the template file)
Host Template on OneDrive
- Go to One Drive and upload a new Word document
- Note: For some reason when creating the Word document directly in One Drive AOP can’t process the file. To get around this create a Word document on your desktop and upload
- Note: the same steps can be used for any type of Office document (ex: Excel)
- Generate Share URL
- This will be a link to give others to work on modifying the Word template file
- We’ll refer to this URL as the “Share URL”
- Right click on the file and click
Share

- A new modal box pops up. Make sure to select the appropriate permissions (not critical that everyone can edit but does make it easy to share the link)
- Select
Copy link
and save this link somewhere- In my example the link is:
https://1drv.ms/w/s!AmD6WK_LJIvHq8xyy0JR-JT6ihJdPQ?e=xC88lZ
- In my example the link is:

- Generate Embed URL
- This will be used by your database to download the template file and send to AOP
- We’ll refer to this URL as the “Embed URL”
- Right click on the file and click
Embed

- A new slider pops up on the right hand side. Click
Generate

- Copy the
iframe
HTML tag and save this link- In my example the HTML is:
<iframe src="https://onedrive.live.com/embed?cid=C78B24CBAF58FA60&resid=C78B24CBAF58FA60%21714354&authkey=AKLKkXB0W5OfUZ4&em=2" width="476" height="288" frameborder="0" scrolling="no"></iframe>
- In my example the HTML is:

APEX Setup
Make sure that your APEX application has the latest AOP plugins installed.
Create a new page with a new region. Add the following text page items (Note: you can change to hidden later on / load from a table)
P3120_ONEDRIVE_EMBED_IFRAME
In the region add the following in the Source > Text
box:
<div id="pdf" data-aop-inline-pdf="onClick: Generate PDF" style="width:100%;height:600px;"></div>

Create a new region button called GENERATE_PDF
- Set the
Button Position
toEdit
- Right click on the button and
Create Dynamic Action
Name
:onClick: Generate PDF
- Note: Do Not this name must match the
data-aop-inline-pdf
from the previousdiv
tag
- Note: Do Not this name must match the
- Add the following actions:
Execute Server Side Code
- Items to Submit:
P3120_ONEDRIVE_EMBED_IFRAME
- PL/SQL Code:
- Items to Submit:
1 | declare |

- Plugin:
UC - APEX Office Print (AOP) - DA [Plug-In]
- Note: You’ll to have installed the AOP Plugins for this to show up in list
- Settings:
- Template Type:
SQL
- Template Source:
- Template Type:
1 | select |
- Data Type:
SQL
- Data Source:
1 | -- Change this to reference you tables etc |
- Output Type:
PDF
- Note you can change this to a different type of file later but for the preview in APEX, PDF is required
- Output To:
Inline Region (pdf/html/md/txt only)
- This is what will make the PDF show up in APEX

Using the iFrame URL, users should be able to see the preview in APEX based on changes made in Office 365 (see video at top of article)