Subversion Repositories Scribus

Rev

Rev 11894 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11780 cbradney 1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
 
11982 subik 4
"""
11780 cbradney 5
 
6
Diese Skript exportiert ein Dokument mit Beschnittrand samt Marken als PDF.
7
Hierzu ist wie folgt vorzugehen:
8
 
11982 subik 9
0) Ihr Dokument muß eine minimale Ablagefläche oberhalb, links und rechts von 20 pt und
10
   einen minimalen vertikalen Abstand zwischen den Seiten von 40 pt aufweisen
11
   (siehe Datei->Dokument einrichten->Anzeige). Das Script ist nur für Dokumente getestet,
11780 cbradney 12
   bei denen alle Seiten gleich groß sind!
11982 subik 13
 
11879 christoph 14
1) Speichern Sie Ihr Dokument.
11780 cbradney 15
 
11879 christoph 16
2) Starten Sie dieses Skript.
11780 cbradney 17
 
11879 christoph 18
3) Zuerst werden Sie nach Einheit und Größe des Beschnittrandes
11982 subik 19
   sowie die Farbnamen gefragt. Die Größe des Beschnittrandes wird automatisch verkleinert, wenn dieser
11879 christoph 20
   größer als der halbe vertikale Abstand zwischen den Seiten ist.
11780 cbradney 21
 
11982 subik 22
4) Dann werden Sie nach dem Namen eines Verzeichnisses gefragt, in dem je ein Scribus-Dokument
11879 christoph 23
   für linke und rechte Seiten abgelegt und die gedruckten Seiten abgelegt werden.
11780 cbradney 24
 
11879 christoph 25
5) Wählen Sie die Optioen für die Beschnittmarken und die Beschriftung aus.
11780 cbradney 26
 
27
 
11879 christoph 28
Sie erhalten nun für jede Seite eine PDF-Datei mit Beschnittrand und, falls gewählt, Schnittmarken, Passermarken und Hilfstext sowie einen Dateinamen aufgedruckt. Außerdem werden drei Scribus-Dateien angelegt.
11780 cbradney 29
 
11879 christoph 30
Autor: Konrad Stania mit Ergänzungen durch Gregory Pittman und Petr Vanek
11780 cbradney 31
 
32
##########################################
33
 
11982 subik 34
This script exports a document with 20 pt bleed and crop-marks as PDF.
11780 cbradney 35
 
36
USAGE:
37
 
38
 
11982 subik 39
0) Make a document with min. 20 pt scratch space above and on the right of the page and 40 pt vertical distance
11780 cbradney 40
   between the pages. The script is tested only for documents in which every page the same size.
41
 
11982 subik 42
1) Save your document
11780 cbradney 43
 
11879 christoph 44
2) Start the script.
11780 cbradney 45
 
11982 subik 46
3) Enter the unit and size of the bleed, the color names for the marks and text.
11780 cbradney 47
  The bleed will be automatically reduced if it's larger then the half vertical distance between the pages.
48
 
11879 christoph 49
4) Choose a directory where the tempory files and the output is stored.
11780 cbradney 50
 
11879 christoph 51
5) Choose whether you like to have marks and/or text.
11780 cbradney 52
 
11982 subik 53
Execution of the script will result in one pdf for each page and three Scribus-files
11780 cbradney 54
 
11879 christoph 55
Author: Konrad Stania, with additions by Gregory Pittman and Petr Vanek
11780 cbradney 56
 
57
#############################################
58
 
59
LICENSE:
60
 
61
This program is free software; you can redistribute it and/or modify
62
it under the terms of the GNU General Public License as published by
63
the Free Software Foundation; either version 2 of the License, or
64
(at your option) any later version.
65
 
66
This program is distributed in the hope that it will be useful,
67
but WITHOUT ANY WARRANTY; without even the implied warranty of
68
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
69
GNU General Public License for more details.
70
 
71
You should have received a copy of the GNU General Public License
72
along with this program; if not, write to the Free Software
73
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
74
"""
75
 
76
# Craig Bradney, Scribus Team
11879 christoph 77
# 10/3/08: Added to Scribus 1.3.3.12svn distribution "as was" from Scribus wiki for bug #6826 and improved later on by Gregory Pittman and Petr Vanek.
78
# script is GPLd
11780 cbradney 79
 
80
import sys
81
from xml.dom import minidom
82
from datetime import date
83
import random
84
import os
85
 
86
try:
87
    from scribus import *
88
except ImportError:
89
    print "This script only runs from within Scribus."
90
    sys.exit(1)
11982 subik 91
 
11780 cbradney 92
def main():
11982 subik 93
    #setRedraw(False)
94
 
95
    #the xml-interpretation with expat does not like some chars. We will have to substitute them and
11780 cbradney 96
    #change this back before going to interpret the new files with scribus
