There is a really simple solution using undocumented features of CERTUTIL. You can use the
-ENCODEHEX
verb with an undocumented format at the end to directly get your desired output of base 64 all on one line without any headers.
certutil -encodehex -f sample.pdf B64.txt 0x40000001
See the DosTips More Tricks with certutil thread for more information. Especially look at this 4th post for a detailed explanation of all the format options.