[scribus] PDFfile causes looping to fail?

Gregory Pittman gpittman at iglou.com
Tue Feb 26 14:38:45 UTC 2019


On 2/26/19 5:58 AM, Jerry Stratton wrote:
> I have the following script that I have simplified down to the basics:
> 
> ----------------------
> import scribus
> 
> countDown = ['three', 'two', 'one']
> 
> #scribus.PDFfile()
> for counter in countDown:
> 	scribus.messageBox('Countdown', counter)
> ----------------------
> 
> If I run it with scribus.PDFfile commented out, as above, it pops up a window for “three”, “two”, “one” as I expect. If I uncomment the scribus.PDFfile() line, however, I get the countdown, but after the final item I also get this error:
> 
> Traceback (most recent call last):
>  File "<string>", line 8, in <module>
>  File "/Users/jerry/bin/Scribus/testPDF.py", line 6, in <module>
>    for counter in countDown:
> IndexError: list assignment index out of range
> 
> The error appears to show up whenever a list is looped through; for example, os.path.join will fail with the same error:
> 
> ----------------------
> import scribus
> 
> scribus.PDFfile()
> os.path.join('/Users/', 'fred.pdf')
> ----------------------
> 
> Produces:
> 
> Traceback (most recent call last):
>  File "<string>", line 8, in <module>
>  File "/Users/jerry/bin/Scribus/testPDF.py", line 4, in <module>
>    os.path.join('/Users/', 'fred.pdf')
>  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.7/posixpath.py", line 67, in join
>    for b in p:
> IndexError: list assignment index out of range
> 
> I did a Google search on lists.scribus.info for “list assignment index out of range” and only found an unfinished discussion back in 2009.
> 
> Am I doing something wrong?
> 
> Currently I’m getting around it by not using os.path.join to create paths after calling PDFfile(), using string concatenation instead; and checking inside the loop if the loop variable is currently equal to the end variable,  breaking out if so. But that only works for unique lists, of course.
> 

Hi Jerry,

This isn't the way to use scribus.PDFfile(). I'm not sure if it's in the 1.4.7 documentation, but at least in 1.5.x, if you look under PDF Export from the menu, there is an explanation of the user of PDFfile() at the bottom:

pdf = scribus.PDFfile()
pdf.file = 'MyFile.pdf'
pdf.save()

scribus.PDFfile() creates a class which you can then do further actions on. 

A more complex example would be:

pdf = scribus.PDFfile()
pdf.file = 'MyFile.pdf'
pdf.quality = 1
pdf.fontEmbedding = 0
pdf.version = 13
pdf.pages = [2, 3, 4, 8]
pdf.save()

Greg




More information about the scribus mailing list