97
    #Append this list, if you encounter an expat-error concerning xml with wrong chars
98
    #We have to decide if you are using it on Win or Linux
99
 
100
    charsToChangeWin1333 = ["","","","","","","", ""]
11837 subik 101
 
102
    charsToChange = charsToChangeWin1333
11982 subik 103
    fgcolmesg = "Foreground Color for Marks\n (The script will create the color if it doesn't exist):"
104
    if (lang == "DE"):
105
        fgcolmesg = "Vordergrundfarbe für Marken\n (Das Skript erstellt die Farbe, wenn sie nicht vorhanden ist):"
106
    fgcol = valueDialog("Bleed and Marks", fgcolmesg ,"regcol")
11837 subik 107
    if fgcol == '':
108
        return
109
    try:
110
        colval = getColor(fgcol)
111
    except NotFoundError:
112
        defineColor(fgcol, 0, 0, 0, 255)
113
        colval = getColor(fgcol)
114
 
11780 cbradney 115
    defineColor("bleed_export_white_323567654", 0, 0, 0, 0)
116
    bgcol = "bleed_export_white_323567654"
117
    #bgcol = valueDialog("Bleed and Marks", "Background color for marks (script stops if color doesn't exist)\nHintergrundfarbe für Marken (Skript bricht ab, wenn Farbe nicht vorhanden):" ,"White")
118
    #olval = getColor(bgcol)
11837 subik 119
 
11780 cbradney 120
    userUnit = getUnit()
121
    setUnit(0)
122
 
123
    #deselectAll()
11982 subik 124
    baseDirmesg = "Output Directory"
125
    if (lang == "DE"):
126
        baseDirmesg = "Ausgabeverzeichnis"
127
    baseDirName = fileDialog("Bleed and Marks - " + baseDirmesg, "*","./" ,False, False, True)
11780 cbradney 128
 
11982 subik 129
    baseName = valueDialog("Bleed and Marks", "File names will begin with (prefix):", "scribus_print")
130
    baseFileName = baseDirName + baseName
11780 cbradney 131
    exportType = "pdf"
132
    UnitFakt = 1
133
    bleedVal = 20
11982 subik 134
    UnitType = "pt"
11837 subik 135
 
11982 subik 136
    UnitTypemesg = "Unit for Bleed: \npt, mm, cm, in"
137
    if (lang == "DE"):
138
        UnitTypemesg = "Maßeinheit für die Randgröße: \npt, mm, cm"
139
    UnitType = valueDialog("Bleed and Marks", UnitTypemesg, "mm")
11837 subik 140
 
11780 cbradney 141
    if UnitType == "mm":
142
        UnitFakt = 1/25.4*72
143
        bleedVal = int(20.0/72*2.54*10)
11837 subik 144
 
11780 cbradney 145
    if UnitType == "cm":
146
        UnitFakt = 1/2.54*72
147
        bleedVal = 0.1*int(20.0/72*2.54*10)
11982 subik 148
 
149
    if UnitType == "in":
150
        UnitFakt = 72
151
        bleedVal = 20.0/72
152
 
11780 cbradney 153
    if UnitType == "pt":
154
        UnitType = "pt"
155
        UnitFakt = 1
156
        bleedVal = 20
11982 subik 157
    bleedValmesg = "Size of Bleed, automatically limited\n to half of vertical gap between pages["+ UnitType +"]:"
158
    if (lang == "DE"):
159
        bleedValmesg = "Größe des Beschnittrandes, automatisch beschränkt\n auf den halben vertikalen Abstand zwischen den Seiten ["+ UnitType +"]:"
160
    bleedVal = float(valueDialog("Bleed and Marks", bleedValmesg ,'%5.3f'% bleedVal))
161
 
162
    pageTypemesg1 = "Page Type"
163
    pageTypemesg2 = "Double first right = dr, Double first left = dl,\nSingle pages = s"
164
    if (lang == "DE"):
165
        pageTypemesg1 = "Seitenart"
166
        pageTypemesg2 = "Doppelseite, erste rechts = dr, Doppelseite, erste links = dl,\nEinzelne Seiten = s"
167
    TypeOfPages = valueDialog("Bleed and Marks - " + pageTypemesg1, pageTypemesg2,"dr")
11780 cbradney 168
    #which marks can be "l", "r", "b" and defines whether left, right or both marks are printed
169
    whichMarks = "b"
170
 
171
    if TypeOfPages <> "errfind":
11982 subik 172
        printCropmesg = "Print Crop Marks: 1 = Yes, 2 = No"
173
        printRegmesg = "Print Registration Marks: 1 = Yes, 2 = No"
174
        printCBarmesg = "Print Color Bar: 1 = Yes, 2 = No"
175
    if (lang == "DE"):
176
        printCropmesg = "Drucke Schnittmarken: 1 = Ja, 2 = Nein"
