pyFPDF one liners

Here you have some pyFPDF one-liners. I just wanted to know how it could be done.

Empty PDF document


python -c "import fpdf;d=fpdf.FPDF();d.add_page();d.output('o.pdf')"

Hello PDF document


python -c "import fpdf;pdf=fpdf.FPDF();pdf.set_font('times');pdf.add_page();pdf.write(0,'Hello');pdf.output('o.pdf')"

Convert text file ‘test.txt’ to PDF


cat test.txt | python -c "import fpdf;import sys;d=fpdf.FPDF();d.add_page();d.set_font('arial');d.multi_cell(0,d.font_size,''.join([l for l in sys.stdin]));d.output('o.pdf')"

Directory listing as a PDF


ls -rlt|python -c "import fpdf;import sys;d=fpdf.FPDF();d.add_page();d.set_font('arial');d.multi_cell(0,d.font_size,''.join([l for l in sys.stdin]));d.output('o.pdf')"

From standard input to PDF

First run this command:


python -c "import fpdf;import sys;d=fpdf.FPDF();d.add_page();d.set_font('arial');d.multi_cell(0,d.font_size,''.join([l for l in sys.stdin]));d.output('o.pdf')"

Then start writing and hitting ‘ENTER’ after each line:


Hello World
Creating a PDF from standard input.
Have to press Ctrl+D two times after last line to finish
and generate the PDF.

To finish you must press two times Ctrl+D.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s