Преобразовать данные из csv в pdf файл

Contents
Введение
Python
pdflatex
subprocess
Похожие статьи

Введение

Python

Допустим есть .csv файл input.csv в котором три столбца price, count и extra несколько строк

price,count,extra 2,5,10 3,7,12

Задача - прочитать из файла и на основе этих данных создать по pdf на каждую строку.

pdflatex

Решение с помощью 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])

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

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat