You can hook the STDOUT of the generator to the STDIN of your pdf generator with a pipe. You could also concatenate the text lines into a variable and then use that directly.
What exactly is the problem? Why aren't you using any of frozenwithjoy's suggested code?