Convert csv data to a pdf file
| Introduction | |
| Python | |
| pdflatex | |
| subprocess | |
| Related articles |
Introduction
Python
Suppose there is a .csv file input.csv with three columns price, count and extra with several rows
price,count,extra 2,5,10 3,7,12
Task - read the file and create one pdf per row from this data.
pdflatex
Solution with pdflatex
python -m pip install pdflatex
import csv from pdflatex import PDFLaTeX with open("input.csv", "r") as fin: dr = csv.DictReader(fin, delimiter=",") j = 0 for i in dr: filename = "pdf_"+str(j)+".tex" j+=1 with open(filename, "w") as ftex: document = "\documentclass[a4paper,12pt]{article}\n"\ +"\\begin{document}\n"\ +"\section{Results}"\ +"$price = "+i['price']+"$\\\n"\ +"$count = "+i['count']+"$\\\n"\ +"$extra = "+i['extra']+"$\\\n"\ +"\end{document}" ftex.write(document) pdfl = PDFLaTeX.from_texfile(filename) pdf, log, completed_process = pdfl.create_pdf(keep_pdf_file=True, keep_log_file=True)
subprocess
import csv import subprocess with open("input.csv", "r") as fin: dr = csv.DictReader(fin, delimiter=",") j = 0 for i in dr: filename = "pdf_"+str(j)+".tex" j+=1 with open(filename, "w") as ftex: document = "\documentclass[a4paper,12pt]{article}\n"\ +"\\begin{document}\n"\ +"\section{Results}"\ +"$price = "+i['price']+"$\\\n"\ +"$count = "+i['count']+"$\\\n"\ +"$extra = "+i['extra']+"$\\\n"\ +"\end{document}" ftex.write(document) subprocess.check_call(["pdflatex", filename])
Article author: Andrei Olegovich
| LaTeX | |
| Tutorial | |
| All LaTeX symbols | |
| Title page | |
| LaTeX in HTML | |
| jpg and png in eps | |
| csv to pdf | |
| Installing tex on Linux | |
| Video Tutorials | |
| MiKTeX | |
| Errors |