Share ideas, ask questions, and get feedback about developing for ProcessMaker
Forum rules: Please post new questions under "Developing processes & programming" for ProcessMaker 2 or 3.
#785756
Is your PDF an Output Document file, an Input Document file, or an attached file to a File field? What version of PM are you using?

Do you want a link to the file that the user can click to download or do you want the download to automatically start when a trigger is executed?
#785769
You didn't say whether you want a link or a forced download, so I will give you the code for both.

Create the following trigger which is set to execute at some point after the Output Document step in your process:
Code: Select all
//set to the ID of the Output Document:
$docId = '104383001575af439cddf47039853493';
$caseId = @@APPLICATION; //set the the ID of the case

$query = "SELECT APP_DOC_UID, DOC_VERSION FROM APP_DOCUMENT 
   WHERE APP_UID='$caseId' AND DOC_UID='$docId' AND APP_DOC_STATUS='ACTIVE'
   ORDER BY DOC_VERSION DESC";
$result = executeQuery($query);

if (!is_array($result) or count($result) == 0) {
   die("Error: Unable to find Output Document file for case $caseId.");
}

$fileId = $result[1]['APP_DOC_UID'];
$version = $result[1]['DOC_VERSION'];
$d = new AppDocument();
$aFile = $d->Load($fileId, $version);
$filename = $aFile['APP_DOC_FILENAME'].'_'.$version.'.pdf';

//link to Output Document file:
//change to '&ext=doc' if MS Word file
$fileUrl = (G::is_https() ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] .
	//':' . $_SERVER['SERVER_PORT'] . //uncomment if using a port number
	'/sys' .@@SYS_SYS. '/neoclassic/en/cases/cases_ShowOutputDocument?a=$fileId&v=$version&ext=pdf';

//path to the Output Document file on the server:
$filePath = PATH_DOCUMENT . G::getPathFromUID(@@APPLICATION) . PATH_SEP . "outdocs" . PATH_SEP .
	$fileId .'_'. $version .'.pdf'; // change to '.doc' if MS Word file

//to force the file download in the server:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
ob_flush();
flush();
If creating a link to the file, see this example: http://wiki.processmaker.com/3.0/Output ... _DynaForms

Fildena double 200 mg capacity to move the relaxin[…]

Wat is Fildena Double 200?

Fildena double 200 mg capacity to move the relaxin[…]

💥 Join the Exclusive Trading Community and Experie[…]

Briefly introduce the topic and provide context. S[…]