Delonix R.
Delonix R.

Reputation: 131

Report Lab is not producing/saving a pdf file

Report lab is not producing a pdf in a very simple example/try:

from arcpy import *
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from pyPdf import PdfFileWriter, PdfFileReader
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter, cm
from reportlab.platypus import Paragraph
from reportlab.lib import colors
from reportlab.pdfgen import canvas

filename = "HelloWorld.pdf"
c = canvas.Canvas(filename)
c.drawString(100,750,"Welcome to Reportlab!")
c.save()

These two lines work fine: c.drawString(100,750,"Welcome to Reportlab!") c.save() But is this one that throw the errors. I've tried to change the path, the filename, try the 'r' before the string of text for the path+filename, nothing works.

I've got this error trace:

Traceback (most recent call last):
  File "C:\Users\Edmundo\GIS_SEG\EGtemp\PdfReports\PyScripts\TestRepLab.py", line 15, in <module>
    c.save()
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfgen\canvas.py", line 1237, in save
    self._doc.SaveToFile(self._filename, self)
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 221, in SaveToFile
    data = self.GetPDFData(canvas)
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 246, in GetPDFData
    return self.format()
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 423, in format
    IOf = IO.format(self)
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 871, in format
    fcontent = format(self.content, document, toplevel=1)   # yes this is at top level
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 80, in format
    f = element.format(document)
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 1561, in format
    return PD.format(document)
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 679, in format
    L = [(format(PDFName(k),document)+b" "+format(dict[k],document)) for k in keys]
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 80, in format
    f = element.format(document)
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\pdfdoc.py", line 610, in format
    s.decode('pdfdoc')
  File "C:\Python27\ArcGIS10.4\lib\site-packages\reportlab\pdfbase\rl_codecs.py", line 1047, in _rl_codecs
    if name.startswith(e): return RL_Codecs.__rl_codecs(e)
AttributeError: 'NoneType' object has no attribute '_RL_Codecs__rl_codecs'

Upvotes: 2

Views: 2645

Answers (1)

rahlf23
rahlf23

Reputation: 9019

You need to call showPage():

from reportlab.pdfgen import canvas

filename = "HelloWorld.pdf"
c = canvas.Canvas(filename)
c.drawString(100,750,"Welcome to Reportlab!")
c.showPage()
c.save()

Upvotes: 1

Related Questions