def main(): # hole Pfad aus der geoeffneten Datei dateiPfad = os.path.split(scribus.getDocName())[0] # extrahiere den Dateinamen ohne Erweiterung dateiName = os.path.splitext(os.path.basename(scribus.getDocName()))[0] # pdf-Objekt erzeugen pdf = scribus.PDFfile() # PDF-Info fuer Konformitaet PDF-X[34] irgendwas reinschreiben pdf.info = "Scribus-Source file -" + dateiName + ".sla - created by Robert Johnen" # Dateiname fuer PDF-Objekt festlegen pdf.file = dateiPfad + "/" + dateiName + ".pdf" # PDF-Objekt speichern pdf.save()
def __init__(self, root): self.__dataSourceFileEntryVariable = StringVar() self.__scribusSourceFileEntryVariable = StringVar() self.__dataSeparatorEntryVariable = StringVar() self.__dataSeparatorEntryVariable.set(CONST.CSV_SEP) self.__outputDirectoryEntryVariable = StringVar() self.__outputFileNameEntryVariable = StringVar() # SLA & PDF are valid output format self.__outputFormatList = [CONST.FORMAT_PDF, CONST.FORMAT_SLA] self.__selectedOutputFormat = StringVar() self.__selectedOutputFormat.set(CONST.FORMAT_PDF) self.__keepGeneratedScribusFilesCheckboxVariable = IntVar() self.__mergeOutputCheckboxVariable = IntVar() self.__saveCheckboxVariable = IntVar() self.__fromVariable = StringVar() self.__fromVariable.set(CONST.EMPTY) self.__toVariable = StringVar() self.__toVariable.set(CONST.EMPTY) self.__root = root if scribus.haveDoc(): doc = scribus.getDocName() self.__scribusSourceFileEntryVariable.set(doc) self.__outputDirectoryEntryVariable.set(os.path.split(doc)[0]) self.__dataSourceFileEntryVariable.set( os.path.splitext(doc)[0] + ".csv")
def copyPlayer(sourceName, destinationName): if scribus.objectExists(sourceName): doc = scribus.getDocName() unit = scribus.getUnit() (PageWidth, PageHeight) = scribus.getPageSize() (iT, iI, iO, iB) = scribus.getPageMargins() NewPagepoint = PageHeight - iT - iB player = scribus.selectObject(sourceName) #Duplicate the object... scribus.duplicateObject(sourceName) x = scribus.getSelectedObject() newObjectName = str(x) size = scribus.getSize(newObjectName) scribus.moveObject(0, size[1], newObjectName) (x, y) = scribus.getPosition(newObjectName) scribus.setRedraw(1) scribus.docChanged(1) if (y + size[1] > NewPagepoint): currentPage = scribus.currentPage() scribus.newPage(-1) newPage = currentPage + 1 scribus.copyObject(newObjectName) scribus.deleteObject(newObjectName) scribus.gotoPage(newPage) scribus.pasteObject(newObjectName) scribus.moveObjectAbs(iO, iT, newObjectName) scribus.setNewName(destinationName, sourceName) scribus.setNewName(sourceName, newObjectName)
def get_image_dir(start_dir=''): if len(start_dir) == 0: start_dir = os.path.dirname(sc.getDocName()) image_dir = sc.fileDialog('Choose Folder with Images', defaultname=start_dir, isdir=True) return image_dir
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 extract_fonts(): """ Extract all fonts in the current document. """ path = scribus.getDocName() root = ET.parse(path) fonts = set() for font_node in root.findall('.//*[@FONT]'): font_name = font_node.attrib['FONT'] font_size = font_node.get('FONTSIZE', None) fonts.add((font_name, font_size)) for font_node in root.findall('.//*[@CFONT]'): font_name = font_node.attrib['CFONT'] font_size = font_node.get('CSIZE', None) fonts.add((font_name, font_size)) return [font_def(name, style) for name, style in fonts]
def store_images(image_list, move=True): """ store images in a subfolder "fotos" relative to the ddocument. image_list: list of path to images move: default move files, else copy returns: list of path to stored images """ store_dir = os.path.join(os.path.dirname(sc.getDocName()), '{}.fotos'.format(BASENAME)) if not os.path.exists(store_dir): os.mkdir(store_dir) stored_images = [] for image in image_list: tartget = os.path.join(store_dir, os.path.basename(image)) if move: os.rename(image, tartget) else: import shutil shutil.copyfile(image, tartget) stored_images.append(tartget) return stored_images
def main(argv): """The main() function disables redrawing, sets a sensible generic status bar message, and optionally sets up the progress bar. It then runs the main() function. Once everything finishes it cleans up after the create() function, making sure everything is sane before the script terminates.""" currentDoc = scribus.getDocName() try: scribus.statusMessage("Importing .csv table...") scribus.progressReset() create(argv) if scribus.haveDoc(): scribus.closeDoc() scribus.openDoc(currentDoc) finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.closeDoc() scribus.openDoc(currentDoc) scribus.statusMessage("") scribus.progressReset()
def extract(chart): """ Extract the graphic chart of the current document. """ if not scribus.haveDoc(): return try: scribus.saveDoc() if not scribus.getDocName(): raise IOError('Could not save document.') except: scribus.messageBox('Script failed', 'This script only works if you saved the document.') return colors = extract_colors() fonts = extract_fonts() for color in colors: chart.add_color(color) for font in fonts: chart.add_font(font) return chart
def main(): # habe ich ein Scribus-Dokument if scribus.haveDoc(): # dann speichere das scribus.saveDoc() # finde den Namen heraus name = scribus.getDocName() # nur den Dateinamen, ohne ext suchname = os.path.splitext(os.path.split(name)[1])[0] # frage nach erstem datensatz von = scribus.valueDialog( "Daten von", "Daten aus " + suchname + ".csv werden verarbeitet.\nBeginne bei Datensatz (keine Eingabe = von Anfang an):", "") # frage nach letztem datensatz bis = scribus.valueDialog( "Daten bis", "Daten aus " + suchname + ".csv werden verarbeitet.\nEnde bei Datensatz (keine Eingabe = bis zum letzten):", "") # starte das Bashscript fuer den Seriengenerator subprocess.call(['bash', '~/bin/scribus/meinSG', suchname, von, bis]) else: scribus.messageBox("Fehler", "kein Dokument geöffnet", scribus.ICON_CRITICAL)
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)
# Produces a PDF for the SLA passed as a parameter. # Uses the same file name and replaces the .sla extension with .pdf # # usage: # scribus -g -py to-pdf.py -- file.sla # # license: # (c) MIT Ale Rimoldi import os import scribus if scribus.haveDoc(): filename = os.path.splitext(scribus.getDocName())[0] pdf = scribus.PDFfile() pdf.file = filename + ".pdf" pdf.save() else: print("No file open")
import logging import re try: import scribus as sc except ImportError: print( 'Unable to import the scribus module. This script will only run within' ) print( 'the Python interpreter embedded in Scribus. Try Script->Execute Script.' ) sys.exit(1) IMAGEFRAMENAME = 'sffimage' BASENAME = os.path.splitext(os.path.basename(sc.getDocName()))[0] CONFIG_FILE_NAME = '{}.json'.format(BASENAME) os.chdir(os.path.dirname(sc.getDocName())) class ImageFrame: """ Image Frame Details """ name = None path = None width = 0 height = 0 offset_x = 0 offset_y = 0
## CSV list for Scribus Generator ## Finds all objects with '%VAR' and lists in a csv (Filename, Variable and type: text/image ## CSV is stored in same folder with the suffix 'Elements' ## contribution from jvr14115, https://github.com/berteh/ScribusGenerator/issues/116 ## run from within Scribus > Script > run Script import os import re import scribus Edoc = scribus.getDocName() Edoc = Edoc.replace('.sla', '') file_name = Edoc + 'Elements.csv' Edoc = Edoc.replace('Elements.csv', '') Edoc = re.search(r'(.*)/(.*)', Edoc).group(2) f = open(file_name, 'w+') f.write('Template,Element,ElementType') f.write('\n') objL = scribus.getAllObjects() for obj in objL: objT = scribus.getObjectType(obj) Evar = '' if objT == 'ImageFrame': Etype = 'image' Evar = scribus.getImageFile(obj) if objT == 'TextFrame': Etype = 'text' Evar = scribus.getAllText(obj) if '%VAR_' in Evar:
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")
import os import scribus if scribus.haveDoc(): filename = os.path.dirname( scribus.getDocName()) + "/export/" + os.path.basename( scribus.getDocName().split('.')[0]) + ".pdf" pdf = scribus.PDFfile() pdf.file = filename pdf.save() else: print("No file open")
sys.exit(1) elif frame_n > 1: scribus.messageBox('Error:', 'Please select one single frame') sys.exit(1) item = scribus.getSelectedObject(0) path_images = None filename_png = None path_png = None path_svg = None if (scribus.getObjectType(item) == 'TextFrame'): path = scribus.getAllText() if path != '': base_path = os.path.dirname(scribus.getDocName()) filename_png = os.path.join(base_path, path) elif (scribus.getObjectType(item) == 'ImageFrame'): filename_png = scribus.getImageFile() if path_png == '': filename_png = None if filename_png == None: scribus.messageBox( 'Error:', 'You need to select a text frame containing the path to the image or an image frame with an old version of the image' ) sys.exit(1) print(filename_png)
def processFile(): def frontPage(LogoPath, ChurchPath, ChurchImage, Citation, CitationLocation): #scribus.setText('Gemeindebrief DIGITAL Buxtehude',"Oben") #Line upper left corner l_line = scribus.createLine(10,10,10,33,"l_Line") scribus.setLineWidth(0.75, l_line) scribus.setLineColor("NAK-blau 100%", l_line) scribus.setLineShade("NAK-blau 100%", l_line) #Headline t_headline = scribus.createText(10,22,128,20,"t_Headline") scribus.setText("Gemeindebrief", t_headline) scribus.selectText(1, 100, t_headline) scribus.setCharacterStyle( "Erste Seite - Gemeindebrief - gross", t_headline) scribus.deselectAll() # Digital - Text t_digitalText = scribus.createText(107,27,30,7, "t_Digital") scribus.selectText(1, 100, t_digitalText) scribus.setCharacterStyle( "Erste Seite - Gemeindebrief - gross", t_digitalText) scribus.deselectAll() # Congregation - Text t_congregationText = scribus.createText(10,35.250, 70, 6, "t_Congregation") scribus.selectText(1, 100, t_congregationText) scribus.setCharacterStyle( "Erste Seite - Gemeindebrief - klein", t_congregationText) scribus.deselectAll() # Month Year t_monthYear = scribus.createText(56, 46.500, 82, 10, "t_MonthYear") scribus.selectText(1, 100, t_monthYear) scribus.setCharacterStyle( "Erste Seite - Gemeindebrief - Monat", t_monthYear) scribus.deselectAll() # Logo charitable i_charitable = scribus.createImage(10, 46, 35.5, 9, "i_NAC_charitable") scribus.loadImage(LogoPath + "Logo_NAK_karitativ_HQ.tiff", i_charitable) scribus.setImageScale(0.0613, 0.0613, i_charitable) # Church image i_churchImage = scribus.createImage(10,57,128,100,"i_Church") scribus.loadImage(ChurchPath + ChurchImage, i_churchImage) scribus.setImageScale(1, 1, i_churchImage) scribus.setImageOffset(-18.244, -0.342, i_churchImage) # Citation t_citation = scribus.createText(42.500, 162.500,95.500,4.500, "t_Citation") # OverflowCheck scribus.setText(Citation, t_citation) scribus.selectText(1, 100, t_citation) scribus.setCharacterStyle("Erste Seite - Bibelzitat - Text", t_citation) scribus.deselectAll() # Citation Location t_citationLocation = scribus.createText(42.500, 170, 95.500, 3, "t_CitationLocation") scribus.setText(CitationLocation, t_citationLocation) scribus.selectText(1, 100, t_citationLocation) scribus.setCharacterStyle( "Erste Seite - Bibelzitat - Ort", t_citationLocation) scribus.deselectAll() # NAC t_nac = scribus.createText(52.500,195,66,5,"t_NAC") scribus.setText("Neuapostolische Kirche", t_nac) scribus.selectText(1, 100, t_nac) scribus.setCharacterStyle("Erste Seite - NAK", t_nac) scribus.deselectAll() # North and east germany t_northEastGermany = scribus.createText(52.500, 195, 66, 5, "t_NorthEastGermany") scribus.setText("Nord- und Ostdeutschland", t_northEastGermany) scribus.selectText(1, 100, t_northEastGermany) scribus.setCharacterStyle( "Erste Seite - Nord- und Ostdeutschland", t_northEastGermany) scribus.deselectAll() # NAC Logo i_nacLogo = scribus.createImage(122, 184, 16, 16,"i_Logo") scribus.loadImage("L:\\GB\\Bilder\\Logos\\Logo_NAK_HQ.tif", i_nacLogo) scribus.setImageScale(0.0384, 0.0384, i_nacLogo) scribus.saveDocAs() def colors(): scribus.defineColorCMYKFloat("NAK-blau 100%", 68.0, 34.0, 0.0, 0.0) scribus.defineColorRGB("Tabelle-Hintergrund", 215, 225, 243) scribus.deleteColor("Blue") scribus.deleteColor("Cool Black") scribus.deleteColor("Cyan") scribus.deleteColor("Green") scribus.deleteColor("Magenta") scribus.deleteColor("Red") scribus.deleteColor("Registration") scribus.deleteColor("Rich Black") scribus.deleteColor("Warm Black") scribus.deleteColor("Yellow") def createCharStyle(Name, Font, FontSize, Features="", BaseLineOffset = 0, Tracking = 0): scribus.createCharStyle( Name, font=Font, fontsize=FontSize, features=Features, fillcolor="", fillshade=1.0, strokecolor="Black", strokeshade=1.0, baselineoffset=BaseLineOffset, shadowxoffset=0, shadowyoffset=0, outlinewidth=0, underlineoffset=0, underlinewidth=0, strikethruoffset=0, strikethruwidth=0, scaleh=1, scalev=1, tracking=Tracking ) def createParagraphStyle(Name, LineSpacingMode, Alignment, LeftMargin, RightMargin, GapBefore, GapAfter, FirstIndent, CharStyle, LineSpacing = 0, HasDropCap = 0, DropCapLines = 0 ): if (LineSpacingMode != 0 and HasDropCap != 0 ): scribus.createParagraphStyle( Name, linespacingmode=LineSpacingMode, alignment=Alignment, leftmargin=LeftMargin, rightmargin=RightMargin, gapbefore=GapBefore, gapafter=GapAfter, firstindent=FirstIndent, hasdropcap=HasDropCap, dropcaplines=DropCapLines, charstyle=CharStyle) if (LineSpacingMode == 0 and HasDropCap != 0): scribus.createParagraphStyle( Name, linespacingmode=LineSpacingMode, linespacing=LineSpacing, alignment=Alignment, leftmargin=LeftMargin, rightmargin=RightMargin, gapbefore=GapBefore, gapafter=GapAfter, firstindent=FirstIndent, hasdropcap=HasDropCap, dropcaplines=DropCapLines, charstyle=CharStyle) if (LineSpacingMode != 0 and HasDropCap == 0): scribus.createParagraphStyle( Name, linespacingmode=LineSpacingMode, alignment=Alignment, leftmargin=LeftMargin, rightmargin=RightMargin, gapbefore=GapBefore, gapafter=GapAfter, firstindent=FirstIndent, hasdropcap=HasDropCap, charstyle=CharStyle) if (LineSpacingMode == 0 and HasDropCap == 0): scribus.createParagraphStyle( Name, linespacingmode=LineSpacingMode, linespacing=LineSpacing, alignment=Alignment, leftmargin=LeftMargin, rightmargin=RightMargin, gapbefore=GapBefore, gapafter=GapAfter, firstindent=FirstIndent, hasdropcap=HasDropCap, charstyle=CharStyle) def processInterfaceFile(InterfaceFile): with open(InterfaceFile) as lfiInterfaceFile: larrData = json.load(lfiInterfaceFile) # Output: {'name': 'Bob', 'languages': ['English', 'Fench']} print(larrData) for larrAction in larrData: print(lstrFile) scribus.openDoc(lstrFile) lstrFilename = os.path.splitext(scribus.getDocName())[0] pdf = scribus.PDFfile() pdf.compress = True pdf.compressmtd = 1 pdf.quality = 2 pdf.file = lstrFilename+".pdf" pdf.save() scribus.closeDoc()
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) if __name__ == "__main__": CONFIGURATION = get_configuration(scribus.getDocName()) main()
sys.exit() if scribus.selectionCount() == 0: scribus.messagebarText("No frame selected.") sys.exit() if scribus.selectionCount() > 1: scribus.messagebarText("Please select one single frame.") sys.exit() master_frame = scribus.getSelectedObject() x, y = scribus.getPosition() width, height = scribus.getSize() path = scribus.fileDialog("Pick a directory", scribus.getDocName(), isdir=True) if path == '': scribus.messagebarText("No directory selected.") 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() # sorted(filenames) filenames.sort()
import os import scribus if scribus.haveDoc() : filename = os.path.splitext(scribus.getDocName())[0] pdf = scribus.PDFfile() pdf.file = filename+".pdf" pdf.version = 15 pdf.save() else : print("Error : no file open")
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 scribus.selectionCount() == 0: scribus.messagebarText("No frame selected.") sys.exit() if scribus.selectionCount() > 1: scribus.messagebarText("Please select one single frame.") sys.exit() master_frame = scribus.getSelectedObject() x,y = scribus.getPosition() width, height = scribus.getSize() path = scribus.fileDialog("Pick a directory", scribus.getDocName(), isdir = True) if path == '': scribus.messagebarText("No directory selected.") 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() # sorted(filenames) filenames.sort()
import scribus import os import glob pageNum = scribus.pageCount() print(pageNum) result = "" os.chdir(os.path.dirname(scribus.getDocName()) + "/../png") listeImages = sorted(glob.glob("*")) itemNum = 0 for i in range(1, pageNum + 1): scribus.gotoPage(i) for o in scribus.getAllObjects(): if (scribus.getObjectType(o) == "ImageFrame"): if (scribus.getSize(o)[0] >= scribus.getPageSize()[0] * 0.99): #result = result + "item:" + str(itemNum) + " page:" + str(i) + " name: " + o + "\n" + " imageFile:" + scribus.getImageFile(o) scribus.loadImage(listeImages[itemNum], o) itemNum = itemNum + 1 #scribus.messageBox("caption", result) #scribus.messageBox("listeImages", "\n".join(listeImages))