报告实验室没有在一个非常简单的例子中生成pdf /尝试:
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()
这两行很好用: c.drawString(100,750,“欢迎来到Reportlab!”) c.save() 但这是否会引发错误。我试图改变路径,文件名,在路径+文件名的文本字符串之前尝试'r',没有任何作用。
我有这个错误跟踪:
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'
答案 0 :(得分:0)
您需要致电showPage()
:
from reportlab.pdfgen import canvas
filename = "HelloWorld.pdf"
c = canvas.Canvas(filename)
c.drawString(100,750,"Welcome to Reportlab!")
c.showPage()
c.save()