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 exportAll2PDF(self): self.textfile = "" self.filenames = "" # outputfile = scribus.fileDialog('Enter name of file to save to', filter='PDF Files (*.pdf);;All Files (*)') for element in self.root.iter("file"): scribus.openDoc(str(element.text)) filename = os.path.splitext(os.path.basename(element.text)) # self.filenames=self.filenames+" "+filename[0] # scribus.messageBox("Export PDF",self.filenames,icon=0,button1=1) self.textfile = "/tmp/" + filename[0] + ".pdf" # files+= self.textfile+" " self.export2PDF() self.exportWeb() scribus.closeDoc()
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 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 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 main(): familles = get_families_ascii_names() for famille in familles: for n in range(1, 7): scribus.openDoc("template.sla") items = scribus.getPageItems() change_title(famille, n, items) change_number(famille, n, items) change_family(famille, n, items) change_advice(famille, n, items) change_family_members(famille, n, items) change_flavor(famille, n, items) change_background(famille, n, items) image = scribus.ImageExport() image.type = 'PNG' image.scale = 100 image.saveAs(famille + "_" + str(n) + ".png") scribus.closeDoc()
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 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 main(argv): if not scribus.haveDoc(): sys.exit(1) thecommand="" infile=os.getcwd()+"/this-is-a-temporary-file.sla" reimposed=os.getcwd()+"/reimposed-from-laidout.sla" thecommand="laidout --command 'Import(filename=\"" \ +infile+"\", keepmystery=2)" \ +" Reimpose(orientation=landscape, paper=\"Tabloid\", imposition=\"Booklet\") " \ +" Export(filter=ScribusExportConfig(filename=\"" \ +reimposed+"\", layout=\"Papers\"))' " #print "command:\n", thecommand try: print "Creating temporary file ",infile,"..." scribus.saveDocAs(infile) except: print "Could not save as ",infile sys.exit(1) try: os.system("/home/tom/p/sourceforge/laidout/src/laidout") #os.system(thecommand) except: print "An error occured trying to run the system command:\n",thecommand sys.exit(1) scribus.closeDoc() #closes the "original" document, which has been rename to infile upon saveDocAs() scribus.openDoc(reimposed) #open the brand spanking new reimposed document #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- keep this around print "Removing temporary file ",infile,"..." os.remove(infile)
def main(argv): if not scribus.haveDoc(): sys.exit(1) thecommand = "" infile = os.getcwd() + "/this-is-a-temporary-file.sla" reimposed = os.getcwd() + "/reimposed-from-laidout.sla" thecommand="laidout --command 'Import(filename=\"" \ +infile+"\", keepmystery=2)" \ +" Reimpose(orientation=landscape, paper=\"Tabloid\", imposition=\"Booklet\") " \ +" Export(filter=ScribusExportConfig(filename=\"" \ +reimposed+"\", layout=\"Papers\"))' " #print "command:\n", thecommand try: print "Creating temporary file ", infile, "..." scribus.saveDocAs(infile) except: print "Could not save as ", infile sys.exit(1) try: os.system("/home/tom/p/sourceforge/laidout/src/laidout") #os.system(thecommand) except: print "An error occured trying to run the system command:\n", thecommand sys.exit(1) scribus.closeDoc( ) #closes the "original" document, which has been rename to infile upon saveDocAs() scribus.openDoc(reimposed) #open the brand spanking new reimposed document #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- keep this around print "Removing temporary file ", infile, "..." os.remove(infile)
def get_pages_range(sla_file): scribus.openDoc(sla_file) page_count = range(1, scribus.pageCount() + 1) scribus.closeDoc() return tuple(page_count)
page_number = args.page - 1 insert_position = 0 if args.before is True else 1 # 0 = before; 1 = after master_page = args.masterpage total_pages = get_pages_range(import_file) # Output path output_file = args.output if output_file is not None: output_file = os.path.abspath(args.output) # Importing `import_file` scribus.openDoc(base_file) scribus.importPage( import_file, total_pages, 1, insert_position, page_number ) # Applying masterpage(s) if master_page is not None: for number in range(page_number + 2, page_number + len(total_pages) + 2): scribus.applyMasterPage(master_page, number) # Either overwriting `base_file` .. if output_file is None: scribus.saveDoc() # .. or creating new `output` file (requires `--output`) else: scribus.saveDocAs(output_file) scribus.closeDoc()
def endDocument(self): """Save and close document""" self.flow() scribus.saveDocAs(self.document) scribus.closeDoc()
os.makedirs(baseDirName) else: for the_file in os.listdir(baseDirName): file_path = os.path.join(baseDirName, the_file) try: if os.path.isfile(file_path): os.unlink(file_path) except Exception, e: print e #Make Document Temporary scribus.saveDoc() scribus.saveDocAs(tmpFileName) scribus.messagebarText("Dokument in Bearbeitung, bitte warten") scribus.closeDoc() scribus.messagebarText("Dokument in Bearbeitung, bitte warten") scribus.openDoc(tmpFileName) scribus.selectText(0, 1, idtextstring) idfont = scribus.getFont(idtextstring) idfonSize = scribus.getFontSize(idtextstring) idtextcolor = scribus.getTextColor(idtextstring) idtextshade = scribus.getTextShade(idtextstring) scribus.selectText(0, 1, gertextstring) gerfont = scribus.getFont(gertextstring) gerfonSize = scribus.getFontSize(gertextstring) gertextcolor = scribus.getTextColor(gertextstring) gertextshade = scribus.getTextShade(gertextstring)
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()