I think my conclusion is -- don't write a book unless you really want to write a book. Nobody but your parents are going to care that your book is in a bookstore. No software engineering interviewer is going to let you skip the interview because you wrote a book. The only reason you should do it is because you want to share your knowledge with the world. That is a valuable pursuit, but you will be undercompensated for it.
(Fun story... many years ago, a Google recruiter reached out to me with a little survey; rate yourself from 1-10 in these categories. They said 10 was "literally wrote a book on this subject". I answered 10 for web frameworks, which I had in fact written a book on! They ghosted me. But I did end talking with another recruiter, and ended up working at Google for 6 years, so... I guess it worked out.)
They also changed the terms of payment at some point. I used to get quarterly royalties via Paypal, but they wanted to switch to European bank transfer or something. That is impossible for people based in the US, and they just didn't seem to understand that. It sounds like something I could have sued them over, but the book was definitely past its prime at that point, so I just said "remove my name from the book and don't contact me" and that has worked out pretty well so far. (I think someone else did a second edition. Good for them!)
It was nice to be forced to write an entire book. I signed a contract, got an advance, and delivered it. Today's me would just tell users "read the source code if you have questions", but a book length tutorial was probably good for the project in general.
If you have the mental energy to write an entire book without anyone pushing you to complete it, I think you'll enjoy the enhanced control that you get by self-publishing. Collecting money for PDFs is a solved problem, and honestly, PDFs are a lot more useful than printed books anyway. It is always "neat" to show people a printed book that you wrote, but I'm not really sure that's worth the downsides. I buy programming books, but I haven't gotten a printed copy in years. They just live on my computer, where I'm actually doing the programming.