Include file upload button inside post and process file

It looks like you want a few things from a single button press.

  1. Initiate request
  2. Process request
  3. Prompt user

WP AJAX will let you utilize jQuery to send a request to admin ajax (action) and trigger your process using shell_exec. When complete you’ll compose the response with wp_send_json_success() and read the result back on your main page. If the process has completed, you can prompt the user at that point to download the file with the information you provided in your AJAX response.

You can also utilize custom endpoints with the REST API instead of admin-ajax.php which will handle encoding on the return value.

add_action( 'rest_api_init', function () {

    register_rest_route( 'pdf/v1', '/process/', array(
        'methods' => 'GET',
        'callback' => 'process_pdf',
    ) );
} );

How you prompt the user is up to you.

If you went with admin_post_(action) you could do must of the above and automatically initiate the download with a header response from PHP.