177
        printRegmesg = "Drucke Paßkreuze: 1 = Ja, 2 = Nein"
178
        printCBarmesg = "Drucke Farbbalken: 1 = Ja, 2 = Nein"
11780 cbradney 179
 
11982 subik 180
    doCropMarks = int(valueDialog("Bleed and Marks", printCropmesg,"1"))
181
    doRegMarks = int(valueDialog("Bleed and Marks", printRegmesg,"1"))
182
    doColorSamples = int(valueDialog("Bleed and Marks", printCBarmesg,"1"))
11780 cbradney 183
 
11982 subik 184
    jobname = valueDialog("Bleed and Marks", "Info Text" ,"Created by Scribus")
185
    if len(jobname) > 0:
186
        doJobText = int("1")
187
    else:
188
        doJobText = int("0")
189
 
11780 cbradney 190
    #preparing the file-environment
11982 subik 191
 
11780 cbradney 192
    tmpFileName = baseDirName + "tmp.sla"
193
    rightPageName = baseDirName + "rightpage.sla"
194
    leftPageName = baseDirName + "leftpage.sla"
195
    saveDocAs(tmpFileName)
11982 subik 196
    processmesg = "Processing the document, please wait"
197
    if (lang == "DE"):
198
        processmesg = "Dokument in Bearbeitung, bitte warten"
199
    messagebarText(processmesg)
11894 subik 200
    #closeDoc()
11982 subik 201
#    messagebarText("Processing the document, please wait - Dokument in Bearbeitung, bitte warten")
11780 cbradney 202
 
203
    #Here we clean-up the xml documents from illegal characters
204
    #Here we replace \x1A \x1B \x1C etc. in the Document to prevent expat from crashing
205
    #these are stored in the list charsToChange
206
    inFile = open(tmpFileName,"r")
207
    richtig = inFile.read()
208
    inFile.close()
209
 
210
    # define an uniqe string to replace the bad chars
211
    charsToChangeMark = "__bleed_and_export_" + '%4.0f'% (10000+80000*random.random())
11982 subik 212
    while richtig.find(charsToChangeMark) > (-1) :
11780 cbradney 213
       charsToChangeMark = "__bleed_and_export_" + '%4.0f'% (10000+80000*random.random())
11982 subik 214
 
11780 cbradney 215
    # change all bad chars
216
    toChangeCounter = 1000
217
    for toChange in charsToChange:
218
        richtig = richtig.replace(toChange,charsToChangeMark +"_"+ '%4i'% toChangeCounter)
219
        toChangeCounter = toChangeCounter + 1
11982 subik 220
 
11780 cbradney 221
    # write the corrected tmp-file
222
    outFile = open(tmpFileName,"w")
223
    outFile.write(richtig)
224
    outFile.close()
11982 subik 225
 
11780 cbradney 226
    if TypeOfPages == "errfind":
227
      # this helps to find the illegal ones
228
      LineNumber = int(valueDialog("bleed_and_export.py", "Line-Zeile" ,"1"))
229
      #ColNumber = int(valueDialog("bleed_and_export.py", "Collumn-Spalte" ,"1"))
11982 subik 230
 
11780 cbradney 231
      inFile = open(tmpFileName,"r")
11982 subik 232
      for x in range(LineNumber):
11780 cbradney 233
        Zeile = inFile.readline()
234
 
235
      inFile.close()
236
      suspectList = "Dangerous chars: "
237
      Spalte = 0
238
 
11982 subik 239
      for x in Zeile:
240
        if Zeile[Spalte:Spalte+3] == "&#x":
241
          suspect = Zeile[Spalte:Spalte+6]
242
          suspectList = suspectList + suspect[0:1+suspect.find(";")] + " "
11780 cbradney 243
 
11982 subik 244
        Spalte = Spalte + 1
11780 cbradney 245
 
11982 subik 246
      suspectListmesg = "The following would be valid: &#x9, &#xa, &#xd"
247
      if (lang == "DE"):
248
           suspectListmesg = "Achtung, folgende wären gültig: &#x9, &#xa, &#xd"
249
      messageBox("Bleed and Marks", suspectList + suspectListmesg, ICON_INFORMATION)
11780 cbradney 250
 
251
 
252
    if TypeOfPages == "s" or TypeOfPages =="dr" or TypeOfPages =="dl":
253
      #Here we make the xml-operations for left pages:
254
 
255
      xmldoc = minidom.parse(tmpFileName)
256
      theDocumentNode = xmldoc.getElementsByTagName('DOCUMENT')
257
      theDocumentNodeRef = theDocumentNode[0]
258
 
259
      thePageSetSetsNodeRef = theDocumentNodeRef.getElementsByTagName('PageSets')[0].getElementsByTagName('Set')
11982 subik 260
 
11780 cbradney 261
      for xRef in thePageSetSetsNodeRef:
