We can remove pages from a pdf using pdfbox
To delete all pages but the first one, example:
Pd=org.apache.pdfbox.pdmodel.PDDocument;
PDFile=java.io.File(fullfile(Path,File));
document=Pd.load(PDFile);
npages=document.getNumberOfPages
if npages>1
for i=npages:-1:2
document.removePage(i-1);
end
document.save(fullfile(Path,File));
end
document.close;