You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: xASL_qc_CreatePDF.m
    path of file: ./repos/ExploreASL/Functions/QualityControl
    
    the code of the file until where you have to start completion: function xASL_qc_CreatePDF(x, DoSubject)
%xASL_qc_CreatePDF Print output QC
%

    
function xASL_qc_CreatePDF(x, DoSubject)
%xASL_qc_CreatePDF Print output QC
%
% FORMAT: xASL_qc_CreatePDF(x[, DoSubject])
%
% INPUT:
%   x           - structure containing fields with all information required to run this submodule (REQUIRED)
%   DoSubject   - index of subject to process (REQUIRED)
%
% OUTPUT: n/a
% OUTPUTFILE:
%   xASL_Report_SubjectName.pdf - printed PDF rapport containing QC images & values
%
% -----------------------------------------------------------------------------------------------------------------------------------------------------
% DESCRIPTION: This function iterates over all values in x.Output and all
%              images in x.Output_im, and prints them in a PDF file.
%              x.Output & x.Output_im should contain the QC/result output
%              of all ExploreASL pipeline steps.
%
%              Further code explanation:
%              Below, using the Matlab & SPM Figure tools we create an image, which is
%              then printed to a PDF file
%
%              - fg = the main Figure handle
%              - ax = "axes" handles, these are objects containing either 1) text or 2)
%              images, with fg as "parent" (1) & (2) images have ax as "parent"
%              Positions are calculated in such a way that 4 categories can be printed,
%              which will be the first 4 fields found in x.Output
%              then allowing 8 single slice images, and 15 text lines (name & value
%              columns)
% 
% EXAMPLE: xASL_qc_CreatePDF(x);
% __________________________________
% Copyright (C) 2015-2021 ExploreASL


if ~usejava('jvm') % only if JVM loaded
    fprintf('Warning: skipping PDF report, JVM missing\n');
    return;
end

fprintf('Printing ExploreASL PDF report:   ');


%% -----------------------------------------------------------------------------------------------
%  Admin
if length(DoSubject)~=1
    warning('Too many indices provided for PDF creation! Using first subject only');
end

% Determine x.mat file
PathX = fullfile(x.dir.SUBJECTDIR,'x.mat');

% Check if x.mat file exists already
if ~exist(PathX, 'file')
    warning([PathX ' didnt exist, skipping xASL_qc_CreateOutputPDF']);
    return;
end