Adjust a text frame to fit its content
Jump to navigation
Jump to search
- read a text file
- filter it line by line
- put it in a frame
- fit the height of the frame to the length of its content
#!/usr/bin/env python import sys try: import scribus except ImportError: print "This script only works from within Scribus" sys.exit(1) # read the content of the file line by line into the text frame file_name = 'mytext.txt' file_name = 'abc.txt' file = open(file_name, 'r') text = ""; for line in open(file_name, 'r') : if line != '\n': # put here some text handling/filtering text += unicode(line, 'iso-8859-2') # create a text frame and put the text into it x = 60 y = 100 w = 300 h = 10 frame = scribus.createText(x, y, w, h) scribus.setText(text, frame) # resize the frame in 10pt steps while (scribus.textOverflows(frame) > 0) : h += 10 scribus.sizeObject(w, h, frame) # undo the latest 10pt step and fine adjust in 1pt steps h -= 10 scribus.sizeObject(w, h, frame) while (scribus.textOverflows(frame) > 0) : h += 1 scribus.sizeObject(w, h, frame)