Subversion Repositories Scribus

Rev

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