I think that a lot of what makes something "fanfic" is the fact that it's not legal to publish professionally for money.
That's what the real difference between writing a novel about Edward Pellew (real historical person) and Robert Lindsay (actor who played him in adaptation of historical novel in which Pellew appeared) is, with regard to one being original fiction, and one being fanfiction. (Of course if Horatio Hornblower is in your Pellew story, it's also fanfic, but that's not the same thing as writing a historical novel about Pellew in which the only characters whose names do not appear in historical records are ones that you made up yourself.)
no subject
That's what the real difference between writing a novel about Edward Pellew (real historical person) and Robert Lindsay (actor who played him in adaptation of historical novel in which Pellew appeared) is, with regard to one being original fiction, and one being fanfiction. (Of course if Horatio Hornblower is in your Pellew story, it's also fanfic, but that's not the same thing as writing a historical novel about Pellew in which the only characters whose names do not appear in historical records are ones that you made up yourself.)