It's better to have it done after birth. It's much better that way
Twenty years ago, if a woman wanted a DNA test before the baby was born, it could be done only if she needed a medically necessary test like amniocentesis or chorionic villii sampling, and those tests pose an element of risk to the baby. A doctor would not do those tests *just* to do a DNA test for paternity, though it could be done once the fluid was drawn.
But in the last decade, prenatal DNA testing for paternity has been developed that can be done simply by drawing blood from the mom and the suspected dad(s). Drawing blood from the mom's arm does not cause any risk to the baby.
You asked about whether it is safe, and the answer is yes, but that doesn't mean a lot of people do it. That is because it is ten times as costly to do a DNA test before the baby is born. People often decide the two thousand dollars are better spent on the baby's necessary stuff.
Here's a link that talks about the kind of test we are talking about. Be careful if you go this route that there are some labs (*not* the two mentioned in the article!) with reputations for losing results and giving inaccurate answers.
http://www.nytimes.com/2012/06/20/health/paternity-blood-tests-that-work-early-in-a-pregnancy.html?pagewanted=all&_r=1&