A simple resistive divider network is all that you need. Three 33K resistors would be fine, all in series between the encoder output and ground. Tap at the top of the resistor connected to ground and you'll have approximately 4 volts out with 12 volts in.
I like the idea of the optocouple better. Seems to be more safe than the resistive diviser. Can't find any good diagram. it should be something like this?
If the encoder has open collector outputs, you may only need pullup resistors to 3.3V, but?
If you do use optos, make sure they can reliably transmit your encoder's highest pulse rate, which is?
What is the maximum speed of this encoder? Standard photo-transistor output opto-couplers aren't
particularly fast so this might be an issue if its a high rate of pulses.
The only information about the encoder on the website is this.
The chip built-in encoder, the signal has been a little wave processed, the accuracy of 400 pulses per second.
A plurality of photoelectric sensors built in, can be output Standard square wave, can be directly connect with microcontroller or PLC board, determine the motor reversing, speed control, stroke position control, synchronous operation paired synchronization and batch funcions.
Red line: DC7v-24v power input, needs a stable and less interference DC power supply
Green line: Pulse output, high level equal to the input voltage, low 0v, the standard square wave.
White line: Pulse output, high level equal to the input voltage, low 0v, the standard square wave.
Black wire: Negative pole of power supply
Hope this helps. unfortunately don't have a background in electronics to give more information.