REDCap::getPDF
(REDCap >= 6.4.0)
REDCap::getPDF
— Returns the content of a PDF file of one data collection instrument or all instruments in a project, in which the instruments can be 1) blank (no data), 2) contain data from a single record, or 3) contain data from all records in the project.
Description
string REDCap::getPDF ( [ string $record = NULL [, string $instrument = NULL [, int $event_id = NULL [, bool $all_records = FALSE [, int $repeat_instance = 1 [, bool $compact_display = FALSE ]]]]] )
Returns a PDF file of one data collection instrument or all instruments in a project, in which the instruments can be 1) blank (no data), 2) contain data from a single record (from either one event or all events, if longitudinal), or 3) contain data from all records in the project.
Parameters
record
The name of an existing record in the project. If record=NULL, then the method will return a blank PDF (containing no data) of one or all instruments.
instrument
The unique name of the data collection instrument (not the instrument label), which corresponds to the value of Column B in the Data Dictionary. If instrument=NULL, then all instruments in the project will be included in the PDF.
event_id
(longitudinal projects only) The event ID number that corresponds to a defined event in a longitudinal project. For classic projects, the event_id is not explicitly required, and thus it will be supplied automatically since there will only ever be one event_id for the project. If event_id=NULL for a longitudinal project and also record=NULL, then it will return data for all events for the given record.
all_records
Set to TRUE to return a PDF of all instruments with data from all records (and all events, if longitudinal). Note: If this parameter is set to TRUE, the parameters record, instrument, and event_id will be ignored. If set to FALSE, then the method will behave according to the first three parameters provided.
repeat_instance
(only for projects with repeating instruments/events) The repeat instance number of the repeating event (if longitudinal) or the repeating instrument (if classic or longitudinal). NOTE: This parameter was added in REDCap 7.3.4.
compact_display
Set to TRUE to return a compact-formatted PDF that excludes fields that have no data saved and excludes unselected multiple choice options, thus producing a smaller PDF file. If set to FALSE, all fields will be displayed normally.
Return Values
Returns the content of a PDF file, which can then be 1) stored as a file, 2) displayed inline on a webpage, or 3) downloaded as a file by a user's web browser.
Restrictions
This method can ONLY be used in a project context (i.e. when "pid" parameter is in the query string of the plugin URL) or else a fatal error is produced.
Examples
Example #1:
This example illustrates how to obtain a blank PDF file of all instruments in project and save it as a file on the web server.
// Get the content of the blank PDF of all instruments
$pdf_content = REDCap::getPDF();
// Save the PDF to a local web server directory
file_put_contents("/var/app001/my_pdfs/blank.pdf", $pdf_content);
Example #2:
This example illustrates how to obtain a PDF of one instrument for one record in a classic (non-longitudinal) project, and then display it as an inline PDF in a user's web browser.
// We have our record name and instrument name
$record = '101';
$instrument = 'participant_info';
// Get the content of the PDF for one record and one instrument
$pdf_content = REDCap::getPDF($record, $instrument);
// Set PHP headers to display the PDF inline in the web browser
header('Content-type: application/pdf');
header('Content-disposition: inline; filename="redcap_instrument.pdf"');
// Output the PDF content
print $pdf_content;
Example #3:
This example illustrates how to obtain a PDF of one instrument for one event for one record in a longitudinal project, and then have the PDF download as a file in a user's web browser.
// We have our record name, instrument name, and event_id
$record = '101';
$instrument = 'participant_info';
$event_id = 339;
// Get the content of the PDF for one record for one event for one instrument
$pdf_content = REDCap::getPDF($record, $instrument, $event_id);
// Set PHP headers to output the PDF to be downloaded as a file in the web browser
header('Content-type: application/pdf');
header('Content-disposition: attachment; filename="redcap_instrument.pdf"');
// Output the PDF content
print $pdf_content;
Example #4:
This example illustrates how to obtain a PDF file of all instruments and all records in project and save it as a file on the web server.
// Get the content of the PDF of all instruments and all records
$pdf_content = REDCap::getPDF(null, null, null, true);
// Save the PDF to a local web server directory
file_put_contents("C:\\my_pdfs\\all_records.pdf", $pdf_content);