I'm not quite sure that I fully understand your issue but I have contributed a few books to mobileread's public domain library and these all started life as plain text, (.txt), documents so maybe I can point you in the direction that I found helpful.
There's a really simple technique that you can use with .txt files which can lead to a good conversion with calibre and it's called
Markdown. It only takes about 15 minutes to learn and can then be applied manually or semi-automatically, (regex), to your text file. There's nothing to install, just learn the syntax here:
https://daringfireball.net/projects/markdown/basics
Markdown will let you apply headings, sub-headings, section headings, bold, italic, item lists, footnotes etc. to your plain text without any need to use HTML. It's elegant and practical.
For example:
to apply a level 1 heading, (h1), start a line with: #
to apply a level 2 heading, (h2), start a line with: ##
for level 3, (h3), start with ###
(These may actually be a good start for you since you have already mentioned h2 and h3).
For conversion purposes the magic happens by using calibre's "TXT Input" options during conversion.
Set Paragraph style to "off" and Formatting style to "markdown" and calibre will do the rest: all your careful markdown will be used to produce a well styled document.
Calibre will convert lines starting with # to h1, lines starting with ## to h2, ### to h3 etc. and the default structure detection options will ensure a page-break before your h1 and h2 lines.
Incidentally, why do you particularly want to generate a PDF document?