Yes, you can do it.
But I think if you draw a ray diagram you may see a problem if you use a pinhole, you bring it very close to your subject, and your film sensitivity curve isn't narrow. For one thing the material in which the hole is made would need to be very thin, or you'll get some odd vignetting. But also remember that pinhole is kind of the opposite of a modern apo/uld/ED lens... a pinhole does a very poor job of focusing different wavelengths to the same plane. As the subject gets closer to the pinhole, that issue should get more noticeable: rays containing all the colours will need to approach the pinhole from more extreme angles. Hence my suggestion to use a film with a narrow sensitivity curve... it'd be best if it were sensitive to a single wavelength
But try what you have in mind, who knows, maybe it will work for you. Experimentation is good!
Another thought would be to shoot several exposures with slightly different focus, and stack those. Or get a lens that stops down more!