How do I export a spreadsheet to pdf and perform the ‘View pdf after export’ action using macro in python?
I am using the code below but the ViewPDFAfterExport filter is not working. Tested on linux and windows.
I need to perform the same action as the command indicated in the image
Could it be that in python it is not the same filter name as in basic?
See in the example the ‘Watermark’ filter works normally.
import uno
from pathlib import Path
from com.sun.star.beans import PropertyValue
from com.sun.star.io import IOException
def dict_to_property(values: dict, uno_any: bool=False):
ps = tuple([PropertyValue(Name=n, Value=v) for n, v in values.items()])
if uno_any:
ps = uno.Any('[]com.sun.star.beans.PropertyValue', ps)
return ps
def export_pdf_args():
doc = XSCRIPTCONTEXT.getDocument()
dict_filter_options = {
'ViewPDFAfterExport' : True,
'Watermark' : 'test',
}
filter_data = dict_to_property(dict_filter_options, True)
dict_media_descriptor = {
'FilterName': 'calc_pdf_Export',
'FilterData': filter_data,
}
sys_output_pdf = Path(Path.home(), f'''{doc.Title}.pdf''')
lo_output_pdf = uno.systemPathToFileUrl(str(sys_output_pdf))
args = dict_to_property(dict_media_descriptor)
try:
doc.storeToURL(lo_output_pdf, args)
except IOException as e:
print(f'''Location is unknown\n\n{e}''')
The above code exports the pdf, but does not display the pdf automatically