def add_songs(all_songs, songs_double_page, manual_processing, songs_data, cache): # let's get the best sorting songs_combined = simplebin.best_fit(all_songs, EFFECTIVE_PAGE_HEIGHT) # sorting the songs alphabetic songs_sorted = sorted(songs_combined, key=lambda x: x[0]) # make sure the double page will be added on the left side page_num = scribus.pageCount() for double_page in songs_double_page: if not double_page in all_songs: continue offset = songs_sorted.index([double_page]) songs_sorted.insert(offset+1, None) # add a empty page after the song if (page_num + offset) % 2 != 0: # song is on right side, empty side on the left side. songs_sorted.insert(offset, songs_sorted.pop(offset+2)) # move next song before the double page # TODO: what if double sided song is last song? for songs in songs_sorted: current_pos = 0 if songs == None: # we added this for a song that should be set on double page new_page() continue for filename in songs: if not manual_processing[filename].get("show", True): continue data = songs_data[filename] height, page_num = load_song(data, current_pos, manual_processing[filename]) current_pos += math.ceil(height/BASELINE_GRID) * BASELINE_GRID cache[filename]["height"] = round(height, 2) cache[filename]["page"] = page_num scribus.progressSet(1) if current_pos != 0: new_page()
def exportText(textfile): page = 1 pagenum = scribus.pageCount() T = [] content = [] while (page <= pagenum): scribus.gotoPage(page) d = scribus.getPageItems() strpage = str(page) T.append('Page ' + strpage + '\n\n') for item in d: if (item[1] == 4): contents = scribus.getAllText(item[0]) if (contents in content): contents = 'Duplication, perhaps linked-to frame' T.append(item[0] + ': ' + contents + '\n\n') content.append(contents) elif (item[1] == 2): imgname = scribus.getImageFile(item[0]) T.append(item[0] + ': ' + imgname + '\n') page += 1 T.append('\n') output_file = open(textfile, 'w') output_file.writelines(T) output_file.close() endmessage = textfile + ' was created' scribus.messageBox("Finished", endmessage, scribus.ICON_NONE, scribus.BUTTON_OK)
def flow(self): while(scribus.textOverflows(self.name) > 0 and scribus.getTextLines(self.name)): current = self.name scribus.newPage(-1) scribus.gotoPage( scribus.pageCount() ) self.name = self.make_textframe() scribus.linkTextFrames(current, self.name)
def exportText(textfile): page = 1 pagenum = scribus.pageCount() T = [] content = [] while (page <= pagenum): scribus.gotoPage(page) d = scribus.getPageItems() strpage = str(page) T.append('Page '+ strpage + '\n\n') for item in d: if (item[1] == 4): contents = scribus.getAllText(item[0]) if (contents in content): contents = 'Duplication, perhaps linked-to frame' T.append(item[0]+': '+ contents + '\n\n') content.append(contents) elif (item[1] == 2): imgname = scribus.getImageFile(item[0]) T.append(item[0]+': ' + imgname + '\n') page += 1 T.append('\n') output_file = open(textfile,'w') output_file.writelines(T) output_file.close() endmessage = textfile + ' was created' scribus.messageBox("Finished", endmessage,icon=0,button1=1)
def run(self): selCount = scribus.selectionCount() if selCount == 0: scribus.messageBox('Scribus Data Merger- Usage Error', "There is no objects selected.\nPlease try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) csvData = self.loadCsvData() # Create a list with the names of the selected objects: selectedObjects = [] # Loop through the selected objects and put their names into the list selectedObjects o = 0 while (o < selCount): selectedObjects.append(scribus.getSelectedObject(o)) o = o + 1 startingPage = scribus.currentPage() lastRow = len(csvData) if(self.__dataObject.getNumberOfLinesToMerge() != 'All'): lastRow = int(self.__dataObject.getNumberOfLinesToMerge()) lastRow = min(lastRow, len(csvData)) # This will prevent the script from trying to merge data from non-existing rows in the data file currentPage = scribus.currentPage() rowNumber = 0 insertPageBeforeThis = -1 while (rowNumber < lastRow): if(scribus.pageCount() > currentPage): insertPageBeforeThis = currentPage + 1 scribus.newPage(insertPageBeforeThis) # Inserts a page before the page given as an argument currentPage = currentPage + 1 for selectedObject in selectedObjects: # Loop through the names of all the selected objects scribus.gotoPage(startingPage) # Set the working page to the one we want to copy objects from scribus.copyObject(selectedObject) scribus.gotoPage(currentPage) scribus.pasteObject() # Paste the copied object on the new page scribus.docChanged(1) scribus.gotoPage(currentPage) # Make sure ware are on the current page before we call getAllObjects() newPageObejcts = scribus.getAllObjects() for pastedObject in newPageObejcts: # Loop through all the items on the current page objType = scribus.getObjectType(pastedObject) text = CONST.EMPTY if(objType == 'TextFrame'): text = scribus.getAllText(pastedObject) # This should have used getText but getText does not return the text values of just pasted objects text = self.replaceText(csvData[rowNumber], text) scribus.setText(text, pastedObject) if(objType == 'ImageFrame'): text = scribus.getImageFile(pastedObject) # self.info("Image text", text) # Todo: Find out if it is possible to replace text in the ImageFile property rowNumber = rowNumber + 1 scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Merge Completed", "Merge Completed", icon=scribus.ICON_INFORMATION, button1=scribus.BUTTON_OK)
def exportText(root_folder): page = 1 pagenum = scribus.pageCount() T = [] content = [] while (page <= pagenum): scribus.gotoPage(page) d = scribus.getPageItems() page_folder = root_folder+"/p"+str(page) if not os.path.isdir(page_folder): os.mkdir(page_folder) for item in d: if (item[1] == 4): # the item is a text textfile = folder+"/p"+str(page)+"/"+item[0]+".txt" output_file = open(textfile,'w') output_file.writelines(scribus.getAllText(item[0])) output_file.close() page += 1 endmessage = "Text files successfully saved in "+root_folder scribus.messageBox("Finished", endmessage,icon=0,button1=1)
def syncPageNumbers(self): scribus.messageBox("Debut", "Apply page numbers", icon=0, button1=1) i = 0 totalpages = 1 # parses the book file; for each book document for element in self.root.iter("file"): files = element.text thing = etree.parse(files) # scribus.messageBox("Debut",str(files),icon=0,button1=1) rawstr = r"""Start=".+" R""" matchstr = etree.tostring(thing) compile_obj = re.compile(rawstr) textpage = 'Start="' + str(totalpages) + '" R' newstr = compile_obj.subn(str(textpage), etree.tostring(thing)) # Open file in Scribus to get the page quantity for each file through scribus own method doc = scribus.openDoc(files) pageqty = scribus.pageCount() totalpages += pageqty # sets the amount of page from the beginning of the first file scribus.closeDoc() # scribus.messageBox("Debut","begins at "+str(newstr[0]),icon=0,button1=1) FILE = open(files, "w") FILE.write(newstr[0]) FILE.close()
def get_imageframes_on_page(page_number, empty_only=False, name_filter=None): """ page_number: if 0 use current page, otherwise the given page set emty_only to return empty frames only name_filter: return frame if name conatins filter string returns a list of the image objects on the current page get all the items on the page """ current_page = sc.currentPage() if page_number > 0: if page_number <= sc.pageCount(): sc.gotoPage(page_number) else: logging.warning('Page {} out of rage.'.format(page_number)) return [] item_list = sc.getPageItems() # refine it to a list of only image objects objs = [] for item in item_list: if item[1] == 2: #type 2 == image add_image = True if empty_only: add_image = is_imageframe_empty(item[0]) and add_image if name_filter: if name_filter in item[0]: add_image = True and add_image else: add_image = False and add_image if add_image: objs.append(item[0]) sc.gotoPage(current_page) return objs
def pageList(self): listOfPages = [] i = 0 while i < scribus.pageCount(): i = i + 1 listOfPages.append(i) return listOfPages
def add_page_number(): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(page_num) textbox = scribus.createText(margin_left, page_height-margin_bottom, page_width-margin_left-margin_right, PAGE_NUM_HEIGHT) scribus.setStyle("pagenumber_{}".format(get_style_suffix()), textbox) scribus.insertText(str(page_num), 0, textbox) scribus.deselectAll()
def main(): text_frames, image_frames = get_placeholders() sla_template_filename = scribus.getDocName() sla_template_path = Path(sla_template_filename) if 'file' in CONFIGURATION['data'] and CONFIGURATION['data']['file']: data_path = str( sla_template_path.parent.joinpath(CONFIGURATION['data']['file'])) elif CONFIGURATION['data']['format'] == 'json': data_path = sla_template_path.with_suffix('.json') else: data_path = sla_template_path.with_suffix('.csv') if not os.path.isfile(data_path): sys.exit() if CONFIGURATION['data']['format'] == 'json': pass else: data_file = open(data_path, 'rt') reader = csv.DictReader(data_file) pdf_base_filename = sla_template_path.stem pdf_path = Path(sla_template_path.parent) if CONFIGURATION['output']['pdf']: pdf = scribus.PDFfile() pdf.quality = 0 pdf.fontEmbedding = 0 pdf.version = 14 scribus.setRedraw(False) for row in reader: for frame, placeholders in text_frames: fill_text_placeholders(frame, placeholders, row) for frame, placeholders in image_frames: fill_image_placeholders(frame, placeholders, row) pdf.file = str( pdf_path.joinpath(pdf_base_filename + '-' + next(iter(row.items()))[1].lower() + '.pdf')) pdf.save() scribus.docChanged(True) scribus.revertDoc() scribus.setRedraw(True) elif CONFIGURATION['output']['single-sla']: original_pages = list(range(1, scribus.pageCount() + 1)) for row in reader: new_frames = duplicate_content( original_pages, [i[0] for i in text_frames + image_frames]) for frame, placeholders in text_frames: fill_text_placeholders(new_frames[frame], placeholders, row) for frame, placeholders in image_frames: fill_image_placeholders(new_frames[frame], placeholders, row) for page in original_pages: scribus.deletePage(page)
def get_a4_pages(size, single, pages_count): if size == 'A5': return get_a4_pages_from_a5(single, pages_count) elif size == 'A6': return get_a4_pages_from_a6(single, pages_count) else: return [] print('{} are not yet supported'.format(scribus.pageCount()))
def fill_addresses(contacts): #on a page, we can put MAX_PAGE_CONTACTS contacts. nb_pages = (len(contacts) / MAX_PAGE_CONTACTS) + 1 for curPage in range(0, nb_pages): start_contact = curPage * MAX_PAGE_CONTACTS end_contact = start_contact + (MAX_PAGE_CONTACTS - 1) fill_page(contacts[start_contact:end_contact]) if (end_contact < len(contacts)): scribus.newPage(-1) scribus.gotoPage(scribus.pageCount() - 1)
def fill_addresses(contacts): #on a page, we can put MAX_PAGE_CONTACTS contacts. nb_pages = (len(contacts) / MAX_PAGE_CONTACTS) + 1 for curPage in range(0, nb_pages): start_contact = curPage * MAX_PAGE_CONTACTS end_contact = start_contact + (MAX_PAGE_CONTACTS -1) fill_page(contacts[start_contact:end_contact]) if(end_contact < len(contacts)): scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()-1)
def add_page_number(): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin( page_num) textbox = scribus.createText(margin_left, page_height - margin_bottom, page_width - margin_left - margin_right, PAGE_NUM_HEIGHT) scribus.setStyle("pagenumber_{}".format(get_style_suffix()), textbox) scribus.insertText(str(page_num), 0, textbox) scribus.deselectAll()
def makeToc(self, firstPageNr): pagenum = scribus.pageCount() for page in range(1, pagenum + 1): scribus.gotoPage(page) pageitems = scribus.getPageItems() for item in pageitems: if item[1] != 4: continue self.textbox = item[0] self.evalTocTemplate(firstPageNr) scribus.redrawAll()
def run(self): sourceDir = scribus.fileDialog("Comic Directory", isdir=True) scribus.newDoc( self.pageSize, self.margins, scribus.PORTRAIT, 0, scribus.UNIT_MILLIMETERS, scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT) for resource in os.walk(sourceDir): self.clean_up_and_queue(resource[0], resource[1], resource[2]) scribus.gotoPage(1) test = re.compile("[0-9]{1,}\.(%s)$" % self.formats, re.IGNORECASE) files = filter(test.search, self.images) files.sort() nImages = len(files) if nImages % 4 > 0: print "not" numPages = ( ((nImages / 4) +1 ) * 4 ) else: print ":p" numPages = nImages print numPages for page in range(1, numPages): scribus.newPage(-1) i = 1 for file in files: scribus.gotoPage(i) self.createImagePage(file, "image_%s" % i) i = i + 1 if os.path.isfile("%s/front_cover.jpg" % sourceDir): file = "%s/front_cover.jpg" % sourceDir scribus.newPage(1) scribus.gotoPage(1) self.createImagePage(file, "front_cover") if os.path.isfile("%s/back_cover.jpg" % sourceDir): file = "%s/back_cover.jpg" % sourceDir scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) self.createImagePage(file, "back_cover") if os.path.isfile("%s/logo_cover.svg" % sourceDir): file = "%s/logo_cover.svg" % sourceDir scribus.gotoPage(1) scribus.placeSVG(file, 0, 0) # result = scribus.messageBox('Debug', "%s" % self._comicInfo) scribus.setInfo("Fernando Michelotti", "Comics", "description") scribus.zoomDocument(-100) scribus.saveDoc()
def createNewPage(self, tbox): curPage = scribus.currentPage() if curPage < scribus.pageCount() - 1: where = curPage + 1 else: where = -1 logger.debug("cur=%d name=%s pc=%d wh=%d", curPage, tbox, scribus.pageCount(), where) cols = scribus.getColumns(tbox) colgap = scribus.getColumnGap(tbox) x, y = scribus.getPosition(tbox) w, h = scribus.getSize(tbox) mp = scribus.getMasterPage(curPage) scribus.newPage(where, mp) # return val? scribus.gotoPage(curPage + 1) newBox = scribus.createText(x, y, w, h) scribus.setColumns(cols, newBox) scribus.setColumnGap(colgap, newBox) scribus.linkTextFrames(tbox, newBox) logger.debug("link from %s to %s", tbox, newBox) return newBox
def evalTocEvents(self, runs, firstPageNr): toc = [] pagenum = scribus.pageCount() foundEvents = 0 for page in range(1, pagenum + 1): scribus.gotoPage(page) self.pageNr = firstPageNr + page - 1 pageitems = scribus.getPageItems() for item in pageitems: if item[1] != 4: continue tbox = item[0] tlen = scribus.getTextLength(tbox) logger.debug("tbox %s length %d", tbox, tlen) if tlen == 0: continue scribus.selectText(0, tlen, tbox) allText = scribus.getText( tbox) # getAllText returns text of complete link chain! z = 0 while True: x = allText.find("_evtid_:", z) if x < 0: break y = allText.find(STX, x) evtId = allText[x + 8:y] z = allText.find(ETX, y) titel = allText[y + 1:z] logger.debug("eventid %s, titel %s on page %d", evtId, titel, self.pageNr) event = self.gui.eventServer.getEventById(evtId, titel) toc.append((self.pageNr, event)) foundEvents += 1 logger.debug("sorting") toc.sort(key=lambda t: t[1].getDatumRaw()) # sortieren nach Datum for (pageNr, event) in toc: self.eventMsg = event.getTitel() + " vom " + event.getDatum()[0] logger.debug("event %s on page %d", self.eventMsg, self.pageNr) self.pageNr = pageNr for run in runs: self.run = run self.evalRun(event) self.insertText("\n", self.run) self.pageNr = None if foundEvents == 0: print("Noch keine Events gefunden") else: # remove template pos1, pos2, tbox = self.toBeDelPosToc scribus.selectText(pos1, pos2 - pos1, tbox) scribus.deleteText(tbox) scribus.redrawAll()
def listImages(filename): file_content = [] for page in range(1, scribus.pageCount() + 1): scribus.gotoPage(page) file_content.append('Page ' + str(page) + '\n\n') for item in scribus.getPageItems(): if item[1] == 2: file_content.append(scribus.getImageFile(item[0]) + '\n') file_content.append('\n') output_file = open(filename, 'w') output_file.writelines(file_content) output_file.close()
def front_matter(): # load pages from other document if not os.path.exists(pwd("front_matter.sla")): print "not front matter, file not found!" return scribus.openDoc(pwd("front_matter.sla")) pages = scribus.pageCount() scribus.closeDoc() scribus.importPage( pwd("front_matter.sla"), # filename tuple(range(1, pages+1)), # range of pages to import 1, # insert (1) or replace(0) 0, # where to insert ) scribus.gotoPage(pages+1)
def exportPDF(self, scribusFilePath, pdfFilePath): # Export to PDF scribus.openDoc(scribusFilePath) listOfPages = [] i = 0 while (i < scribus.pageCount()): i = i + 1 listOfPages.append(i) pdfExport = scribus.PDFfile() pdfExport.info = CONST.APP_NAME pdfExport.file = str(pdfFilePath) pdfExport.pages = listOfPages pdfExport.save() scribus.closeDoc()
def get_all_empty_images_frames(): image_frames = [] for page in range(1, scribus.pageCount() + 1): page_image_frames = [] scribus.gotoPage(page) # get all empty image frames on the page for item in scribus.getPageItems(): if item[1] == 2: if scribus.getImageFile(item[0]) == "": x, y = scribus.getPosition(item[0]) page_image_frames.append((item[0], x, y)) # sort the frames by position page_image_frames.sort(key=lambda k: [k[2], k[1]]) image_frames += [i[0] for i in page_image_frames] return image_frames
def front_matter(): # load pages from other document if not os.path.exists(pwd("front_matter.sla")): print "not front matter, file not found!" return scribus.openDoc(pwd("front_matter.sla")) pages = scribus.pageCount() scribus.closeDoc() scribus.importPage( pwd("front_matter.sla"), # filename tuple(range(1, pages + 1)), # range of pages to import 1, # insert (1) or replace(0) 0, # where to insert ) scribus.gotoPage(pages + 1)
def get_placeholders(): text_frames = [] image_frames = [] page_n = scribus.pageCount() for page in range(1, page_n + 1): scribus.gotoPage(page) for item in scribus.getPageItems(): if item[1] == 2: placeholders = get_image_placeholders(item[0]) if placeholders: image_frames.append((item[0], placeholders)) if item[1] == 4: placeholders = get_text_placeholders(item[0]) if placeholders: text_frames.append((item[0], placeholders)) return text_frames, image_frames
def fileMatchingTextFrame(sampleFrameName, pattern): pagenum = scribus.pageCount() for page in range(1, pagenum + 1): scribus.gotoPage(page) d = scribus.getPageItems() for item in d: # print(item) frameName = item[0] if (item[1] == 4): if frameName != sampleFrameName and remove_copy_prefix(frameName).startswith(pattern): print(frameName + " found") position = scribus.getPosition(frameName) scribus.selectObject(sampleFrameName) scribus.duplicateObject() #duplicateFrameName = scribus.getSelectedObject() scribus.moveObjectAbs(position[0], position[1]) scribus.deleteObject(frameName)
def fileMatchingTextFrame(sampleFrameName, pattern): pagenum = scribus.pageCount() for page in range(1, pagenum + 1): scribus.gotoPage(page) d = scribus.getPageItems() for item in d: # print(item) frameName = item[0] if (item[1] == 4): if frameName != sampleFrameName and remove_copy_prefix( frameName).startswith(pattern): print(frameName + " found") position = scribus.getPosition(frameName) scribus.selectObject(sampleFrameName) scribus.duplicateObject() #duplicateFrameName = scribus.getSelectedObject() scribus.moveObjectAbs(position[0], position[1]) scribus.deleteObject(frameName)
def main(argv): ########################################## # 1.import all images import_all_images.main_wrapper(sys.argv) # 2.add exit buttons add_exit_buttons.main_wrapper(sys.argv) # 3.add arrows and links add_arrows_and_links.main_wrapper(sys.argv) # done pagenum = scribus.pageCount() donetext = """ The photo documentation is ready! Page(s): """ + str(pagenum) + """ The following layers have been created: - Arrowlinks: a layer with the arrows and the annotation links to the pages - Exitbuttons: a layer with the exit buttons - Filenames: a layer with the file names of the images (if wanted) - Background : a layer with the images Tips: - Show layers in Scribus: Menu/Windows/Layers or F6 - Rotate object (e.g. arrows): R (do not rotate the links!) - Show object properties: Menu/Windows/Properties or F2 - In the properties, you can rotate and resize the images (select the "Background" layer first) - The object name of a link shows the destination page, e.g. "link_to_page_7" - Try to put also arrows and links into the images to navigate directly - Reduce the size of your pictures before starting PhotoDoc to speed up the process and reduce the PDF file size - Use the power of Scribus to enhance the documentation with textes, arrows, weblinks... - If you need to reproduce a step, delete the step layer and restart step script, e.g. "add_exit_buttons.py" - Export a PDF with 96 dpi as image resolution to reduce the PDF file size """ scribus.messageBox("PhotoDoc", donetext)
def processTemplate(xlat): if xlat is None: return logger.info(r'! process template') page = 1 pagenum = scribus.pageCount() while page <= pagenum: logger.info(r'.process page ' + str(page)) scribus.gotoPage(page) pitems = scribus.getPageItems() for item in [p for p in pitems if p[1] == 4]: logger.info(r'..process item: [%s] ', item) buf = scribus.getAllText(item[0]) logger.info(r'...cur text: [%s]', buf) phc = None # try to figure placeholder mbuf = re.search(r'[{]+(\w+)[}]+', buf) if mbuf is not None: # placeholder text phc = mbuf.group(1) Automator3.codes[item[0]] = phc else: # have we been here before? if item[0] in Automator3.codes: phc = Automator3.codes[item[0]] # ok. do we have a xlat for this? if phc is not None and phc in xlat: nstr = xlat[phc] else: nstr = buf try: scribus.replaceText(nstr, item[0]) logger.info('...new text: ' + str(nstr)) except scribus.ScribusException: logger.error('.. scribus setText failed') page += 1 logger.info('! done processing template')
def duplicate_content(pages, named_items): """ duplicate the content of pages at the end of the document and track the new item names for the items in named_items return the list of created item names from named_items """ result = {} page_n = scribus.pageCount() for page in pages: scribus.gotoPage(page) items = [item[0] for item in scribus.getPageItems()] scribus.newPage(-1, scribus.getMasterPage(page)) page_n += 1 for item in items: scribus.gotoPage(page) scribus.copyObject(item) scribus.gotoPage(page_n) scribus.pasteObject() if item in named_items: result[item] = scribus.getSelectedObject() return result
def exportText(filename): file_content = [] content = [] for page in range(1, scribus.pageCount() + 1): scribus.gotoPage(page) file_content.append('Page ' + str(page) + '\n\n') for item in scribus.getPageItems(): if item[1] == 4: contents = scribus.getAllText(item[0]) if contents in content: contents = 'Duplication, perhaps linked-to frame' file_content.append(item[0] + ': ' + contents + '\n\n') content.append(contents) elif item[1] == 2: imgname = scribus.getImageFile(item[0]) file_content.append(item[0] + ': ' + imgname + '\n') file_content.append('\n') output_file = open(filename, 'w') output_file.writelines(file_content) output_file.close()
def exportPDF(self, scribusFilePath, pdfFilePath): import scribus d = os.path.dirname(pdfFilePath) if not os.path.exists(d): os.makedirs(d) # Export to PDF scribus.openDoc(scribusFilePath) listOfPages = [] i = 0 while (i < scribus.pageCount()): i = i + 1 listOfPages.append(i) pdfExport = scribus.PDFfile() pdfExport.info = CONST.APP_NAME pdfExport.file = str(pdfFilePath) pdfExport.pages = listOfPages pdfExport.save() scribus.closeDoc()
def add_songs(all_songs, songs_double_page, manual_processing, songs_data, cache): # let's get the best sorting songs_combined = simplebin.best_fit(all_songs, EFFECTIVE_PAGE_HEIGHT) # sorting the songs alphabetic songs_sorted = sorted(songs_combined, key=lambda x: x[0]) # make sure the double page will be added on the left side page_num = scribus.pageCount() for double_page in songs_double_page: if not double_page in all_songs: continue offset = songs_sorted.index([double_page]) songs_sorted.insert(offset + 1, None) # add a empty page after the song if (page_num + offset ) % 2 != 0: # song is on right side, empty side on the left side. songs_sorted.insert( offset, songs_sorted.pop(offset + 2)) # move next song before the double page # TODO: what if double sided song is last song? for songs in songs_sorted: current_pos = 0 if songs == None: # we added this for a song that should be set on double page new_page() continue for filename in songs: if not manual_processing[filename].get("show", True): continue data = songs_data[filename] height, page_num = load_song(data, current_pos, manual_processing[filename]) current_pos += math.ceil(height / BASELINE_GRID) * BASELINE_GRID cache[filename]["height"] = round(height, 2) cache[filename]["page"] = page_num scribus.progressSet(1) if current_pos != 0: new_page()
def TemplateCheck(): """ Performs some sanity checks on the template page. Args: none Returns: None: No error. string: A string containing the error message """ # check number of documents open; we accept only one numDocs = scribus.haveDoc() if numDocs < 1: return "No document opened." elif numDocs > 1: return "More than one document is opened." # check number of pages that exist; we accept only one numPages = scribus.pageCount() if numPages < 1: return "No page created." elif numPages > 1: return "Please reduce the document to a single calendar template page." # check if items exist on this page numItems = len(scribus.getPageItems()) if numItems < 1: return "This page is empty." # check if at least one object's name starts with the MAGICSTRING magicStrings = 0 for item in scribus.getPageItems(): if item[0].find(MAGICSTRING) == 0: magicStrings += 1 if magicStrings == 0: return "No object with file name tag 't365_' found." return None
def main(): if not scribus.haveDoc(): return filename = scribus.fileDialog('Select a document', 'Scribus document (*.sla)') if not filename: return # find the masterpages in use in the source document scribus.openDoc(filename) pages = tuple(range(1, scribus.pageCount() + 1)) masterpages = [scribus.getMasterPage(p) for p in pages] scribus.closeDoc() # the current page before importing page = scribus.currentPage() # import pages by creating them after the current one scribus.importPage(filename, pages, 1, 1) for i, masterpage in enumerate(masterpages): scribus.applyMasterPage(masterpage, page + 1 + i)
def rmEventIdMarkers(self): pagenum = scribus.pageCount() for page in range(1, pagenum + 1): scribus.gotoPage(page) pageitems = scribus.getPageItems() for item in pageitems: if item[1] != 4: continue tbox = item[0] # frameLinks nonempty only if starten called from same gui if self.frameLinks.get( tbox ) is not None: # i.e. if tbox is not the root of a link chain continue # TODO find out if tbox is a linked frame tlen = scribus.getTextLength(tbox) if tlen == 0: continue scribus.selectText(0, tlen, tbox) allText = scribus.getAllText( tbox) # getAllText returns text of complete link chain! z = 0 xl = [] while True: x = allText.find("_evtid_:", z) if x < 0: break y = allText.find(STX, x) evtId = allText[x + 8:y] z = allText.find(ETX, y) titel = allText[y + 1:z] xl.append((x, z + 1 - x)) for (x, l) in reversed(xl): # the reversed is important! scribus.selectText(x, l, tbox) scribus.deleteText(tbox) scribus.redrawAll()
def main(): try: import scribus except ImportError: # if the script does not run inside of scribus, launch scribus with this script as paremeter filename = [] if (len(sys.argv) == 2): print("launching the script for " + sys.argv[1]) filename.append(sys.argv[1]) else: print("launching the script for each .sla in the directory.") for file in os.listdir('.'): filenameSplit = os.path.splitext(file) if filenameSplit[-1] == '.sla' and filenameSplit[0].find( '_autosave_') == -1: filename.append(file) arguments = [] for argument in sys.argv[1:]: if argument[0] == '-': # arguments.append('--python-arg') arguments.append('-pa') arguments.append(argument.strip('-')) print(arguments) for file in filename: call(['scribus', '-g', '-py', sys.argv[0]] + arguments + ['--', file]) sys.exit(1) if scribus.haveDoc(): page_sizes = {(210, 297): 'A4', (148, 210): 'A5', (105, 148): 'A6'} filename = os.path.splitext(scribus.getDocName())[0] pdf = scribus.PDFfile() page_size = tuple(int(round(s)) for s in scribus.getPageSize()) print(page_sizes[page_size]) page_size = page_sizes[page_size] pdf.file = filename + '-' + page_size.lower() + '.pdf' pdf.save() single_sided = 'single' in sys.argv print(sys.argv) print(single_sided) # sys.exit(1) pdf = scribus.PDFfile() pdf.file = filename + "-reordered.pdf" pdf.pages = get_a4_pages(page_size, single_sided, scribus.pageCount()) print(page_size) print(single_sided) print(scribus.pageCount()) print(pdf.pages) pdf.save() # os.system("pdfnup --nup 2x2 --frame false --no-landscape " + filename + "-reordered.pdf --outfile " + filename.replace("a6", "a4") + ".pdf") call([ 'pdfnup', '--nup', '2x2', '--frame', 'false', '--no-landscape', filename + '-reordered.pdf', '--outfile', filename + "-a4.pdf" ]) os.remove(pdf.file) else: print("No file open")
def new_page(): scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) add_page_number()
#!/usr/bin/env python # -*- coding: utf-8 -*- """ This Script redo hyphenation for the whole document """ import random try: import scribus except ImportError: print "This script only runs from within Scribus." sys.exit(1) pRange = xrange(1, scribus.pageCount()) for p in pRange: scribus.gotoPage(p) items = scribus.getPageItems() for i in items: iname, itype, iorder = i if itype == 4: scribus.dehyphenateText(iname) scribus.hyphenateText(iname)
def load_song(data, offset, settings): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin( page_num) start_point = margin_top + offset new_width = page_width - margin_left - margin_right if not FAST: scribus.placeEPS(os.path.join(FILES, data["filename"]), 0, 0) eps = scribus.getSelectedObject() eps_width, eps_height = scribus.getSize(eps) #scribus.scaleGroup(new_width/eps_width) # slow on scribus 1.4; does something else on scribus 1.5 scribus.sizeObject(eps_width * 0.86, eps_height * 0.86, eps) scribus.moveObjectAbs(margin_left, start_point + SPACING_HEADLINE_SONG, eps) eps_width, eps_height = scribus.getSize(eps) else: eps_height = 0 scribus.deselectAll() textbox = scribus.createText(margin_left, start_point, new_width, 20) style_suffix = get_style_suffix() if data["composer"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["composer"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) if data["poet"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["poet"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) scribus.deselectAll() scribus.insertText(u"{}\n".format(data["name"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("headline_{}".format(style_suffix), textbox) text = data["text"] text = [t.strip() for t in text if t.strip() != ""] # TODO: exit if text == [] textbox = scribus.createText( margin_left, start_point + eps_height + SPACING_HEADLINE_SONG + SPACING_SONG_TEXT, new_width, 50) scribus.setStyle("text", textbox) # let's see how many digits are in there: num_verses = len([l for l in text if l.isdigit()]) num_chars = 0 num_line_total = len(text) num_line_actually = 0 no_new_line = False verse_counter = 0 text_columns_height = 0 # TODO: should be None for num_line, line in enumerate(text): if line.strip == "": continue num_line_actually += 1 if line.isdigit(): print "#", verse_counter, math.ceil( num_verses * 0.5), num_verses, data["filename"] if verse_counter == math.ceil( num_verses * 0.5 ): # this is the first verse that should be in the new column, so let's see what's the height print text_columns_height, num_line_actually text_columns_height = BASELINE_GRID * (num_line_actually - 1) first_char = "\n" if num_line == 0: first_char = "" no_new_line = True line = u"{}{}.\t".format(first_char, line) scribus.insertText(line, -1, textbox) scribus.deselectAll() scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("num", textbox) # no character styles available #scribus.setFontSize(5, textbox) # TODO: testing only # BUG? scribus.setFont("Linux Libertine O Bold", textbox) num_chars += len(line) verse_counter += 1 else: if no_new_line: first_char = "" else: first_char = chr(28) no_new_line = False line = u"{}{}".format(first_char, line) scribus.insertText(line, -1, textbox) #scribus.deselectAll() #scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("text", textbox) num_chars += len(line) scribus.setColumnGap(5, textbox) columns = settings.get("columns", 2) scribus.setColumns(columns, textbox) if columns != 2: fit_height(textbox) else: scribus.sizeObject(new_width, text_columns_height, textbox) l, t = scribus.getPosition(textbox) scribus.moveObjectAbs(l, round(t / BASELINE_GRID) * BASELINE_GRID, textbox) if scribus.textOverflows(textbox): fit_height(textbox) # there are some cases,.. text_width, text_height = scribus.getSize(textbox) text_left, text_top = scribus.getPosition(textbox) return text_top + text_height - start_point + SPACING_SONGS, page_num
def get_style_suffix(): page_num = scribus.pageCount() style_suffix = "r" # is this really the right way? is there no shortcut provided by scribus? if page_num % 2 == 0: style_suffix = "l" return style_suffix
def run_script() : args = get_args_scribus() print('booooklet ' + str(args.booklet)) if not scribus.haveDoc(): print("No file open"); return filename = os.path.splitext(scribus.getDocName())[0] # scribus.getPageSize() # create a PDF with the original size pdf = scribus.PDFfile() pdf.file = filename + ".pdf" pdf.save() # create a pdf with the page reordered # get it to be steared by facing pages and first page left / right # it's booklet if it has facing pages and first page right # (the function are probably not in the API yet) n = scribus.pageCount() pdf = scribus.PDFfile() pdf.file = filename + "-reordered.pdf" if (n == 1) : pdf.pages = [1,1,1,1] elif (n == 2) : pdf.pages = [1,1,1,1,2,2,2,2] elif (n == 4) : if args.booklet: pdf.pages = [4,1,4,1,2,3,2,3] else: pdf.pages = [1,3,1,3,4,2,4,2] elif (n == 8) : if args.booklet: pdf.pages = [8,1,6,3,2,7,4,5] else: pdf.pages = [1,3,5,7,4,2,8,6] elif (n == 12) : if args.booklet: pdf.pages = [12, 1, 2, 11, 10, 3, 4, 9, 8, 5, 6, 7] else : pass elif (n == 16) : if args.booklet: pdf.pages = [16, 1, 14 , 3, 2, 15, 4, 13, 12, 5, 10, 7, 6, 11, 8, 9] # <- first join top/down , then staple 1/2 else: pass elif (n == 24) : if args.booklet: pass else: pdf.pages = [1,3,5,7,4,2,8,6,9,11,13,15,12,10,16,14,17,19,21,23,20,18,24,22] # mit starter cards else: print('{} are not yet supported'.format(n)) pdf.save() call_args = ['pdfnup', '--nup', '2x2', '--frame', 'false', '--no-landscape'] call_args += ['--', 'outfile', filename.replace("a6", "a4") + ".pdf"] call_args += [filename + '-reordered.pdf'] subprocess.call(call_args) os.system("pdfnup --nup 2x2 --frame false --no-landscape " + filename + "-reordered.pdf --outfile " + filename.replace("a6", "a4") + ".pdf") os.remove(pdf.file)
if not scribus.haveDoc(): scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1) sys.exit(2) charsIgnore = ["-", "–", "", " ", ".", ":", ";", ";", "?", "!", "\n", "'", "‘", "’", "," "\"", "“", "”", "\r"] button = scribus.messageBox('Confirmation', 'You should only scramble a copy of your document', scribus.ICON_WARNING, scribus.BUTTON_OK, scribus.BUTTON_CANCEL) print button if button == scribus.BUTTON_CANCEL : sys.exit(2) selectedFrame = [] textFrame = [] imageFrame = [] if scribus.selectionCount() == 0: for page in range(scribus.pageCount()) : scribus.gotoPage(page + 1) scribus.messagebarText("Processing Page "+str(page)) scribus.redrawAll() for item in scribus.getPageItems() : if (item[1] == 4): textFrame.append(item[0]) elif (item[1] == 2) : imageFrame.append(item[0]) else : for i in range(scribus.selectionCount()) : item = scribus.getSelectedObject(i) selectedFrame.append(item) if scribus.getObjectType(item) == "TextFrame" : textFrame.append(item) if scribus.getObjectType(item) == "ImageFrame" :
You must have a document open. This script checks if the document contains image frames with a broken link. If any is found, it will ask if you want to look for the correct image and then prompt for the new location of the first image. It will then check all other image frames with a broken link, and look for an image of the same name in the new location. It the image is there, the link will be replaced. You would be wise to work on a copy of the original to avoid accidentally include the wrong images. """ import scribus import os.path page_n = scribus.pageCount() item_missing = [] # create a list of items with a brokein link for page_i in range(0, page_n) : scribus.gotoPage(page_i + 1) item_list = scribus.getPageItems() #print(item_list) for item in item_list : if item[1] == 2 : image_filepath = "" image_filepath = scribus.getImageFile(item[0]) print(image_filepath) if image_filepath != "" and not os.path.isfile(image_filepath) : item_missing.append((item[0], image_filepath)) # print(item_missing)
def main(argv): scribus.setUnit(scribus.UNIT_MILLIMETERS) # get page size pagesize = scribus.getPageSize() ########################################### # size and position of the exit buttons linksize = pagesize[0] / 30 linkpos = pagesize[0] - linksize - 2 # set up exit to page pagenum = scribus.pageCount() exittopage = scribus.valueDialog( "Exit to page", "Exit buttons should go to page (1-" + str(pagenum) + ") :", "1") #error #if exittopage > pagenum: # scribus.messageBox("Error", "This page doesn't exist.") # sys.exit() # get active layer, create new layer for exit buttons, set it as active activelayer = scribus.getActiveLayer() scribus.createLayer("Exitbuttons") scribus.setActiveLayer("Exitbuttons") #progressbar max scribus.progressTotal(pagenum) # iterate through all the pages page = 1 while (page <= pagenum): #messagebar text scribus.messagebarText("Create exit buttons...") scribus.progressSet(page) scribus.gotoPage(page) # create rectangle exitrect = scribus.createRect(linkpos, 2, linksize, linksize, "exitrect" + str(page)) scribus.setFillColor("White", exitrect) # create text in rectangle exittext = scribus.createText(linkpos, 4, linksize, linksize, "exittext" + str(page)) scribus.setText("X", exittext) scribus.setFontSize(20, exittext) scribus.setTextAlignment(1, exittext) # create link annotation exitlink = scribus.createText(linkpos, 2, linksize, linksize, "exitlink" + str(page)) #setLinkAnnotation(page,x,y,["name"]) scribus.setLinkAnnotation(int(exittopage), 0, 0, exitlink) # add page number to iteration page += 1 # go back to active layer scribus.setActiveLayer(activelayer)
import scribus if not scribus.haveDoc(): scribus.messagebarText("No .") sys.exit() path = "/tmp/t/lot_forum" extensions = ['jpg', 'png', 'tif'] filenames = [f for f in os.listdir(path) if any(f.endswith(ext) for ext in extensions)] if not filenames: scribus.messagebarText("No image found.") sys.exit() page = 1 n_pages = scribus.pageCount() scribus.copyObject() scribus.loadImage(filenames[0]) filenames = filenames[1:] for filename in filenames: if page <= n_pages: scribus.gotoPage(page) else: scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) page_item = scribus.pasteObject() scribus.loadImage(filename, page_item)
You must have a document open. This script moves all images to a new layer called "Ghostlayer", the idea being that you can show/hide, print-export/not as desired. """ import scribus if scribus.haveDoc(): fantome = "Ghostlayer" scribus.createLayer(fantome) working = scribus.getActiveLayer() page = 1 pagenum = scribus.pageCount() while (page <= pagenum): scribus.gotoPage(page) scribus.setActiveLayer(working) # maybe not necessary? pageitems = scribus.getPageItems() for item in pageitems: if (item[1] == 2): imagebox = item[0] scribus.selectObject(imagebox) scribus.copyObject(imagebox) scribus.setActiveLayer(fantome) scribus.pasteObject(imagebox) scribus.deleteObject(imagebox) scribus.setActiveLayer(working) page += 1
if scribus.haveDoc(): if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Usage Error', "There is no object selected.\nPlease try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox('Scribus - Usage Error', "You have more than one object selected. \nPlease select one object and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) pagelist = scribus.valueDialog('Paste to...',"Paste to which pages? \n(page numbers, separated by white space)","1") pageslist = pagelist.split() selframe = scribus.getSelectedObject() pages = scribus.pageCount() for p in pageslist: p_no = int(p) if ((p_no > pages) or (p_no < 1)): scribus.messageBox('OOPS!', "You have a page number outside the range of pages in your document", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) scribus.copyObject(selframe) for p in pageslist: p_no = int(p) scribus.gotoPage(p_no) scribus.pasteObject(selframe) scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Finished", "Done",icon=0,button1=1) else:
def load_song(data, offset, settings): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(page_num) start_point = margin_top + offset new_width = page_width - margin_left - margin_right if not FAST: scribus.placeEPS(os.path.join(FILES, data["filename"]), 0, 0) eps = scribus.getSelectedObject() eps_width, eps_height = scribus.getSize(eps) #scribus.scaleGroup(new_width/eps_width) # slow on scribus 1.4; does something else on scribus 1.5 scribus.sizeObject(eps_width*0.86, eps_height*0.86, eps) scribus.moveObjectAbs(margin_left, start_point+SPACING_HEADLINE_SONG, eps) eps_width, eps_height = scribus.getSize(eps) else: eps_height = 0 scribus.deselectAll() textbox = scribus.createText(margin_left, start_point, new_width, 20) style_suffix = get_style_suffix() if data["composer"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["composer"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) if data["poet"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["poet"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) scribus.deselectAll() scribus.insertText(u"{}\n".format(data["name"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("headline_{}".format(style_suffix), textbox) text = data["text"] text = [t.strip() for t in text if t.strip() != ""] # TODO: exit if text == [] textbox = scribus.createText(margin_left, start_point + eps_height + SPACING_HEADLINE_SONG + SPACING_SONG_TEXT, new_width, 50) scribus.setStyle("text", textbox) # let's see how many digits are in there: num_verses = len([l for l in text if l.isdigit()]) num_chars = 0 num_line_total = len(text) num_line_actually = 0 no_new_line = False verse_counter = 0 text_columns_height = 0 # TODO: should be None for num_line, line in enumerate(text): if line.strip == "": continue num_line_actually += 1 if line.isdigit(): print "#", verse_counter, math.ceil(num_verses * 0.5), num_verses, data["filename"] if verse_counter == math.ceil(num_verses*0.5): # this is the first verse that should be in the new column, so let's see what's the height print text_columns_height, num_line_actually text_columns_height = BASELINE_GRID * (num_line_actually -1) first_char = "\n" if num_line == 0: first_char = "" no_new_line = True line = u"{}{}.\t".format(first_char, line) scribus.insertText(line, -1, textbox) scribus.deselectAll() scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("num", textbox) # no character styles available #scribus.setFontSize(5, textbox) # TODO: testing only # BUG? scribus.setFont("Linux Libertine O Bold", textbox) num_chars += len(line) verse_counter += 1 else: if no_new_line: first_char = "" else: first_char = chr(28) no_new_line = False line = u"{}{}".format(first_char, line) scribus.insertText(line, -1, textbox) #scribus.deselectAll() #scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("text", textbox) num_chars += len(line) scribus.setColumnGap(5, textbox) columns = settings.get("columns", 2) scribus.setColumns(columns, textbox) if columns != 2: fit_height(textbox) else: scribus.sizeObject(new_width, text_columns_height, textbox) l, t = scribus.getPosition(textbox) scribus.moveObjectAbs(l, round(t/BASELINE_GRID)*BASELINE_GRID, textbox) if scribus.textOverflows(textbox): fit_height(textbox) # there are some cases,.. text_width, text_height = scribus.getSize(textbox) text_left, text_top = scribus.getPosition(textbox) return text_top + text_height - start_point + SPACING_SONGS, page_num
# add a "crossed frame" for missing images for item in scribus.getAllObjects(): if scribus.getObjectType(item) == 'ImageFrame': image = scribus.getImageFile(item) if image == '': pos = scribus.getPosition(item) size = scribus.getSize(item) rectangle = scribus.createRect(pos[0], pos[1], size[0], size[1]) scribus.setFillColor('none', rectangle) scribus.setLineColor('Black', rectangle) scribus.setLineWidth(0.4, rectangle) line = scribus.createLine(pos[0], pos[1] , pos[0] + size[0], pos[1] + size[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.4, line) line = scribus.createLine(pos[0], pos[1] + size[1], pos[0] + size[0], pos[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.4, line) layer = scribus.getActiveLayer() if ('placeholder' in scribus.getLayers()) : scribus.setActiveLayer('placeholder') else: scribus.createLayer('placeholder') for page in range(1, scribus.pageCount() + 1): scribus.gotoPage(page) drawPlaceholders() scribus.setActiveLayer(layer)
# open CSV file data = getCSVdata(delim=delim, qc=qc) # Process data scribus.messagebarText("Processing "+str(nol)+" elements") scribus.progressTotal(len(data)) for row in data: scribus.messagebarText("Processing "+str(nol)+" elements") celltext = row[numcol].strip() if len(celltext)!=0: createCell(celltext, cr, cc, CARDWIDTH, CARDHEIGHT, MARGINS[0], MARGINS[2], isBlack) nol=nol+1 if cr==colstotal and cc==rowstotal: #create new page scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) cr=1 cc=1 else: if cr==colstotal: cr=1 cc=cc+1 else: cr=cr+1 scribus.progressSet(nol) scribus.messagebarText("Processed "+str(nol)+" items. ") scribus.progressReset()
for file in filename : print(file) os.system('scribus -g -py ' + sys.argv[0] + ' -- ' + file) sys.exit(1) if scribus.haveDoc(): filename = os.path.splitext(scribus.getDocName())[0] pdf = scribus.PDFfile() pdf.file = filename + ".pdf" pdf.save() pdf = scribus.PDFfile() pdf.file = filename + "-reordered.pdf" if (scribus.pageCount() == 1) : pdf.pages = [1,1,1,1] elif (scribus.pageCount() == 2) : pdf.pages = [1,1,1,1,2,2,2,2] elif (scribus.pageCount() == 4) : pdf.pages = [4,1,4,1,2,3,2,3] elif (scribus.pageCount() == 8) : pdf.pages = [8,1,6,3,2,7,4,5] elif (scribus.pageCount() == 12) : pdf.pages = [12, 1, 2, 11, 10, 3, 4, 9, 8, 5, 6, 7] elif (scribus.pageCount() == 16) : # pdf.pages = [16, 1, 2, 15, 14, 3, 4, 13, 12, 5, 6, 11, 10, 7, 8, 9] # <- probably wrong pdf.pages = [16, 1, 14 , 3, 2, 15, 4, 13, 12, 5, 10, 7, 6, 11, 8, 9] # <- first join top/down , then staple 1/2 else: print('{} are not yet supported'.format(scribus.pageCount())) pdf.save()