Embed PDFs and Document Links in LibreOffice Base

LibreOffice Base allows users to manage and access external documents, such as PDFs, directly from database forms. Instead of storing large binary files within the database itself—which causes file bloat and performance issues—the optimal method is to store local file paths or URLs in text fields. By leveraging standard form controls, the LibreOffice system integration service, or lightweight macros, you can create functional document links and trigger external PDF viewers directly from your Base user interface.

1. Prepare the Table to Store File Paths

Before configuring form controls, ensure your underlying database table has a dedicated field for storing the location of your external files.

  1. Open your database in LibreOffice Base and navigate to Tables.
  2. Edit your table in Design View.
  3. Add a field named DocumentPath (or similar).
  4. Set the Field Type to Text [VARCHAR] and assign a length sufficient for full file paths (e.g., 255 or 500 characters).
  5. Save and close the table design.

Paths should ideally be formatted as standard operating system file paths (e.g., C:\Documents\Invoice.pdf on Windows or /home/user/Documents/Invoice.pdf on Linux/macOS) or as file URLs (e.g., file:///C:/Documents/Invoice.pdf).

The most straightforward way to open an external PDF using the operating system’s default viewer is by adding a configured Push Button.

  1. Open your Form in Design Mode.
  2. Insert a Text Box linked to the DocumentPath field so the path for the current record is accessible.
  3. Select the Push Button tool from the Form Controls toolbar and draw a button on the form.
  4. Right-click the button and select Control Properties.
  5. In the General tab:
    • Set Label to Open PDF.
    • Scroll down to Action and change it to Open document/web page.
    • For static links, enter the direct file path into the URL property.

3. Dynamically Open PDFs Using a Macro

Because form records typically link to different files, a macro is required to dynamically read the active record’s file path and launch it.

Step A: Add the Macro

  1. Go to Tools > Macros > Organize Macros > Basic.
  2. Select your database file, click New, and paste the following script:
Sub OpenLinkedPDF(oEvent As Object)
    Dim oButton As Object
    Dim oForm As Object
    Dim sDocPath As String
    Dim oShell As Object

    oButton = oEvent.Source.Model
    oForm = oButton.Parent
    
    ' Retrieve the path from the DocumentPath column
    sDocPath = oForm.getString(oForm.findColumn("DocumentPath"))

    If sDocPath <> "" Then
        ' Convert system path to URL format if necessary
        sDocPath = ConvertToURL(sDocPath)
        
        ' Launch the file using the default system handler
        oShell = createUnoService("com.sun.star.system.SystemShellExecute")
        oShell.execute(sDocPath, "", 0)
    Else
        MsgBox "No file path specified for this record.", 48, "Missing Path"
    End If
End Sub

Step B: Bind the Macro to the Button

  1. Open the form in Design Mode.
  2. Right-click the Push Button and open Control Properties.
  3. Under the General tab, set Action to None.
  4. Switch to the Events tab.
  5. Click the browse (...) button next to Execute action, select Macro, locate OpenLinkedPDF, and click OK.
  6. Save the form and exit Design Mode. Clicking the button will now open the corresponding PDF for the active record.

4. Embedding In-Form PDF Previews

LibreOffice Base does not include a native interactive PDF rendering control. However, there are two practical approaches to visual previews within forms: