The application for a D visa is submitted before entering Croatia, at the competent embassy/consulate or at the VFS Global Visa Application Center.
Instructions and a list of required documents can be found on the website of the Croatian Ministry of Foreign and European Affairs.