def prepareDocument(): """creates the new document, sets up colors """ colorList = getColorsFromDocument() spotDict = getSpotColors() scribus.statusMessage("Preparing new document...") scribus.newDocument(scribus.PAPER_A4, (15,15, 20, 20), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.PAGE_1, 0, 1) scribus.setUnit(scribus.UNIT_MILLIMETERS) #delete existing colors cols = scribus.getColorNames() for col in cols: scribus.deleteColor(col, "None") #create our new colors for color in colorList: cname=color[0] c = int(color[1]) m = int(color[2]) y = int(color[3]) k = int(color[4]) scribus.defineColorCMYK(cname, c, m, y, k ) if spotDict.has_key(cname): scribus.setSpotColor(cname, spotDict[cname]) #get the pageTitle form user and store it in PageTitle global pageTitle pageTitle=scribus.valueDialog("ColorChart by Sebastian Stetter", "Please enter document title", "Scribus COLOR CHART") drawHeaderFooter(pageTitle)
def helperNewDocument( pageWidth, pageHeight, leftMargin, topMargin, rightMargin, bottomMargin, orientation, firstPageNumber, unit, pagesType, firstPageOrder, numPages, ): # size (height, width) # margins (left, top, right, bottom) return scribus.newDocument( (pageHeight, pageWidth), (leftMargin, topMargin, rightMargin, bottomMargin), orientation, firstPageNumber, unit, pagesType, firstPageOrder, numPages, )
def helperNewDocument(pageWidth, pageHeight, leftMargin, topMargin, rightMargin, bottomMargin, orientation, firstPageNumber, unit, pagesType, firstPageOrder, numPages): # size (height, width) # margins (left, top, right, bottom) return scribus.newDocument( (pageHeight, pageWidth), (leftMargin, topMargin, rightMargin, bottomMargin), orientation, firstPageNumber, unit, pagesType, firstPageOrder, numPages)
def __init__(self): self.doc = scribus.newDocument( self.page_size, (self.margins["left"].scribus_repr( self.units), self.margins["right"].scribus_repr( self.units), self.margins["top"].scribus_repr(self.units), self.margins["bottom"].scribus_repr(self.units)), self.orientation, 1, # Number of first page self.units.scribus_repr(), scribus.FACINGPAGES, scribus.FIRSTPAGELEFT, 1 # Number of pages in document ) self.current_position = hv_position(self.margins["left"], self.margins["top"]) return
def __init__(self): self.doc = scribus.newDocument( self.page_size, ( self.margins["left"].scribus_repr(self.units), self.margins["right"].scribus_repr(self.units), self.margins["top"].scribus_repr(self.units), self.margins["bottom"].scribus_repr(self.units), ), self.orientation, 1, # Number of first page self.units.scribus_repr(), scribus.FACINGPAGES, scribus.FIRSTPAGELEFT, 1, # Number of pages in document ) self.current_position = hv_position(self.margins["left"], self.margins["top"]) return
def main(argv): """This is a documentation string. Write a description of what your code does here. You should generally put documentation strings ("docstrings") on all your Python functions.""" ######################### # YOUR CODE GOES HERE # ######################### scribus.statusMessage(str(scribus.PAPER_A4)) scribus.newDocument( scribus.PAPER_A4, #paper (MARGIN, MARGIN, MARGIN, MARGIN), #margins scribus.LANDSCAPE, #orientation 0, #firstPageNumber scribus.UNIT_MILLIMETERS, #unit scribus.PAGE_1, #pagesType 0, #firstPageOrder 0, #numPages ) scribus.createCharStyle('date1', 'Athelas Bold', 45) scribus.createCharStyle('month1', 'Athelas Bold', 16) scribus.createCharStyle('name1', 'Athelas Regular', 16) scribus.createParagraphStyle('dateL', alignment=scribus.ALIGN_LEFT, charstyle='date1') scribus.createParagraphStyle('monthL', alignment=scribus.ALIGN_LEFT, charstyle='month1') scribus.createParagraphStyle('nameL', alignment=scribus.ALIGN_LEFT, charstyle='name1') scribus.createParagraphStyle('dateR', alignment=scribus.ALIGN_RIGHT, charstyle='date1') scribus.createParagraphStyle('monthR', alignment=scribus.ALIGN_RIGHT, charstyle='month1') scribus.createParagraphStyle('nameR', alignment=scribus.ALIGN_RIGHT, charstyle='name1') masterPage() d = data.loadData() """ We want to make pamphlet (signature) of 5 x A4 papers printed from both sides with 2 weeks on each side 2sided 4imposition refer imposition.py """ def pageFn(left, right): page = scribus.newPage(-1, 'planner') i = 0 sizeDate = (20, 15) sizeMonth = (20, 7) sizeName = (290, 7) for xend, y in iterDayLines(): try: tLeftDate = left[i] posLeftDate = (xstart, y - sizeDate[1]) posLeftMonth = (xstart + sizeDate[0], y - sizeDate[1]) posLeftName = (xstart + sizeDate[0], y - sizeName[1]) tLeftName = ', '.join(d[tLeftDate.month][tLeftDate.day]) objLeftDate = scribus.createText(*posLeftDate + sizeDate) objLeftMonth = scribus.createText(*posLeftMonth + sizeMonth) objLeftName = scribus.createText(*posLeftName + sizeName) scribus.setText(tLeftDate.strftime('%d'), objLeftDate) scribus.setText(mm(tLeftDate), objLeftMonth) scribus.setText(tLeftName, objLeftName) scribus.setStyle('dateL', objLeftDate) scribus.setStyle('monthL', objLeftMonth) scribus.setStyle('nameL', objLeftName) except IndexError: pass try: posRightDate = (xend - sizeDate[0], y - sizeDate[1]) posRightMonth = (xend - sizeDate[0] - sizeMonth[0], y - sizeDate[1]) posRightName = (xend - sizeDate[0] - sizeName[0], y - sizeName[1]) tRightDate = right[i] tRightName = ', '.join(d[tRightDate.month][tRightDate.day]) objRightDate = scribus.createText(*posRightDate + sizeDate) objRightMonth = scribus.createText(*posRightMonth + sizeMonth) objRightName = scribus.createText(*posRightName + sizeName) scribus.setText(tRightDate.strftime('%d'), objRightDate) scribus.setText(mm(tRightDate), objRightMonth) scribus.setText(tRightName, objRightName) scribus.setStyle('dateR', objRightDate) scribus.setStyle('monthR', objRightMonth) scribus.setStyle('nameR', objRightName) except IndexError: pass i += 1 dates.forEachWeek(pageFn) scribus.deletePage(1)
# When 4 pics per page, coords are: (15, 42),(310, 187), (15, 388), (310, 533) # When 6 pics per page: (15, 42),(310, 42), (15, 290), (310, 290),(15,533),(310,533) # if nrimages == '4': # xpos = [15, 310, 15, 310] # ypos = [42, 187, 388, 533] # if nrimages == '6': # xpos = [15, 310, 15, 310, 15, 310] # ypos = [42, 42, 290, 290, 533, 533] # This proportion is right for photographs from my digital camera pwidth = 69.35 pheight = 94.35 imagecount = 0 # framecount = 0 if len(D) > 0: if scribus.newDocument((69.35, 94.35), (0, 0, 0, 0), scribus.PORTRAIT, 1, scribus.UNIT_MM, scribus.PAGE_1, 0, 1): while imagecount < len(D): if imagecount > 0: scribus.newPage(-1) framecount = 0 # L is the frame at the top of each page showing the directory name # L = scribus.createText(15, 20, 200, 20) # scribus.setText("Dir: " + imagedir, L) # scribus.setTextAlignment(scribus.ALIGN_LEFT, L) # scribus.setFont(labelFont, L) # scribus.setFontSize(10, L) # Here is where we're loading images into the page, four at a time, then go back up for a newPage if imagecount < len(D): f = scribus.createImage(0, 0, pwidth, pheight) scribus.loadImage(imagedir + '/' + D[imagecount], f) scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=f)
G = float(G) W = scribus.valueDialog('Book Cover Calculator', 'Enter Page Width') W = float(W) H = scribus.valueDialog('Book Cover Calculator', 'Enter Page Height') H = float(H) R = scribus.valueDialog('Book Cover Calculator', 'Enter Cover Paper thickness') R = float(R) W1 = W WW = W + 0.125 S = P / G + (R * 2) S = float(S) W = W + S + W + 0.25 H = H + 0.25 scribus.newDocument((W, H), (0.375, 0.375, 0.375, 0.375), scribus.PORTRAIT, 1, scribus.UNIT_INCHES, scribus.PAGE_1, 0, 1) scribus.setVGuides( [WW, (W1 / 2 + 0.125), (WW + S / 2), (WW + S), (WW + S + W1 / 2)])
#!/usr/bin/python # -*- coding: utf-8 -*- import sys import random import scribus # page size in inch (letter) pageX = 8.5 pageY = 11.0 lineY = 0.4125 spaceY = 0.1875 scribus.newDocument((pageX, pageY), (0.0, 0.0, 0.0, 0.0), scribus.PORTRAIT, 1, scribus.UNIT_INCHES, scribus.PAGE_1, 0, 1) scribus.defineColor("lightgray",21,21,21,21) scribus.defineColor("gray",51,51,51,51) scribus.defineColor("darkgray",91,91,91,91) l = scribus.createLine(1.0,0.0,1.0,11) scribus.setLineColor("gray", l) l = scribus.createLine(1.05,0.0,1.05,11) scribus.setLineColor("gray", l) for x in range(0,19): l = scribus.createLine(0.0,lineY-spaceY,8.5,lineY-spaceY) scribus.setLineColor("gray", l) l = scribus.createLine(0.0,lineY,8.5,lineY) scribus.setLineColor("lightgray", l) scribus.setLineStyle(scribus.LINE_DOT,l)
#add Logo hOffset=37 wOffset=5 addLogo(marginl+(roffset-1)*w+wOffset,margint+(coffset-1)*h+hOffset, isBlack) return # Main colstotal=get_multipl(WIDTH, CARDWIDTH, MARGINS[0], MARGINS[1]) rowstotal=get_multipl(HEIGHT, CARDHEIGHT, MARGINS[2], MARGINS[3]) #print "n per rows: "+ str(colstotal) + ", n per cols: " + str(rowstotal) # create a new document t=scribus.newDocument((WIDTH,HEIGHT), MARGINS, scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT,1) cr=1 cc=1 nol=0 # ask for CSV infos tstr=scribus.valueDialog('Cvs Delimiter, Quote and Column to process','Type 1 delimiter, 1 quote character and the column number (Clear for default ,"0):',';"0') if len(tstr) > 0: delim=tstr[0] else: delim=',' if len(tstr) > 1: qc=tstr[1] else: qc='"' if len(tstr) > 2: numcol=int(tstr[2]) else: numcol=0 # select black or white cards color=scribus.valueDialog('Color of the cards :','black (b) or white (w)','w')
def main (self) : # Load up all the file and record information. # Use CSV reader to build list of record dicts records = self.loadCSVData(self.dataFile) totalRecs = len(records) # Reality check first to see if we have anything to process if totalRecs <= 0 : scribus.messageBox('Not Found', 'No records found to process!') sys.exit() pageNumber = 1 recCount = 0 row = 0 pageSide = 'Odd' scribus.progressTotal(totalRecs) paIndex = {} lastName = '' firstName = '' photoFirstName = '' verseRef = '' verseText = '' # Get the page layout coordinates for this publication crds = self.getCoordinates(self.dimensions) # Make a new document to put our records on if scribus.newDocument(getattr(scribus, self.dimensions['page']['scribusPageCode']), (self.dimensions['margins']['left'], self.dimensions['margins']['right'], self.dimensions['margins']['top'], self.dimensions['margins']['bottom']), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT, 1) : self.setPageNumber(crds, pageSide, row, pageNumber) while recCount < totalRecs : # Output a new page on the first row after we have done the first page if row == 0 and recCount != 0: scribus.newPage(-1) if pageSide == 'Odd' : pageSide = 'Even' else : pageSide = 'Odd' self.setPageNumber(crds, pageSide, row, pageNumber) ########### Now set the current record in the current row ########## # Set the last name lastName = records[recCount]['NameLast'] # Adjust the NameFirst field to include the spouse if there is one if records[recCount]['Spouse'] != '' : firstName = records[recCount]['NameFirst'] + ' & ' + records[recCount]['Spouse'] else : firstName = records[recCount]['NameFirst'] # Make the photo file name photoFirstName = firstName.replace('&', '-').replace('.', '').replace(' ', '') # Set our record count for progress display and send a status message scribus.progressSet(recCount) scribus.statusMessage('Placing record ' + `recCount` + ' of ' + `totalRecs`) # Add a watermark if a string is specified if self.outputWatermark : self.addWatermark() # Put the last name element in this row nameLastBox = scribus.createText(crds[row]['nameLastXPos'], crds[row]['nameLastYPos'], crds[row]['nameLastWidth'], crds[row]['nameLastHeight']) scribus.setText(lastName, nameLastBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, nameLastBox) scribus.setTextDistances(0, 0, 0, 0, nameLastBox) scribus.setFont(self.fonts['nameLast']['bold'], nameLastBox) scribus.setFontSize(self.fonts['nameLast']['size'], nameLastBox) scribus.setTextShade(80, nameLastBox) scribus.rotateObject(90, nameLastBox) # Place the first name element in this row nameFirstBox = scribus.createText(crds[row]['nameFirstXPos'], crds[row]['nameFirstYPos'], crds[row]['nameFirstWidth'], crds[row]['nameFirstHeight']) scribus.setText(records[recCount]['Caption'], nameFirstBox) scribus.setTextAlignment(scribus.ALIGN_LEFT, nameFirstBox) scribus.setFont(self.fonts['nameFirst']['boldItalic'], nameFirstBox) scribus.setFontSize(self.fonts['nameFirst']['size'], nameFirstBox) # Place the image element in this row # We will need to do some processing on the first pass # The default output format is JPG orgImgFileName = records[recCount]['Photo'] orgImgFile = os.path.join(self.orgImgDir, orgImgFileName) baseImgFileName = lastName + '_' + photoFirstName if self.willBePngImg : ext = 'png' else : ext = 'jpg' if not self.rgbColor : imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '-gray' + '.' + ext) else : imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '.' + ext) # Process the image now if there is none if not os.path.exists(imgFile) : self.img_process.sizePic(orgImgFile, imgFile, self.maxHeight) # self.img_process.outlinePic(imgFile, imgFile) self.img_process.scalePic(imgFile, imgFile, self.imgDensity) self.img_process.addPoloroidBorder(imgFile, imgFile) # Color RGB is the default if not self.rgbColor : self.img_process.makeGray(imgFile, imgFile) # Double check the output and substitute with placeholder pic if not os.path.exists(imgFile) : imgFile = self.placeholderPic # Create the imageBox and load the picture imageBox = scribus.createImage(crds[row]['imageXPos'], crds[row]['imageYPos'], crds[row]['imageWidth'], crds[row]['imageHeight']) if os.path.isfile(imgFile) : scribus.loadImage(imgFile, imageBox) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=imageBox) # Place the country element in this row (add second one if present) countryBox = scribus.createText(crds[row]['countryXPos'], crds[row]['countryYPos'], crds[row]['countryWidth'], crds[row]['countryHeight']) countryLine = records[recCount]['Country1'] try : if records[recCount]['Country2'] != '' : countryLine = countryLine + ' & ' + records[recCount]['Country2'] except : pass scribus.setText(countryLine, countryBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, countryBox) scribus.setFont(self.fonts['text']['boldItalic'], countryBox) scribus.setFontSize(self.fonts['text']['size'], countryBox) # Place the assignment element in this row assignBox = scribus.createText(crds[row]['assignXPos'], crds[row]['assignYPos'], crds[row]['assignWidth'], crds[row]['assignHeight']) scribus.setText(self.fixText(records[recCount]['Assignment']), assignBox) # Assign style to box # scribus.createParagraphStyle(name='assignStyle', alignment=0, leftmargin=10, firstindent=-10) # scribus.setStyle('assignStyle', assignBox) # Hard formated box scribus.setTextAlignment(scribus.ALIGN_LEFT, assignBox) scribus.setFont(self.fonts['text']['italic'], assignBox) scribus.setFontSize(self.fonts['text']['size'], assignBox) scribus.setLineSpacing(self.fonts['text']['size'] + 1, assignBox) scribus.setTextDistances(4, 0, 0, 0, assignBox) # Resize the frame height and determine the difference for # placing the next frame below it assignHeightNew = self.resizeFrame(assignBox) assignHeightDiff = crds[row]['assignHeight'] - assignHeightNew # Place the verse element in this row verseYPosNew = crds[row]['verseYPos'] - assignHeightDiff verseBox = scribus.createText(crds[row]['verseXPos'], verseYPosNew, crds[row]['verseWidth'], crds[row]['verseHeight']) # The verse element may be either a Scripture verse or a prayer request # If it is Scripture, and it has a verse ref, we want to set that # seperatly so we need to do a little preprocess on the text to find # out if it has a ref. This script will only recognize references # at the end of the string that are enclosed in brackets. See the # findVerseRef() function for more details verseRef = self.findVerseRef(records[recCount]['Prayer']) if verseRef : verseText = self.removeVerseRef(self.fixText(records[recCount]['Prayer'])) scribus.setText(verseText, verseBox) else : scribus.setText(self.fixText(records[recCount]['Prayer']), verseBox) # Can't find a way to set alignment to justified using setTextAlignment() # scribus.setTextAlignment(scribus.ALIGN_LEFT, verseBox) # Because of this, we make a style which seems to work scribus.createParagraphStyle(name='vBoxStyle', alignment=3) scribus.setStyle('vBoxStyle', verseBox) scribus.setFont(self.fonts['verse']['regular'], verseBox) scribus.setFontSize(self.fonts['verse']['size'], verseBox) scribus.setLineSpacing(self.fonts['verse']['size'] + 1, verseBox) scribus.setTextDistances(4, 0, 4, 0, verseBox) if self.hyphenate : scribus.hyphenateText(verseBox) # Get the height difference in case we need to set ref box verseHeightNew = self.resizeFrame(verseBox) verseHeightDiff = crds[row]['verseHeight'] - verseHeightNew if verseRef : # Set coordinates for this box vRefBoxX = crds[row]['verseXPos'] vRefBoxY = (verseYPosNew + verseHeightNew) vRefBoxH = crds[row]['nameFirstHeight'] / 2 vRefBoxW = crds[row]['verseWidth'] verseRefBox = scribus.createText(vRefBoxX, vRefBoxY, vRefBoxW, vRefBoxH) scribus.setText(verseRef, verseRefBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, verseRefBox) scribus.setFont(self.fonts['verse']['italic'], verseRefBox) scribus.setFontSize(self.fonts['verse']['size'] - 2, verseRefBox) scribus.setLineSpacing(self.fonts['verse']['size'], verseRefBox) scribus.setTextDistances(2, 0, 0, 0, verseRefBox) # Up our counts if row >= self.dimensions['rows']['count'] - 1 : row = 0 pageNumber +=1 else : row +=1 recCount +=1 # Create the index page here # Output a new page for the index if row == 0 and recCount != 0: scribus.newPage(-1) if pageSide == 'Odd' : pageSide = 'Even' else : pageSide = 'Odd' self.setPageNumber(crds, pageSide, 0, pageNumber) # Outut the index entries at this point # for key in paIndex.keys() : # Report we are done now before we loose focus scribus.statusMessage('Process Complete!') ############################################################################### ############################## Output Results ################################# ############################################################################### # Now we will output the results to PDF if that is desired if self.makePdf : pdfExport = scribus.PDFfile() pdfExport.info = self.pdfFile pdfExport.file = self.pdfFile pdfExport.save() # View the output if set if self.makePdf and self.viewPdf : cmd = ['evince', self.pdfFile] try : subprocess.Popen(cmd) except Exception as e : result = scribus.messageBox ('View PDF command failed with: ' + str(e), scribus.BUTTON_OK)
i = random.randint(0,2) if i == 0: random_degree = 0 elif i == 1: random_degree = 120 elif i == 2: random_degree = 240 scribus.rotateObject(random_degree, bars) scribus.sentToLayer("randombars", bars) #################################################################################### # create new document (landscape) #################################################################################### if scribus.newDocument((document_width,document_height), (document_margin,document_margin,document_margin,document_margin), scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.PAGE_2, 0, 1): scribus.setMargins(0,6.35,3.175,3.175) # create some layers; so objects appear front/background scribus.createLayer("randombars") scribus.createLayer("randomcircles") scribus.createLayer("textlayer") distros.keys().sort() for distro in sorted(distros.iterkeys()): # extract the dictionary content description = distros[distro][0] filesizeiso = distros[distro][1] md5sum = distros[distro][2]
def main(): colstotal = get_multipl(WIDTH, CARDWIDTH, MARGINS[0], MARGINS[1]) rowstotal = get_multipl(HEIGHT, CARDHEIGHT, MARGINS[2], MARGINS[3]) # create a new document t = scribus.newDocument( (WIDTH, HEIGHT), MARGINS, scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT, 1, ) cr = 1 cc = 1 nol = 0 # ask for CSV infos tstr = scribus.valueDialog( 'Cvs Delimiter, Quote and Column to process', 'Type 1 delimiter, 1 quote character ' 'and the column number (Clear for default ,"0):', ';"0', ) if len(tstr) > 0: delim = tstr[0] else: delim = ',' if len(tstr) > 1: qc = tstr[1] else: qc = '"' if len(tstr) > 2: numcol = int(tstr[2]) else: numcol = 0 # select black or white cards color = scribus.valueDialog( 'Color of the cards :', 'black (b) or white (w)', 'w', ) if len(color) > 0 and 'b' == color[0]: is_black = True else: is_black = False # 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], is_black, ) 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. ") # open CSV file data = getCSVdata(delim=delim, qc=qc) # Process data scribus.messagebarText("Processing " + str(nol) + " elements") scribus.progressReset() scribus.progressTotal(len(data)) nol = 0 cr = 1 cc = cc + 2 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], is_black=True, ) 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()
scribus.createText(x, y, width, height, text_id) #scribus.text_id = scribus.createText(120, 10, 200, 20) scribus.setText(parsedtext, text_id) scribus.setFont(font, text_id) scribus.setTextColor(text_colour, text_id) scribus.setTextDistances(3*spacing, spacing, 0, spacing, text_id) scribus.sentToLayer(layer, text_id) scribus.setFontSize(fontsize, text_id) def loadimages(img_id, img_x, img_y, img_width, img_height, img_path, layer, scaletoframe): scribus.createImage(img_x, img_y, img_width, img_height, img_id) scribus.loadImage(img_path, img_id) scribus.sentToLayer(layer, img_id) # create new document (smallsquare) if scribus.newDocument((document_width,document_height), (0,6.35,3.175,3.175), scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.PAGE_2, 1, 0): i = 0 scribus.createLayer("images") scribus.createLayer("text") textframes("titel", 42.5, 50, 129.7, 17.99, "White","Black", 39, "FreeSans Bold", 0, "DIE SCHWÄRZUNG","text", 0, 0) scribus.createLine(20.2,67.5,190.2,67.5) scribus.createImage(55, 72.7, 99.5, 20.2, "logo") scribus.loadImage("handydandy_logo.eps", "logo") scribus.sentToLayer("images", "logo") scribus.setScaleImageToFrame(1,1,"logo") textframes("jahr", 81.7, 216.7, 46.1, 18.5, "White","Black", 22, "FreeSans Medium", 0, "2006 - 2012","text", 0, 0) scribus.newPage(-1)
#!/usr/bin/python # -*- coding: utf-8 -*- import sys import scribus # page size in inch (letter) pageX = 8.5 pageY = 11 scribus.defineColor("gray",21,21,21,21) scribus.newDocument((pageX, pageY), (0.0, 0.0, 0.0, 0.0), scribus.LANDSCAPE, 1, scribus.UNIT_INCHES, scribus.PAGE_1, 0, 1) #0,13 for final for x in range(0,13): #1,12,6 for final for y in range(1,12,6): rx = x ry = y for zx in range(0,2): for zy in range(0,3): a = scribus.createText(2.25+((zx+0)*(pageX/1.55)), 0.75+(zy*(pageY/3.84)), 1.25, 0.25) scribus.setFont('Arial Regular',a) scribus.setFontSize(12, a) scribus.setTextColor("gray", a) scribus.setTextAlignment(scribus.ALIGN_CENTERED, a) scribus.rotateObject(180, a); rxy = rx-ry scribus.insertText('%(rx)d - %(ry)d = %(rxy)d' % locals(), 0, a)
from __future__ import print_function, division import scribus page_width = scribus.valueDialog('Cover Assistant', 'Page width (mm)', '148') page_height = scribus.valueDialog('Cover Assistant', 'Page height (mm)', '210') spine_width = scribus.valueDialog('Cover Assistant', 'Spine width (mm)', '8') page_width = float(page_width) page_height = float(page_height) spine_width = float(spine_width) cover_width = 2 * page_width + spine_width cover_height = page_height print('Spine width: {} mm'.format(spine_width)) print('Cover width: {} mm'.format(cover_width)) print('Cover height: {} mm'.format(cover_height)) scribus.newDocument((cover_width, cover_height), (0, 0, 0, 0), scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.PAGE_1, 0, 1) vguides = [page_width, page_width + spine_width] scribus.setVGuides(vguides)
def main(self): # Load up all the file and record information. # Use CSV reader to build list of record dicts records = self.loadCSVData(self.dataFile) totalRecs = len(records) # Reality check first to see if we have anything to process if totalRecs <= 0: scribus.messageBox('Not Found', 'No records found to process!') sys.exit() pageNumber = 1 recCount = 0 row = 0 pageSide = 'Odd' scribus.progressTotal(totalRecs) paIndex = {} lastName = '' firstName = '' photoFirstName = '' verseRef = '' verseText = '' # Get the page layout coordinates for this publication crds = self.getCoordinates(self.dimensions) # Make a new document to put our records on if scribus.newDocument( getattr(scribus, self.dimensions['page']['scribusPageCode']), (self.dimensions['margins']['left'], self.dimensions['margins']['right'], self.dimensions['margins']['top'], self.dimensions['margins']['bottom']), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT, 1): self.setPageNumber(crds, pageSide, row, pageNumber) while recCount < totalRecs: # Output a new page on the first row after we have done the first page if row == 0 and recCount != 0: scribus.newPage(-1) if pageSide == 'Odd': pageSide = 'Even' else: pageSide = 'Odd' self.setPageNumber(crds, pageSide, row, pageNumber) ########### Now set the current record in the current row ########## # Set the last name lastName = records[recCount]['NameLast'] # Adjust the NameFirst field to include the spouse if there is one if records[recCount]['Spouse'] != '': firstName = records[recCount][ 'NameFirst'] + ' & ' + records[recCount]['Spouse'] else: firstName = records[recCount]['NameFirst'] # Make the photo file name photoFirstName = firstName.replace('&', '-').replace( '.', '').replace(' ', '') # Set our record count for progress display and send a status message scribus.progressSet(recCount) scribus.statusMessage('Placing record ' + ` recCount ` + ' of ' + ` totalRecs `) # Add a watermark if a string is specified if self.outputWatermark: self.addWatermark() # Put the last name element in this row nameLastBox = scribus.createText(crds[row]['nameLastXPos'], crds[row]['nameLastYPos'], crds[row]['nameLastWidth'], crds[row]['nameLastHeight']) scribus.setText(lastName, nameLastBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, nameLastBox) scribus.setTextDistances(0, 0, 0, 0, nameLastBox) scribus.setFont(self.fonts['nameLast']['bold'], nameLastBox) scribus.setFontSize(self.fonts['nameLast']['size'], nameLastBox) scribus.setTextShade(80, nameLastBox) scribus.rotateObject(90, nameLastBox) # Place the first name element in this row nameFirstBox = scribus.createText(crds[row]['nameFirstXPos'], crds[row]['nameFirstYPos'], crds[row]['nameFirstWidth'], crds[row]['nameFirstHeight']) scribus.setText(records[recCount]['Caption'], nameFirstBox) scribus.setTextAlignment(scribus.ALIGN_LEFT, nameFirstBox) scribus.setFont(self.fonts['nameFirst']['boldItalic'], nameFirstBox) scribus.setFontSize(self.fonts['nameFirst']['size'], nameFirstBox) # Place the image element in this row # We will need to do some processing on the first pass # The default output format is JPG orgImgFileName = records[recCount]['Photo'] orgImgFile = os.path.join(self.orgImgDir, orgImgFileName) baseImgFileName = lastName + '_' + photoFirstName if self.willBePngImg: ext = 'png' else: ext = 'jpg' if not self.rgbColor: imgFile = os.path.join( getattr(self, ext + 'ImgDir'), baseImgFileName + '-gray' + '.' + ext) else: imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '.' + ext) # Process the image now if there is none if not os.path.exists(imgFile): self.img_process.sizePic(orgImgFile, imgFile, self.maxHeight) # self.img_process.outlinePic(imgFile, imgFile) self.img_process.scalePic(imgFile, imgFile, self.imgDensity) self.img_process.addPoloroidBorder(imgFile, imgFile) # Color RGB is the default if not self.rgbColor: self.img_process.makeGray(imgFile, imgFile) # Double check the output and substitute with placeholder pic if not os.path.exists(imgFile): imgFile = self.placeholderPic # Create the imageBox and load the picture imageBox = scribus.createImage(crds[row]['imageXPos'], crds[row]['imageYPos'], crds[row]['imageWidth'], crds[row]['imageHeight']) if os.path.isfile(imgFile): scribus.loadImage(imgFile, imageBox) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=imageBox) # Place the country element in this row (add second one if present) countryBox = scribus.createText(crds[row]['countryXPos'], crds[row]['countryYPos'], crds[row]['countryWidth'], crds[row]['countryHeight']) countryLine = records[recCount]['Country1'] try: if records[recCount]['Country2'] != '': countryLine = countryLine + ' & ' + records[recCount][ 'Country2'] except: pass scribus.setText(countryLine, countryBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, countryBox) scribus.setFont(self.fonts['text']['boldItalic'], countryBox) scribus.setFontSize(self.fonts['text']['size'], countryBox) # Place the assignment element in this row assignBox = scribus.createText(crds[row]['assignXPos'], crds[row]['assignYPos'], crds[row]['assignWidth'], crds[row]['assignHeight']) scribus.setText(self.fixText(records[recCount]['Assignment']), assignBox) # Assign style to box # scribus.createParagraphStyle(name='assignStyle', alignment=0, leftmargin=10, firstindent=-10) # scribus.setStyle('assignStyle', assignBox) # Hard formated box scribus.setTextAlignment(scribus.ALIGN_LEFT, assignBox) scribus.setFont(self.fonts['text']['italic'], assignBox) scribus.setFontSize(self.fonts['text']['size'], assignBox) scribus.setLineSpacing(self.fonts['text']['size'] + 1, assignBox) scribus.setTextDistances(4, 0, 0, 0, assignBox) # Resize the frame height and determine the difference for # placing the next frame below it assignHeightNew = self.resizeFrame(assignBox) assignHeightDiff = crds[row]['assignHeight'] - assignHeightNew # Place the verse element in this row verseYPosNew = crds[row]['verseYPos'] - assignHeightDiff verseBox = scribus.createText(crds[row]['verseXPos'], verseYPosNew, crds[row]['verseWidth'], crds[row]['verseHeight']) # The verse element may be either a Scripture verse or a prayer request # If it is Scripture, and it has a verse ref, we want to set that # seperatly so we need to do a little preprocess on the text to find # out if it has a ref. This script will only recognize references # at the end of the string that are enclosed in brackets. See the # findVerseRef() function for more details verseRef = self.findVerseRef(records[recCount]['Prayer']) if verseRef: verseText = self.removeVerseRef( self.fixText(records[recCount]['Prayer'])) scribus.setText(verseText, verseBox) else: scribus.setText(self.fixText(records[recCount]['Prayer']), verseBox) # Can't find a way to set alignment to justified using setTextAlignment() # scribus.setTextAlignment(scribus.ALIGN_LEFT, verseBox) # Because of this, we make a style which seems to work scribus.createParagraphStyle(name='vBoxStyle', alignment=3) scribus.setStyle('vBoxStyle', verseBox) scribus.setFont(self.fonts['verse']['regular'], verseBox) scribus.setFontSize(self.fonts['verse']['size'], verseBox) scribus.setLineSpacing(self.fonts['verse']['size'] + 1, verseBox) scribus.setTextDistances(4, 0, 4, 0, verseBox) if self.hyphenate: scribus.hyphenateText(verseBox) # Get the height difference in case we need to set ref box verseHeightNew = self.resizeFrame(verseBox) verseHeightDiff = crds[row]['verseHeight'] - verseHeightNew if verseRef: # Set coordinates for this box vRefBoxX = crds[row]['verseXPos'] vRefBoxY = (verseYPosNew + verseHeightNew) vRefBoxH = crds[row]['nameFirstHeight'] / 2 vRefBoxW = crds[row]['verseWidth'] verseRefBox = scribus.createText(vRefBoxX, vRefBoxY, vRefBoxW, vRefBoxH) scribus.setText(verseRef, verseRefBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, verseRefBox) scribus.setFont(self.fonts['verse']['italic'], verseRefBox) scribus.setFontSize(self.fonts['verse']['size'] - 2, verseRefBox) scribus.setLineSpacing(self.fonts['verse']['size'], verseRefBox) scribus.setTextDistances(2, 0, 0, 0, verseRefBox) # Up our counts if row >= self.dimensions['rows']['count'] - 1: row = 0 pageNumber += 1 else: row += 1 recCount += 1 # Create the index page here # Output a new page for the index if row == 0 and recCount != 0: scribus.newPage(-1) if pageSide == 'Odd': pageSide = 'Even' else: pageSide = 'Odd' self.setPageNumber(crds, pageSide, 0, pageNumber) # Outut the index entries at this point # for key in paIndex.keys() : # Report we are done now before we loose focus scribus.statusMessage('Process Complete!') ############################################################################### ############################## Output Results ################################# ############################################################################### # Now we will output the results to PDF if that is desired if self.makePdf: pdfExport = scribus.PDFfile() pdfExport.info = self.pdfFile pdfExport.file = self.pdfFile pdfExport.save() # View the output if set if self.makePdf and self.viewPdf: cmd = ['evince', self.pdfFile] try: subprocess.Popen(cmd) except Exception as e: result = scribus.messageBox( 'View PDF command failed with: ' + str(e), scribus.BUTTON_OK)