That's a script, but it doesn't really conform to your requirements. Specifically, it ignores the case when there is no subdirectory.
The following is a bit contorted but should perhaps work.
Code:
#!/bin/sh
set -o nullglob
pdf=false
for f in /myserver/myfolder/*; do
test -d "$f" || continue
for p in "$f"/*.pdf; do
pdf=true
X
break
done
$pdf || break
done
$pdf || Z