Power OctoPi from printer
What you are looking for is called a "buck converter" or a "step down module". These literally cost about half a buck/Euro a piece. These converters convert a high voltage into a low voltage, the better ones are able to draw 2 to 3 Amps, which is required for stable operation of the Raspberry Pi.

If you have an old computer power supply of a decent brand (probably not as you refer to a kit/assembled printer, but added for completeness), you can even use the standby 5&nbsp;V line out and switch the power supply on using a relay to short the green wire of the PSU to ground. This is how I use it on one of my printers.

Note to power the Raspberry Pi through the micro USB port, to not bypass safety features.