Removing a header and footer from text output with PDFminer
This line performs the same string splitting 3 times:


outfile = pdf.split("_")[4] + "_" + pdf.split("_")[1] + "_" + \
    pdf.split("_")[0] + ".txt"



It would be better to split only once, and also to replace the messy string concatenation:

parts = pdf.split("_")
outfile = '{}_{}_{}.txt'.format(parts[4], parts[1], parts[0])




The variables could have better names.
When I see "pdf",
it makes me think of a PDF object.
But in this code it's just the filename string.
So I'd call it pdf_filename.



I don't have this Python library you're using,
and I'm just wondering if you could rewrite all those resources that you close manually (fp, device, outfp) to use the with syntax instead like you used for txtin and txtout.
If that's not possible with this library, then nevermind.