Merging Multiple PDF Reports into a Single File and Downloading in Ignition Perspective

Hello team,

How can I combine into a single PDF file in Ignition Perspective and download it using system.perspective.download?

Here is the script generating the PDF byte arrays:

def runAction(self, event):

		startTime = '2024-12-21 10:00:05'
		endTime = '2024-12-21 11:31:53'
		interval = 1	
		
		matching_levels = [
			{'ID': 1, 'Level': 'ESD 1'},
			{'ID': 2, 'Level': 'ESD 2'},
			{'ID': 3, 'Level': 'ESD 2.1'}
		]
		
		merged_pdf_bytes = ""
		
		for level in matching_levels:
			params = {
			    "StartDate": startTime,
			    "EndDate": endTime,
			    "Level": level['ID'],    
			    "Valves": interval,
			    "Name": level['Level']
			}
			
			file_bytes = system.report.executeReport(
			    path = "PSD Report",
			    project = system.util.getProjectName(),
			    parameters = params,
			    fileType = 'pdf'
			)
			
			# need to merge file_bytes each time the loop runs and store the overall result in merged_pdf_bytes variable
			
		filename = "Reports.pdf"
		system.perspective.download(filename, merged_pdf_bytes)

What is the best way to merge these byte arrays into a single PDF and trigger a download?

1 Like

Please see Wiki - how to post code on this forum.

There's no built-in solution. You cannot just merge the bytes--that makes a corrupt PDF file. I recommend the "PDFtk" external tool for this (community edition). Call the command line "pdftk server" using java's ProcessBuilder.

1 Like