Enable PDF Export for Modules
Objective
- To customize a PDF export for selected status reports
Note
- Here, only the general functionality is installed. Optimizations are to be carried upon requirement, e.g.:
- Editing messages
- Variable input of export path, file name, module variant, etc., e.g. in the Global Settings module.
- Handling of the PDF file (e.g. the behavior when the file has already been opened or the possibility to specify another name)
Procedure
- Create a new module that displays the status reports to be printed with a Create PDF button (=selection module)
- The selection of these status reports can be done, e.g., via another module in which status reports are selected by activating a checkbox.
- Create a macro module for this button.
- Adjust the following parameters in this macro:
exp_path
= save path of the created PDF filefile_name
= "name of the created PDF file"REPORT_MOD_ID
=module, which is used for output
(=report module). For status reports, e.g., the MOD009A52 Status Report default moduleREPORT_VARIANT_ID
= required variant of the report moduleDA_PYTHON_ID
= name of the source data area in selection mode
# Moduleinstellungen: Exportpfad. Exportdateiname, Ausgabemodul und zu verwendende Variante, Python-ID des Quell-Datenbereichs
exp_path = 'Exportpfad'.replace(chr(92),chr(92)+chr(92))
file_name = "Name der erzeugten PDF Datei"
REPORT_MOD_ID = "Modul-ID"
REPORT_VARIANT_ID = "Varianten-ID"
DA_PYTHON_ID = 'Python-ID'
#Auslesen der Druckeinstellungen aus dem Reportmodul
module_customizing_record = ppms.search_record(405, [REPORT_MOD_ID], [25609,25610,1789,2947], True)
page_size = module_customizing_record.paper_format.get_value()
landscape = not bool(module_customizing_record.portrait_format.get_value())
zoom = float(module_customizing_record.zoom_print_preview.get_value())
fit_to_page = bool(module_customizing_record.default_zoom_col.get_value())
#Modulobjekte
macro_module = ppms.get_macro_module()
select_module = macro_module.get_invoker_module()
#Zusammensetzung des Befehls fuer den Client
CLIENT_CODE = """
e = get_Env()
pdf_list = e.PdfExportDocumentsList
list = e.PdfExportDocumentsList
page_size = '{page_size}'
landscape = {landscape}
zoom = {zoom}
fit_to_page = {fit_to_page}
for uid in {export_list}:
module = e.ActivePanel.ModuleManager[uid]
doc = module.CreatePdfExportDocument(pageSize=page_size, landscape=landscape, zoom=zoom, fitToPage=fit_to_page)
pdf_list.Add(doc)
e.ActivePanel.ModuleManager
e.GeneratePdfFile(pdf_list, '{exp_path}', '{file_name}')
"""
def get_selected_reports():
export_list =[]
modules_to_close = []
for pr_rec in select_module.get_da(DA_PYTHON_ID).get_records():
pr_id = pr_rec.pr_id.get_raw_value()
main_pr_id = pr_rec.main_pr_id.get_raw_value()
report_id = pr_rec.report_id.get_raw_value()
#Alle im Reportmodul verwendete Filterkriterien setzen
select_module.set_new_L_var(30, [pr_id])
select_module.set_new_L_var(78, [report_id])
select_module.set_new_L_var(74, [main_pr_id])
#select_module.set_new_L_var(26, [report_id]) - wird im Makro des Statusberichts gesetzt
#select_module.set_new_L_var(25, [report_id]) - ist im Standard leer
#Aufruf der Modul-Variante (angedockt ausserhalb der Bildschirmanzeige)
reporting_module=select_module.open_module(REPORT_MOD_ID,
dock_to_module=select_module.get_uid(),
forced_status=2,
dock_style=3,
dock_proportion=0.001,
foreground=0,
focus=0)
reporting_module.apply_mv_by_id(REPORT_VARIANT_ID)
reporting_module.menu(12)
modules_to_close.append(reporting_module)
#Interne Nummer des geoeffneten Moduls
uid = str(reporting_module.get_uid())
#Offene Module zur Liste fuer PDF-Schnittstelle anfuegen
export_list.append((uid))
client_call = CLIENT_CODE.format(export_list=export_list, exp_path=exp_path, file_name=file_name,
page_size=page_size, landscape=landscape,
zoom=zoom, fit_to_page=fit_to_page)
ppms.client_exec(client_call)
for module in modules_to_close:
module.menu(49)
select_module.menu(49)
#Schleife fuer Anzeige Modulvariante
get_selected_reports()
Notes
- For the transfer of data to the client, an rpc service is to be used.
- When using the !IronPython method
CreatePdfExportDocument()
, the parameter names must be specified as well.-
doc = module.CreatePdfExportDocument(pageSize='A4',landscape=TRUE, zoom=100.0, fitToPage=TRUE)
stattdoc = module.CreatePdfExportDocument('A4', TRUE, 100.0,TRUE)
-