Mar-05-2021, 07:35 PM
(This post was last modified: Mar-05-2021, 07:35 PM by Gribouillis.)
I call the following script 'a2pdf'. It sends a text on its standard input to a pdf format on its standard output, using the venerable a2ps utility and the commands iconv and ps2pdf.
#!/usr/bin/env python3
import argparse
import subprocess as sp
import sys
__version__ = '0.0.1'
def main():
parser = argparse.ArgumentParser(description='Write text input to pdf')
parser.add_argument('-o', '--output-file', metavar='OUTPUT-FILE', type=str,
help='output.pdf', default='-', dest='ofile')
args = parser.parse_args()
com = "iconv -c -f utf-8 -t ISO-8859-1 | a2ps --columns=1 -f12 -R -B --borders=no -Xlatin1 -o - | ps2pdf - {ofile}".format(ofile=args.ofile)
proc = sp.Popen(com, shell=True, stdin=sys.stdin, stdout=sys.stdout)
proc.wait()
if __name__ == '__main__':
main()To use it, just pipe the output of some command, for exampleOutput:ls -l | a2pdf -o out.pdfOr pipe directly the ouptut to a pdf viewer such as okularOutput:ls -l | a2pdf | okular -It is currently a rudimentary tool. You can develop your own ways of setting the subcommand's numerous options.