11982 subik 262
 
11780 cbradney 263
          if float(xRef.attributes["GapBelow"].value) <= (2 * bleedVal*UnitFakt):
11982 subik 264
 
11780 cbradney 265
              bleedVal = float(xRef.attributes["GapBelow"].value) / UnitFakt / 2
11982 subik 266
 
267
 
11780 cbradney 268
      for xRef in thePageSetSetsNodeRef:
269
          xRef.attributes["GapBelow"].value = '%5.3f'%(float(xRef.attributes["GapBelow"].value) - 2 *bleedVal*UnitFakt)
11982 subik 270
 
11780 cbradney 271
      theDocumentNodeRef.attributes["PAGEHEIGHT"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
272
      theDocumentNodeRef.attributes["PAGEWIDTH"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
273
      theDocumentNodeRef.attributes["ScratchTop"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchTop"].value) - bleedVal*UnitFakt)
274
      theDocumentNodeRef.attributes["ScratchLeft"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchLeft"].value) - bleedVal*UnitFakt)
11982 subik 275
 
11780 cbradney 276
      thePageNodeRef = theDocumentNodeRef.getElementsByTagName('PAGE')
277
      for xRef in thePageNodeRef :
278
          xRef.attributes["PAGEHEIGHT"].value =   '%5.3f'%(float(xRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
279
          xRef.attributes["PAGEWIDTH"].value =   '%5.3f'%(float(xRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
11982 subik 280
 
11780 cbradney 281
      theMasterPageNodeRef = theDocumentNodeRef.getElementsByTagName('MASTERPAGE')
11982 subik 282
 
11780 cbradney 283
      for xRef in theMasterPageNodeRef :
284
          xRef.attributes["PAGEHEIGHT"].value = '%5.3f'%(float(xRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
285
          xRef.attributes["PAGEWIDTH"].value =  '%5.3f'%(float(xRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
286
          xRef.attributes["PAGEXPOS"].value =   '%5.3f'%(float(xRef.attributes["PAGEXPOS"].value)  -  bleedVal*UnitFakt)
287
          xRef.attributes["PAGEYPOS"].value =   '%5.3f'%(float(xRef.attributes["PAGEYPOS"].value) -  bleedVal*UnitFakt)
288
 
289
      outxml  = xmldoc.toxml()
290
 
291
      #put back the bad  chars
292
      toChangeCounter = 1000
293
      for toChange in charsToChange:
294
        outxml = outxml.replace(charsToChangeMark +"_" + '%4i'% toChangeCounter, toChange)
295
        toChangeCounter = toChangeCounter + 1
296
 
297
      outFile = open(leftPageName, 'w')
298
      outFile.write(outxml[outxml.find("<SCRIBUS"):len(outxml)])
299
      outFile.close()
300
      outxml = "n"
301
 
11982 subik 302
 
11780 cbradney 303
    if TypeOfPages =="dr" or TypeOfPages =="dl":
304
       #Here we make the xml-operations for right pages of double sides documents
11982 subik 305
 
11780 cbradney 306
      theDocumentNodeRef.attributes["ScratchLeft"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchLeft"].value) - 2 * bleedVal*UnitFakt)
307
 
308
      outxml  = xmldoc.toxml()
11982 subik 309
 
11780 cbradney 310
      #put back the illegal char
11982 subik 311
 
11780 cbradney 312
      toChangeCounter = 1000
313
      for toChange in charsToChange:
314
        outxml = outxml.replace(charsToChangeMark +"_" + '%4i'% toChangeCounter, toChange)
315
        toChangeCounter = toChangeCounter + 1
316
 
317
      outFile = open(rightPageName, 'w')
318
      outFile.write(outxml[outxml.find("<SCRIBUS"):len(outxml)])
319
      outFile.close()
320
      outxml = "n"
11982 subik 321
 
322
 
11780 cbradney 323
    #From here we do the drawing and exporting to pdf
11982 subik 324
 
11780 cbradney 325
    if TypeOfPages == "dr":
326
      ##and here we open it
327
 
11982 subik 328
      openDoc(rightPageName)
329
 
330
      messagebarText(processmesg)
331
 
11780 cbradney 332
      seitenanzahl = pageCount()
333
      for xcounter in range(seitenanzahl):
334
          seitennummer = xcounter + 1
11982 subik 335
          if seitennummer%2 > 0:
11780 cbradney 336
             gotoPage(seitennummer)
337
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
338
             # draw marks etc
339
             if doColorSamples == 1:
340
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
341
             if doCropMarks == 1:
342
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
343
             if doJobText == 1:
344
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
345
             if doRegMarks == 1:
346
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
347
             # export one page
348
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
349
 
350
 
351
      saveDoc()
352
      closeDoc()
353
 
11982 subik 354
      messagebarText(processmesg)
355
 
11780 cbradney 356
      openDoc(leftPageName)
357
 
11982 subik 358
      messagebarText(processmesg)
359
 
11780 cbradney 360
      seitenanzahl = pageCount()
361
      for xcounter in range(seitenanzahl ):
362
          seitennummer = xcounter + 1
11982 subik 363
          if seitennummer%2 == 0:
11780 cbradney 364
             gotoPage(seitennummer)
365
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
366
             # draw marks etc
367
             if doColorSamples == 1:
368
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
369
             if doCropMarks == 1:
370
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
371
             if doJobText == 1:
372
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
373
             if doRegMarks == 1:
374
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
375
             # export one page
376
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
377
 
378
 
379
      saveDoc()
380
      closeDoc()
381
      os.remove(tmpFileName)
382
 
11982 subik 383
 
11780 cbradney 384
    if TypeOfPages == "s":
11982 subik 385
 
11780 cbradney 386
    ##and here we open it
11982 subik 387
 
11780 cbradney 388
      openDoc(leftPageName)
389
 
11982 subik 390
      messagebarText(processmesg)
391
 
11780 cbradney 392
      seitenanzahl = pageCount()
11982 subik 393
 
11780 cbradney 394
      for xcounter in range(seitenanzahl):
395
          seitennummer = xcounter + 1
11982 subik 396
 
11780 cbradney 397
          gotoPage(seitennummer)
398
          resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
399
          # draw marks etc
400
          if doColorSamples == 1:
401
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
402
          if doCropMarks == 1:
403
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
404
          if doJobText == 1:
405
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
406
          if doRegMarks == 1:
407
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
11982 subik 408
 
11780 cbradney 409
             # export one page
410
          dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
411
 
412
 
413
      saveDoc()
414
      #closeDoc()
415
      os.remove(tmpFileName)
416
 
417
 
418
    if TypeOfPages == "dl":
419
 
420
 
421
      ##and here we open it
422
 
11982 subik 423
      openDoc(rightPageName)
11780 cbradney 424
 
11982 subik 425
      messagebarText(processmesg)
426
 
11780 cbradney 427
      seitenanzahl = pageCount()
428
      for xcounter in range(seitenanzahl ):
429
          seitennummer = xcounter + 1
11982 subik 430
          if seitennummer%2 == 0:
11780 cbradney 431
             gotoPage(seitennummer)
432
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
433
             # draw marks etc
434
             if doColorSamples == 1:
435
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
436
             if doCropMarks == 1:
437
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
438
             if doJobText == 1:
439
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
440
             if doRegMarks == 1:
441
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
442
             # export one page
443
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
444
 
445
 
446
      saveDoc()
447
      closeDoc()
11982 subik 448
      messagebarText(processmesg)
11780 cbradney 449
      openDoc(leftPageName)
11982 subik 450
      messagebarText(processmesg)
451
 
11780 cbradney 452
      seitenanzahl = pageCount()
453
      for xcounter in range(seitenanzahl ):
454
          seitennummer = xcounter + 1
11982 subik 455
          if seitennummer%2 > 0:
11780 cbradney 456
             gotoPage(seitennummer)
457
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
458
             # draw marks etc
459
             if doColorSamples == 1:
460
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
461
             if doCropMarks == 1:
462
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
463
             if doJobText == 1:
464
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
465
             if doRegMarks == 1:
466
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
467
             # export one page
468
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
469
 
470
      saveDoc()
471
      closeDoc()
472
 
11894 subik 473
    # OK, it's ugly, but it ensures the tmp files deletion
474
    try:
475
        os.remove(tmpFileName)
476
    except OSError:
477
        pass
478
    try:
479
        os.remove(rightPageName)
480
    except OSError:
481
        pass
482
    try:
483
        os.remove(leftPageName)
484
    except OSError:
485
        pass
11780 cbradney 486
 
11894 subik 487
    setUnit(userUnit)
488
    setRedraw(True)
489
 
490
 
11780 cbradney 491
def dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt):
492
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
493
    if exportType == "pdf":
494
      pdfExport =  PDFfile()
495
      pdfExport.bleedt = bleedVal*UnitFakt
496
      pdfExport.bleedb = bleedVal*UnitFakt
497
      pdfExport.bleedl = bleedVal*UnitFakt
498
      pdfExport.bleedr = bleedVal*UnitFakt
499
      pdfExport.info = resultFileName
500
      pdfExport.pages = [seitennummer]
501
      pdfExport.file = resultFileName
502
      pdfExport.save()
11982 subik 503
 
11780 cbradney 504
   # if exportType == "ps":
505
   #   psExport = Printer()
506
   #   psExport.file = resultFileName
507
   #   psExport.copies = 1
508
   #   psExport.pages = [seitennummer]
509
   #   psExport.printer = "File"
510
   #   psExport.print()
11982 subik 511
 
11780 cbradney 512
def PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType,seitennummer):
513
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
11982 subik 514
    Pagemesg = "  Page: "
515
    Datemesg = "  Date: "
516
    if (lang == "DE"):
517
        Pagemesg = "  Seite: "
518
        Datemesg = "  Datum: "
519
    shortresultFileName = resultFileName[-23:] + Pagemesg + '%(0)05i'% {"0":seitennummer} + Datemesg +  date.today().strftime("%Y-%m-%d")
11780 cbradney 520
    pageX,pageY = getPageSize()
521
    textboxT = createText(bleedVal*UnitFakt+2, 1, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-10)
522
    setTextColor(fgcol,textboxT)
523
    setLineWidth(0,textboxT)
524
    setLineColor(bgcol,textboxT)
11982 subik 525
    setFillColor(bgcol,textboxT)
526
    insertText(shortresultFileName, 0,textboxT )
11780 cbradney 527
    setFontSize(6, textboxT)
528
    textboxB1 = createText(bleedVal*UnitFakt+2, pageY-bleedVal*UnitFakt + 8, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-9)
529
    setTextColor(fgcol,textboxB1)
530
    setLineWidth(0,textboxB1)
531
    setLineColor(bgcol,textboxB1)
11982 subik 532
    setFillColor(bgcol,textboxB1)
533
    cropmesg = ", Crop:"
534
    if (lang == "DE"):
535
        cropmesg = ", Beschnitt:"
536
    insertText("Total: " + '%5.2f'% (pageX/UnitFakt)  + "x" + '%5.2f'% (pageY/UnitFakt)+"["+UnitType+"]" + cropmesg + '%5.2f'% bleedVal+"["+UnitType+"]" + ", Prod.:" + '%5.2f'% (pageX/UnitFakt - 2 * bleedVal) + "x"+ '%5.2f'% (pageY/UnitFakt - 2 * bleedVal)+"["+UnitType+"]", 0,textboxB1 )
11780 cbradney 537
    setFontSize(6, textboxB1)
538
    setLineSpacing(8,textboxB1)
539
    textboxB2 = createText(pageX/2 + 10, pageY-bleedVal*UnitFakt + 8, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-9)
540
    setTextColor(fgcol,textboxB2)
541
    setLineWidth(0,textboxB2)
542
    setLineColor(bgcol,textboxB2)
11982 subik 543
    setFillColor(bgcol,textboxB2)
11780 cbradney 544
    insertText(jobname , 0,textboxB2 )
545
    setFontSize(6, textboxB2)
546
    setLineSpacing(8,textboxB2)
547
 
548
 
549
 
11982 subik 550
 
11780 cbradney 551
def DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt):
552
 
553
    defineColor("bleed_export_c_100",255,  0,  0,  0)
554
    defineColor("bleed_export_c__80",204,  0,  0,  0)
11982 subik 555
    defineColor("bleed_export_c__40",102,  0,  0,  0)
11780 cbradney 556
 
557
    defineColor("bleed_export_m_100",  0,255,  0,  0)
558
    defineColor("bleed_export_m__80",  0,204,  0,  0)
559
    defineColor("bleed_export_m__40",  0,102,  0,  0)
11982 subik 560
 
11780 cbradney 561
    defineColor("bleed_export_y_100",  0,  0,255,  0)
562
    defineColor("bleed_export_y__80",  0,  0,204,  0)
563
    defineColor("bleed_export_y__40",  0,  0,102,  0)
11982 subik 564
 
11780 cbradney 565
    defineColor("bleed_export_k_100",  0,  0,  0,255)
566
    defineColor("bleed_export_k__80",  0,  0,  0,204)
567
    defineColor("bleed_export_k__40",  0,  0,  0,102)
11982 subik 568
 
11780 cbradney 569
    defineColor("bleed_export_cmy50",128,128,128,  0)
11982 subik 570
 
11780 cbradney 571
    pageX,pageY = getPageSize()
572
    boxw = bleedVal*UnitFakt - 10
573
    if boxw > 20:
574
      boxw = 20
575
    FontSize = boxw/4
576
    if FontSize < 2 :
11982 subik 577
      FontSize = 2
11780 cbradney 578
    boxdist = 5
579
    boxh = ((pageY - 20 - bleedVal*UnitFakt*2 - 20)  /  13) - boxdist
580
    if boxh > boxw:
11982 subik 581
      boxh = boxw
11780 cbradney 582
    upperLeftx = pageX - boxw
583
    upperLefty = bleedVal*UnitFakt + 5
584
    gruppenListe = list()
585
    for Farbe in ["bleed_export_c_100","bleed_export_c__80","bleed_export_c__40","bleed_export_m_100","bleed_export_m__80","bleed_export_m__40","bleed_export_y_100","bleed_export_y__80","bleed_export_y__40","bleed_export_k_100","bleed_export_k__80","bleed_export_k__40","bleed_export_cmy50"]:
11982 subik 586
 
11780 cbradney 587
       if upperLefty > pageY/2 - (FontSize * 1.5 + boxh + + 7 + 15):
588
         if upperLefty < pageY/2 - 15:
589
            upperLefty = pageY/2 + 20
11982 subik 590
 
591
 
11780 cbradney 592
       tbox = createText(upperLeftx, upperLefty, boxw, FontSize * 4)
593
       insertText(Farbe[len(Farbe)-5:len(Farbe)] , 0, tbox)
594
       setFontSize(FontSize, tbox)
595
       setLineSpacing(FontSize, tbox)
596
       setTextColor("regcol",tbox)
597
       setLineWidth(0, tbox)
598
       setLineColor(bgcol, tbox)
599
       setFillColor(bgcol, tbox)
11982 subik 600
 
11780 cbradney 601
       upperLefty = upperLefty + FontSize * 1.8
602
 
603
       cbox = createRect(upperLeftx, upperLefty, boxw, boxh)
604
       setLineWidth(0, cbox)
605
       setLineColor(Farbe, cbox)
11982 subik 606
       setFillColor(Farbe, cbox)
607
 
11780 cbradney 608
       upperLefty = upperLefty + boxh + 7
11982 subik 609
 
11780 cbradney 610
       gruppenListe.append(cbox)
611
       gruppenListe.append(tbox)
11982 subik 612
 
613
 
11780 cbradney 614
    groupObjects(gruppenListe)
11982 subik 615
 
11780 cbradney 616
def DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks):
617
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
618
    pageX,pageY = getPageSize()
619
    # line widths unit pt
620
    lwb = 3.0
621
    lwf = 0.25
622
 
623
    if whichMarks == "l" or whichMarks == "b":
624
       # top left:
625
       b01 = createLine(bleedVal*UnitFakt, bleedVal*UnitFakt - 9,  bleedVal*UnitFakt, 0)
626
       b02 = createLine(0,  bleedVal*UnitFakt, bleedVal*UnitFakt -9 , bleedVal*UnitFakt)
627
       setLineWidth(lwb, b01)
628
       setLineWidth(lwb, b02)
629
       setLineColor(bgcol,b01)
630
       setLineColor(bgcol,b02)
631
       f01 = createLine(bleedVal*UnitFakt, bleedVal*UnitFakt - 9,  bleedVal*UnitFakt, 0)
632
       f02 = createLine(0,  bleedVal*UnitFakt, bleedVal*UnitFakt -9 , bleedVal*UnitFakt)
633
       setLineWidth(lwf, f01)
634
       setLineWidth(lwf, f02)
635
       setLineColor(fgcol,f01)
636
       setLineColor(fgcol,f02)
637
 
638
       # bottom left:
639
       b05 = createLine(bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,  bleedVal*UnitFakt ,pageY)
640
       b06 = createLine(0,pageY-bleedVal*UnitFakt,  bleedVal*UnitFakt -9 ,pageY-bleedVal*UnitFakt)
641
       setLineWidth(lwb, b05)
642
       setLineWidth(lwb, b06)
643
       setLineColor(bgcol,b05)
644
       setLineColor(bgcol,b06)
645
       f05 = createLine(bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,  bleedVal*UnitFakt ,pageY)
646
       f06 = createLine(0,pageY-bleedVal*UnitFakt,  bleedVal*UnitFakt -9 ,pageY-bleedVal*UnitFakt)
647
       setLineWidth(lwf, f05)
648
       setLineWidth(lwf, f06)
649
       setLineColor(fgcol,f05)
650
       setLineColor(fgcol,f06)
651
 
652
    if whichMarks == "r" or whichMarks == "b":
653
       # top right:
654
       b03 = createLine(pageX - bleedVal*UnitFakt + 9, bleedVal*UnitFakt,  pageX ,bleedVal*UnitFakt)
655
       b04 = createLine(pageX - bleedVal*UnitFakt,0,  pageX-bleedVal*UnitFakt,bleedVal*UnitFakt - 9)
656
       setLineWidth(lwb, b03)
657
       setLineWidth(lwb, b04)
658
       setLineColor(bgcol,b03)
659
       setLineColor(bgcol,b04)
660
       f03 = createLine(pageX - bleedVal*UnitFakt + 9, bleedVal*UnitFakt,  pageX ,bleedVal*UnitFakt)
661
       f04 = createLine(pageX - bleedVal*UnitFakt,0,  pageX-bleedVal*UnitFakt,bleedVal*UnitFakt - 9)
662
       setLineWidth(lwf, f03)
663
       setLineWidth(lwf, f04)
664
       setLineColor(fgcol,f03)
665
       setLineColor(fgcol,f04)
666
 
667
       # bottom rigth:
668
       b07 = createLine(pageX-bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,   pageX-bleedVal*UnitFakt,pageY)
669
       b08 = createLine(pageX,pageY-bleedVal*UnitFakt, pageX-bleedVal*UnitFakt + 9 ,pageY-bleedVal*UnitFakt)
670
       setLineWidth(lwb, b07)
671
       setLineWidth(lwb, b08)
672
       setLineColor(bgcol,b07)
673
       setLineColor(bgcol,b08)
674
       f07 = createLine(pageX-bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,   pageX-bleedVal*UnitFakt,pageY)
675
       f08 = createLine(pageX,pageY-bleedVal*UnitFakt, pageX-bleedVal*UnitFakt + 9 ,pageY-bleedVal*UnitFakt)
676
       setLineWidth(lwf, f07)
677
       setLineWidth(lwf, f08)
678
       setLineColor(fgcol,f07)
679
       setLineColor(fgcol,f08)
680
 
681
 
11982 subik 682
 
11780 cbradney 683
def DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks):
684
 
685
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
686
    pageX,pageY = getPageSize()
11982 subik 687
 
11780 cbradney 688
    if whichMarks == "l" or whichMarks == "b":
689
       # left mark:
690
       DrawOneReg(bleedVal*UnitFakt-12.5,pageY/2,bgcol,fgcol)
691
 
11982 subik 692
    if whichMarks == "r" or whichMarks == "b":
11780 cbradney 693
       # rigth mark:
694
       DrawOneReg(pageX-bleedVal*UnitFakt+12.5,pageY/2,bgcol,fgcol)
695
 
696
    # top mark:
697
    DrawOneReg(pageX/2,bleedVal*UnitFakt-12.5,bgcol,fgcol)
698
    # bottom mark:
699
    DrawOneReg(pageX/2,pageY-bleedVal*UnitFakt+12.5,bgcol,fgcol)
700
 
11982 subik 701
 
11780 cbradney 702
def DrawOneReg(centerX,centerY,bgcol,fgcol):
703
    # Diese Funktion muss in der Einheit Punkt aufgerufen werden
704
    outercircle = createEllipse(centerX-7.5,centerY-7.5 , 15, 15)
705
    middlecircle = createEllipse(centerX-5.5,centerY-5.5 , 11, 11)
706
    innercircle =  createEllipse(centerX-2.5,centerY-2.5 , 5, 5)
707
    lin01 = createLine(centerX-7.5, centerY,  centerX-2.5, centerY)
708
    lin02 = createLine(centerX+2.5, centerY,  centerX+7.5, centerY)
709
    lin03 = createLine(centerX, centerY-7.5,  centerX, centerY-2.5)
710
    lin04 = createLine(centerX, centerY+7.5,  centerX, centerY+2.5)
711
 
712
    lin05 = createLine(centerX-2.5, centerY,  centerX+2.5, centerY)
713
    lin06 = createLine(centerX, centerY-2.5,  centerX, centerY+2.5)
11982 subik 714
 
11780 cbradney 715
    # line widths in Poinzs
716
    lwb = 3.0
717
    lwf = 0.25
11982 subik 718
 
11780 cbradney 719
    setLineWidth(0,outercircle)
720
    setLineColor(bgcol,outercircle)
11982 subik 721
    setFillColor(bgcol,outercircle)
11780 cbradney 722
    setLineWidth(lwf,middlecircle)
723
    setLineColor(fgcol,middlecircle)
724
    setFillColor(bgcol,middlecircle)
725
    setLineWidth(lwf,innercircle)
726
    setLineColor(fgcol,innercircle)
727
    setFillColor(fgcol,innercircle)
728
    setLineWidth(lwf,lin01)
729
    setLineWidth(lwf,lin02)
730
    setLineWidth(lwf,lin03)
731
    setLineWidth(lwf,lin04)
732
    setLineWidth(lwf,lin05)
733
    setLineWidth(lwf,lin06)
734
    setLineColor(fgcol,lin01)
735
    setLineColor(fgcol,lin02)
736
    setLineColor(fgcol,lin03)
737
    setLineColor(fgcol,lin04)
738
    setLineColor(bgcol,lin05)
739
    setLineColor(bgcol,lin06)
740
 
11982 subik 741
 
11780 cbradney 742
if __name__ == '__main__':
11982 subik 743
    lang = valueDialog("Dialog Language - " + os.name, "Delete or alter this value to have dialogs in German" ,"English")
744
    if (lang != "English"):
745
        lang = "DE"
11780 cbradney 746
    if haveDoc():
747
        main()
748
    else:
11982 subik 749
        docerrmesg = "There must be an open document."
750
    if (lang == "DE"):
751
        docerrmesg = "Es muß ein Dokument geöffnet sein."
752
        messageBox("Bleed and Marks", docerrmesg, ICON_INFORMATION)