[reportlab-users] Future of py2pdf
Dave Kuhlman
dkuhlman at rexx.com
Wed Dec 3 18:08:12 EST 2008
On Wed, Nov 19, 2008 at 11:50:48AM +0100, Dinu Gherman wrote:
> Hi,
>
> I've just looked again at a tool named py2pdf, that I wrote
> and that was included in the ReportLab distribution in 2001
> I think (with reportlab 0.92 or so!). AFAIK, the Python Wing
> IDE used this module and maybe still does.
Dinu -
Thank you for a very useful and useable tool. I use pypdf.py
frequently to produce displayable sample code for students to whom
I'm teaching Python. I hope you will continue to support it.
I've made a couple of changes to my copy of py2pdf.py. I'd like to
suggest that you consider including these changes. The changes
are:
1. I'd like to be able to add the ".pdf" extension to file names
rather than replace the ".py" with ".pdf". So I added command
line flags to control that.
2. I'd like line numbering to start with 1 rather than 0. I
hard-wired that into py2pdf.py. Maybe, if you choose to support
this, you would want to add a command line flag, for example,
something like --initial-line-number, along with a default of
0 or 1, whichever.
I've attached a patch file and the original to which I made my
changes. Needless to say, you know py2pdf.py better than I and are
likely to know better ways to make these changes. Still, I'm
hoping that a patch file will save you some work.
Thanks again for a really good tool.
- Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
-------------- next part --------------
*** orig/py2pdf.py Fri Nov 21 16:08:26 2008
--- py2pdf.py Fri Nov 21 16:51:55 2008
***************
*** 42,47 ****
--- 42,50 ----
--multiPage generate one file per page (with filenames
tagged by 1, 2...), disables PDF outline
--noOutline don't generate PDF outline (default: unset)
+ --outExt output file extension (default: '.pdf')
+ --appendOutExt append rather than replace output file extension
+ (default: replace)
-v or --verbose set verbose mode
Takes the input, assuming it is Python source code and formats
***************
*** 356,362 ****
'paperFormat': 'A4',
'landscape' : 0,
'title' : None,
! 'multiPage' : 0})
# Default colors (for color mode), mostly taken from py2html.
self.pool.update({'commCol' : HexColor('#1111CC'),
--- 359,368 ----
'paperFormat': 'A4',
'landscape' : 0,
'title' : None,
! 'multiPage' : 0,
! 'outExt': '.pdf',
! 'appendOutExt' : False,
! })
# Default colors (for color mode), mostly taken from py2html.
self.pool.update({'commCol' : HexColor('#1111CC'),
***************
*** 438,443 ****
--- 444,450 ----
lo = 'tabSize= paperFormat= paperSize= landscape stdout title= fontName= fontSize='
lo = lo + ' bgCol= verbose lineNum marcs help multiPage noOutline config= input= mode='
lo = lo + ' commCol= identCol= kwCol= strngCol= paramCol= restCol='
+ lo = lo + ' outExt= appendOutExt'
longOpts = string.split(lo, ' ')
try:
***************
*** 509,514 ****
--- 516,527 ----
elif name == 'files':
self.pool['files'] = value
+ elif name == 'outExt':
+ self.pool['outExt'] = value
+
+ elif name == 'appendOutExt':
+ self.pool['appendOutExt'] = True
+
else:
# Set the value found or 1 for options without values.
self.pool[name] = value or 1
***************
*** 542,553 ****
self.options = options
self.canvas = None
self.multiLineStringStarted = 0
! self.lineNum = 0
# Set a default color and font.
o = self.options
self.currColor = o.restCol
self.currFont = (o.fontName, o.fontSize)
### Helper methods.
--- 555,568 ----
self.options = options
self.canvas = None
self.multiLineStringStarted = 0
! self.lineNum = 1
# Set a default color and font.
o = self.options
self.currColor = o.restCol
self.currFont = (o.fontName, o.fontSize)
+ self.outExt = o.outExt
+ self.appendOutExt = o.appendOutExt
### Helper methods.
***************
*** 605,611 ****
def begin(self, srcPath, numLines):
"Things to do before doing anything else."
! self.lineNum = 0
self.pageNum = 0
self.numLines = numLines
self.srcPath = srcPath
--- 620,626 ----
def begin(self, srcPath, numLines):
"Things to do before doing anything else."
! self.lineNum = 1
self.pageNum = 0
self.numLines = numLines
self.srcPath = srcPath
***************
*** 616,622 ****
self.pdfPath = sys.stdout
else:
if srcPath != sys.stdin:
! self.pdfPath = os.path.splitext(srcPath)[0] + '.pdf'
else:
self.pdfPath = sys.stdout
--- 631,641 ----
self.pdfPath = sys.stdout
else:
if srcPath != sys.stdin:
! self.pdfPath, ext = os.path.splitext(srcPath)
! if self.appendOutExt:
! self.pdfPath = '%s%s%s' % (self.pdfPath, ext, self.outExt, )
! else:
! self.pdfPath = '%s%s' % (self.pdfPath, self.outExt, )
else:
self.pdfPath = sys.stdout
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py2pdf.py
Type: text/x-python
Size: 45666 bytes
Desc: not available
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20081203/f8ff6480/attachment-0001.py>
More information about the reportlab-users
mailing list