Pdf creation using python

Post on 29-Nov-2014

876 views 3 download

description

baabtra mentoring partner

Transcript of Pdf creation using python

Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd

Week Target

Achieved

1 23 192 25 233 30 27

4 35

Typing Speed

Jobs Applied# Company Designation Applied

DateCurrent Status

1 Skillsearch Limited

Junior software engineer

7/08/2013

2

3

PDF CREATION IN PYTHON

● Shameena

● shameenavayoli@gmail.com

● www.facebook.com/shameenalatheef

● twitter.com/shameena

● in.linkedin.com/in/shamean

● 9567135569

PDF- Portable Document Format

ReportLab :

---Open source python libraries for pdf creation.

---ReportLab is fast ,flexible, and fully cross platform

---The ReportLab library directly creates PDF based on your graphics commands

Installing syntax:

---sudo apt-get install python-pip

---pip install reportlab

The pdfgen package is the lowest level interface for generating PDF documents.

A pdfgen program is essentially a sequence of instructions for "painting" a document onto a sequence of pages

The interface object which provides the painting operations is the pdfgen canvas.

The canvas should be thought of as a sheet of white paper with points on the sheet identified using Cartesian (X,Y) coordinates

--default have the (0,0) origin point at the lower bottom left corner of the page.

A simple example program that uses a canvas follows.

from reportlab.lib.pagesizes import letter

from reportlab.pdfgen import canvasc = canvas.Canvas("form.pdf", pagesize=letter)

c.setFont('Helvetica', 12)

c.drawString(30,750,'OFFICIAL COMMUNIQUE')

c.drawString(30,735,'OF ACME INDUSTRIES')

c.drawString(500,750,"12/12/2010")

c.line(480,747,580,747)

c.drawString(275,725,'AMOUNT OWED:')

c.drawString(500,725,"$1,000.00")

c.line(378,723,580,723)

c.drawString(30,703,'RECEIVED BY:')

c.line(120,700,580,700)

c.drawString(120,703,"JOHN DOE")

c.save()

output

● If you’re in advertising or do any kind of work with form letters

● For that we want to import the following module

from reportlab.lib.enums import TA_JUSTIFYfrom reportlab.lib.enums import TA_JUSTIFY

from reportlab.platypus import SimpleDocTemplate, from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, ImageParagraph, Spacer, Image

from reportlab.lib.styles import getSampleStyleSheet, from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyleParagraphStyle

from reportlab.lib.units import inchfrom reportlab.lib.units import inch

● doc=SimpleDocTemplate("form_letter.pdf",pagesize=letter, rightMargin=72,leftMargin=72, topMargin=72,bottomMargin=18)

● styles=getSampleStyleSheet()● styles.add(ParagraphStyle(name='Justify',

alignment=TA_JUSTIFY))● Story.append(Paragraph(ptext,

styles["Normal"]))

If this presentation helped you, please visit our page facebook.com/baabtra and

like it.

Thanks in advance.  

www.baabtra.com | www.massbaab.com |www.baabte.com

Contact Us

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Start up VillageEranakulam,Kerala, India.

Email: info@baabtra.com