Macros/ScriptForge/RedefinePDFExportOptions
Appearance
< Macros | ScriptForge
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
How to (re)define PDF export options
Authored by Jean-Pierre Ledure.
The current PDF export settings defined in the PDF Options dialogue, which can be accessed by choosing File - Export as - Export as PDF. Export options set with the PDF Options dialogue are kept until they are redefined with the dialogue or by code. In the example, all the options are displayed and afterwards one of them is modified.

How to run it in BASIC
Create a new document.
- Open the Basic IDE
- Select the first available blank module
- Copy and paste the Basic code
- Verify line 14
- Run Main()
How to run it in Python
Create a new document.
- Run APSO
- Create a new module, call it 'Module1'
- Copy and paste the Python code below
- Verify line 15
- Save and run the Main() method
Code
REM How to (re)define the PDF options
REM Minimal required version: LibreOffice 7.6
REM Used service(s) Dictionary, Session
Sub PdfOptions()
' Read the PDF options and modify one of them
Dim session As Object
Dim dict1 As Object, dict2 As Object
Dim key As String
Dim message As String
GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
Set session = CreateScriptService("Session")
' Read the actual PDF export options ?
Set dict1 = session.GetPDFExportOptions()
With dict1
' Display the actual options
message = ""
For Each key in .Keys
message = message & key & " = " & .Item(key) & ", "
Next key
.Dispose()
End With
MsgBox message
' Change one or more options
' We could have re-used the same dictionary, we choose to make a new one
Set dict2 = CreateScriptService("Dictionary", True) ' True = case sensitive
dict2.Add("ViewPDFAfterExport", True)
' Rewrite the PDF options
session.SetPDFExportOptions(dict2)
dict2.Dispose()
' Check by running Export As PDF on any open document, now or later
' In the General tab of the dialog, the View PDF after export checkbox is selected.
End Sub
# coding: utf-8
from __future__ import unicode_literals
from scriptforge import CreateScriptService
basic = CreateScriptService('Basic')
### How to (re)define the PDF options
### Minimal required version: LibreOffice 7.6
### Used service(s) Dictionary, Session
def pdfoptions():
# Read the PDF options and modify one of them
session = CreateScriptService('Session')
# Read the actual PDF export options
dict1 = session.GetPDFExportOptions()
# Display the actual options
message = ''
for key, item in dict1.items():
message = message + key + ' = ' + str(item) + ', '
basic.MsgBox(message)
# Change one or more options
# We could have re-used the same dictionary, we choose to make a new one
dict2 = CreateScriptService('Dictionary')
dict2['ViewPDFAfterExport'] = True
# Rewrite the PDF options
session.SetPDFExportOptions(dict2)
# Check by running Export As PDF on any open document, now or later
# In the General tab of the dialog, the View PDF after export checkbox is selected.
g_exportedScripts = (pdfoptions,)