Customizing
Version 26 39.5.25 39.5.23 39.5.22 39.5.21 39.5.20 39.5.19 39.5.18 39.5.17 German English
Version 26 39.5.25 39.5.23 39.5.22 39.5.21 39.5.20 39.5.19 39.5.18 39.5.17 German English

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 out if necessary, 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 file

    • file_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 module

    • REPORT_VARIANT_ID = required variant of the report module

    • DA_PYTHON_ID = name of the source data area in selection mode

Python
# module settings: Export path. Export file name, output module, and variant to be used, Python ID of the source data area        
exp_path = 'Exportpfad'.replace(chr(92),chr(92)+chr(92))
file_name = "Name of the created PDF file"
REPORT_MOD_ID = "Module ID" 
REPORT_VARIANT_ID = "Variant ID"  
DA_PYTHON_ID = 'Python ID' 
                
#Read out the print settings from the report module
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())

#Module objects
macro_module = ppms.get_macro_module()
select_module = macro_module.get_invoker_module()

#Structure of the command for the 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()
        
        #Set all filter criteria used in the report module
        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]) - is set in the macro of the status report
        #select_module.set_new_L_var(25, [report_id]) - is empty in standard

        #Call of the module variant (docked outside the on-screen display)
        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)
        #Internal number of the opened module
        uid = str(reporting_module.get_uid())
        
        #Add opened modules to the list for PDF interface
        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)

#Loop for display of module variant
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) statt doc = module.CreatePdfExportDocument('A4', TRUE, 100.0,TRUE)