Convert csv data to a pdf file

Contents
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

Related articles
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
BibTeX bibliography
Beamer presentations
TikZ graphics
Overleaf online editor
Conference posters

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: