[reportlab-users] Reportlab + Python + RHEL 4 = Traceback (most recent call last)

Miguel Angel ing.miguel.angel at gmail.com
Sun Oct 12 17:34:35 EDT 2008


yes ...

---------------------------------
#!/usr/bin/python
# -*- coding: utf8 -*

import sys
import string
import os
import time
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter

class FacturaPdf:

def construirPdf(self):
archivoIn = open(str(sys.argv[-1]))
datos = archivoIn.read()

miTimeStamp = time.time()

# Realizamos un parseo simple por lineas
lista = string.split( datos, '\n' )
print lista[-1]

# Toma el archivo y le agrega el nombre pertinente
tipo_documentos = ["ORIGINAL","COPIA 1","COPIA 2"]
for doc in tipo_documentos:
if len(sys.argv)==2:
nombre = doc+" "+".".join(sys.argv[-1].split(".")[:1]+["pdf"])
else:
nombre = doc+" exro.pdf"
nombre = nombre.replace(" ","_")
c = canvas.Canvas(nombre, pagesize=letter)

# INSERTANDO DATOS EN EL AREA D
c.setFont("Helvetica", 8)

# Cliente
#c.drawString(85,678, lista[5])
c.drawString(85,678, "Nombre el cliente")

# NIT. Va una copia mas abajo
c.drawString(85,661, "8600017786")

# Direccion
c.drawString(85,648, "CR 126 A 17 50")

# Ciudad
c.drawString(85,634, u"BOGOTÁ")

# Telefono
c.drawString(85,620, u"teléfono")

# OC
c.drawString(85,604, "OC------")

# Remision
c.drawString(280,604, "8929")

# Factura Numero
c.drawString(510,634, "000000000000")

# Fecha Factura
c.drawString(510,620, "09/17/2008")

# Fecha Vencimiento
c.drawString(510,604, "10/17/2008")

# INSERTANDO DATOS EN EL AREA C
# Generando un time stamp

# INSERTANDO DATOS EN EL AREA D
# Valor Venta
c.drawString(526,320, "11857500.00")

# Valor Subtotal
c.drawString(526,293, "11857500.00")

# Observacion
c.drawString(45,304, "Abstenerse de efectuar Reteiva")

# IVA
c.drawString(526,277, "1897200.00")

# Total
c.drawString(526,263, "13754700.00")

# Son 1
c.drawString(55,249, lista[31])

# Son 2
c.drawString(55,241, lista[32])
#valor="* TRECE MILLONES SETECIENTOS CINCUENTA Y CUATRO
MIL SETECIENTOS PESOS CON 00/100 M/CTE"
# Parsea la linea y la divide
#valor.split(" ")
#valor.split(" ")[2]
#c.drawString(55,249, valor.split(" ")[2])
# Otro tratamiento
#c.drawString(55,249, valor[:76])
#c.drawString(55,241, "* "+valor[76:])

# Cliente inferior
c.drawString(451,148, "INDUSTRIAS IVOR CASA INGLESA")

# NIT inferior
c.drawString(451,138, "8600017786")

# Aqui se generan los tres Pdf: ORIGINAL, COPIA 1, COPIA 2
c.drawString(60,50, doc)
c.showPage()
c.save()
self.unirPdfs(nombre)

def unirPdfs(self,nombre):
comando = "pdftk "+nombre+" background watermark.pdf output
final_"+nombre
print comando
os.system(comando)

c = FacturaPdf()
c.construirPdf()
---------------------------------------------




On Sun, Oct 12, 2008 at 4:13 PM, Peter Mattingly
<pmattingly at mail.csuchico.edu> wrote:

> Can we see your code?

>

> On Sun, Oct 12, 2008 at 12:42 PM, Miguel Angel <ing.miguel.angel at gmail.com>

> wrote:

>>

>> Hi, first of all, I would like to apologize for my english.

>>

>> I have a linux box with RHEL 4 and:

>> - python-reportlab-1.20-1.rf

>> - python-2.3.4-14

>> - python-devel-2.3.4-14

>>

>> But when I run my code, show me this:

>>

>> [root at ibes dev]# python2.3 mydev.py

>> Traceback (most recent call last):

>> File "mydev.py", line 110, in ?

>> c.construirPdf()

>> File "mydev.py", line 46, in construirPdf

>> c.drawString(85,634, u"BOGOTÁ")

>> File "/usr/lib/python2.3/site-packages/reportlab/pdfgen/canvas.py",

>> line 1169, in drawString

>> t.textLine(text)

>> File "/usr/lib/python2.3/site-packages/reportlab/pdfgen/textobject.py",

>> line 334, in textLine

>> self._code.append('%s T*' % self._formatText(text))

>> File "/usr/lib/python2.3/site-packages/reportlab/pdfgen/textobject.py",

>> line 306, in _formatText

>> text = self._canvas._escape(text)

>> File "/usr/lib/python2.3/site-packages/reportlab/pdfgen/canvas.py",

>> line 231, in _escape

>> return _escapePDF(s)

>> File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfutils.py",

>> line 139, in _escape

>> return join(map(lambda c, d=_ESCAPEDICT: d[c],s),'')

>> File "/usr/lib/python2.3/site-packages/reportlab/pdfbase/pdfutils.py",

>> line 139, in <lambda>

>> return join(map(lambda c, d=_ESCAPEDICT: d[c],s),'')

>> KeyError: u'\xc1'

>>

>> What is the problem?

>>

>> Thanks, any help would be greatly appreciated.

>>

>>

>> --

>> Atentamente,

>>

>>

>> Miguel Angel Moreno Bolaños

>>

>> Usuario Linux registrado No. 391784

>> http://counter.li.org

>>

>> "El amor es un dolor entre pecho y espalda,

>> que sabe a papas fritas sin salsa de tomate!"

>>

>> Att: Nous

>> _______________________________________________

>> reportlab-users mailing list

>> reportlab-users at reportlab.com

>> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

>

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

>




--
Atentamente,


Miguel Angel Moreno Bolaños

Usuario Linux registrado No. 391784
http://counter.li.org

"El amor es un dolor entre pecho y espalda,
que sabe a papas fritas sin salsa de tomate!"

Att: Nous


More information about the reportlab-users mailing list