Subversion Repositories Scribus

Rev

Rev 11837 | Go to most recent revision | Details | 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"]
143
    #charsToChangeLin1333 = ["UnSinnx"]
144
    if os.name == "posix":
145
      defaultSystemVersion = "lin1333"
146
    else:
147
      defaultSystemVersion = "win1333"
148
 
149
    SystemVersion = valueDialog("Bleed and Marks - OS and Scribus Version - Betriebssystem und Scribus-Version:", "OS and Scribus Version: win1333 lin1333" ,defaultSystemVersion)
150
 
151
    if SystemVersion == "lin1333":
152
      charsToChange = charsToChangeLin1333
153
    else:
154
      charsToChange = charsToChangeWin1333
155
      SystemVersion = "win1333"
156
 
157
    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")
158
    colval = getColor(fgcol)
159
    defineColor("bleed_export_white_323567654", 0, 0, 0, 0)
160
    bgcol = "bleed_export_white_323567654"
161
    #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")
162
    #olval = getColor(bgcol)
163
 
164
    userUnit = getUnit()
165
    setUnit(0)
166
 
167
    #deselectAll()
168
 
169
    baseDirName = fileDialog("Bleed and Marks - Output directory - Wahl des Ausgabeverzeichnisses", "*","./" ,False, False, True)
170
 
171
    baseFileName = baseDirName + "scribus_print"
172
    exportType = "pdf"
173
    UnitFakt = 1
174
    bleedVal = 20
175
    UnitType = "pt"    
176
 
177
 
178
    UnitType = valueDialog("Bleed and Marks", "Unit for bleed - Maßeinheit für die Randgröße \nPunkt = pt, Millimeter = mm, Zentimeter = cm " ,"mm")
179
 
180
    if UnitType == "mm":
181
        UnitFakt = 1/25.4*72
182
        bleedVal = int(20.0/72*2.54*10)
183
 
184
    if UnitType == "cm":
185
        UnitFakt = 1/2.54*72
186
        bleedVal = 0.1*int(20.0/72*2.54*10)
187
 
188
    if UnitType == "pt":
189
        UnitType = "pt"
190
        UnitFakt = 1
191
        bleedVal = 20
192
 
193
    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))
194
 
195
 
196
    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")
197
    #which marks can be "l", "r", "b" and defines whether left, right or both marks are printed
198
    whichMarks = "b"
199
 
200
    if TypeOfPages <> "errfind":
201
 
202
        doCropMarks = int(valueDialog("Bleed and Marks", "Print Crop Marks - Drucke Schnittmarken 1=Yes-Ja, 0=No-Nein" ,"1"))
203
        doRegMarks = int(valueDialog("bleed_and_export.py", "Print Registration Marks - Drucke Paßkreuze 1=Yes-Ja, 0=No-Nein" ,"1"))
204
        doColorSamples = int(valueDialog("Bleed and Marks", "Print color bar - Drucke Farbbalken 1=Yes-Ja, 0=No-Nein" ,"1"))
205
 
206
        jobname = valueDialog("Bleed and Marks", "Help Text - Hilfstext" ,"Created by Scribus")
207
        if len(jobname) > 0:
208
          doJobText = int("1")
209
        else:
210
          doJobText = int("0")
211
 
212
    #preparing the file-environment
213
 
214
    tmpFileName = baseDirName + "tmp.sla"
215
    rightPageName = baseDirName + "rightpage.sla"
216
    leftPageName = baseDirName + "leftpage.sla"
217
    saveDocAs(tmpFileName)
218
    messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
219
    closeDoc()
220
    messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
221
 
222
    #Here we clean-up the xml documents from illegal characters
223
    #Here we replace \x1A \x1B \x1C etc. in the Document to prevent expat from crashing
224
    #these are stored in the list charsToChange
225
    inFile = open(tmpFileName,"r")
226
    richtig = inFile.read()
227
    inFile.close()
228
 
229
    # define an uniqe string to replace the bad chars
230
    charsToChangeMark = "__bleed_and_export_" + '%4.0f'% (10000+80000*random.random())
231
    while richtig.find(charsToChangeMark) > (-1) :
232
       charsToChangeMark = "__bleed_and_export_" + '%4.0f'% (10000+80000*random.random())
233
 
234
    # change all bad chars
235
    toChangeCounter = 1000
236
    for toChange in charsToChange:
237
        richtig = richtig.replace(toChange,charsToChangeMark +"_"+ '%4i'% toChangeCounter)
238
        toChangeCounter = toChangeCounter + 1
239
 
240
    # write the corrected tmp-file
241
    outFile = open(tmpFileName,"w")
242
    outFile.write(richtig)
243
    outFile.close()
244
 
245
    if TypeOfPages == "errfind":
246
      # this helps to find the illegal ones
247
      LineNumber = int(valueDialog("bleed_and_export.py", "Line-Zeile" ,"1"))
248
      #ColNumber = int(valueDialog("bleed_and_export.py", "Collumn-Spalte" ,"1"))
249
 
250
      inFile = open(tmpFileName,"r")
251
      for x in range(LineNumber):
252
        Zeile = inFile.readline()
253
 
254
      inFile.close()
255
      suspectList = "Dangerous chars: "
256
      Spalte = 0
257
 
258
      if SystemVersion == "win1333":
259
 
260
        for x in Zeile:
261
           if Zeile[Spalte:Spalte+3] == "&#x":
262
             suspect = Zeile[Spalte:Spalte+6]
263
             suspectList = suspectList + suspect[0:1+suspect.find(";")] + " "
264
 
265
           Spalte = Spalte + 1
266
 
267
 
268
        messageBox("Bleed and Marks", suspectList + "The following would be valid - Achtung, folgende wären gültig: &#x9, &#xa, &#xd" , ICON_INFORMATION)
269
 
270
      if SystemVersion == "lin1333":
271
        spalte = 0
272
        for x in Zeile:
273
           if ord(Zeile[Spalte]) < ord("\x1f"):
274
 
275
             suspect = " "'%x'% ord(Zeile[Spalte])
276
             suspectList = suspectList + suspect
277
 
278
           Spalte = Spalte + 1
279
 
280
 
281
        messageBox("Bleed and Marks", suspectList + "The following would be valid - Achtung, folgende wären gültig: 9, a, d"  , ICON_INFORMATION)
282
 
283
 
284
 
285
 
286
 
287
    if TypeOfPages == "s" or TypeOfPages =="dr" or TypeOfPages =="dl":
288
      #Here we make the xml-operations for left pages:
289
 
290
      xmldoc = minidom.parse(tmpFileName)
291
      theDocumentNode = xmldoc.getElementsByTagName('DOCUMENT')
292
      theDocumentNodeRef = theDocumentNode[0]
293
 
294
      thePageSetSetsNodeRef = theDocumentNodeRef.getElementsByTagName('PageSets')[0].getElementsByTagName('Set')
295
 
296
      for xRef in thePageSetSetsNodeRef:
297
 
298
          if float(xRef.attributes["GapBelow"].value) <= (2 * bleedVal*UnitFakt):
299
 
300
              bleedVal = float(xRef.attributes["GapBelow"].value) / UnitFakt / 2
301
 
302
 
303
      for xRef in thePageSetSetsNodeRef:
304
          xRef.attributes["GapBelow"].value = '%5.3f'%(float(xRef.attributes["GapBelow"].value) - 2 *bleedVal*UnitFakt)
305
 
306
      theDocumentNodeRef.attributes["PAGEHEIGHT"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
307
      theDocumentNodeRef.attributes["PAGEWIDTH"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
308
      theDocumentNodeRef.attributes["ScratchTop"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchTop"].value) - bleedVal*UnitFakt)
309
      theDocumentNodeRef.attributes["ScratchLeft"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchLeft"].value) - bleedVal*UnitFakt)
310
 
311
      thePageNodeRef = theDocumentNodeRef.getElementsByTagName('PAGE')
312
      for xRef in thePageNodeRef :
313
          xRef.attributes["PAGEHEIGHT"].value =   '%5.3f'%(float(xRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
314
          xRef.attributes["PAGEWIDTH"].value =   '%5.3f'%(float(xRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
315
 
316
      theMasterPageNodeRef = theDocumentNodeRef.getElementsByTagName('MASTERPAGE')
317
 
318
      for xRef in theMasterPageNodeRef :
319
          xRef.attributes["PAGEHEIGHT"].value = '%5.3f'%(float(xRef.attributes["PAGEHEIGHT"].value) + 2 * bleedVal*UnitFakt)
320
          xRef.attributes["PAGEWIDTH"].value =  '%5.3f'%(float(xRef.attributes["PAGEWIDTH"].value) + 2 * bleedVal*UnitFakt)
321
          xRef.attributes["PAGEXPOS"].value =   '%5.3f'%(float(xRef.attributes["PAGEXPOS"].value)  -  bleedVal*UnitFakt)
322
          xRef.attributes["PAGEYPOS"].value =   '%5.3f'%(float(xRef.attributes["PAGEYPOS"].value) -  bleedVal*UnitFakt)
323
 
324
      outxml  = xmldoc.toxml()
325
 
326
      #put back the bad  chars
327
      toChangeCounter = 1000
328
      for toChange in charsToChange:
329
        outxml = outxml.replace(charsToChangeMark +"_" + '%4i'% toChangeCounter, toChange)
330
        toChangeCounter = toChangeCounter + 1
331
 
332
      outFile = open(leftPageName, 'w')
333
      outFile.write(outxml[outxml.find("<SCRIBUS"):len(outxml)])
334
      outFile.close()
335
      outxml = "n"
336
 
337
 
338
    if TypeOfPages =="dr" or TypeOfPages =="dl":
339
       #Here we make the xml-operations for right pages of double sides documents
340
 
341
      theDocumentNodeRef.attributes["ScratchLeft"].value =  '%5.3f'%(float(theDocumentNodeRef.attributes["ScratchLeft"].value) - 2 * bleedVal*UnitFakt)
342
 
343
      outxml  = xmldoc.toxml()
344
 
345
      #put back the illegal char
346
 
347
      toChangeCounter = 1000
348
      for toChange in charsToChange:
349
        outxml = outxml.replace(charsToChangeMark +"_" + '%4i'% toChangeCounter, toChange)
350
        toChangeCounter = toChangeCounter + 1
351
 
352
      outFile = open(rightPageName, 'w')
353
      outFile.write(outxml[outxml.find("<SCRIBUS"):len(outxml)])
354
      outFile.close()
355
      outxml = "n"
356
 
357
 
358
    #From here we do the drawing and exporting to pdf
359
 
360
    if TypeOfPages == "dr":
361
      ##and here we open it
362
 
363
      openDoc(rightPageName)
364
 
365
      messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
366
 
367
      seitenanzahl = pageCount()
368
      for xcounter in range(seitenanzahl):
369
          seitennummer = xcounter + 1
370
          if seitennummer%2 > 0:  
371
             gotoPage(seitennummer)
372
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
373
             # draw marks etc
374
             if doColorSamples == 1:
375
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
376
             if doCropMarks == 1:
377
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
378
             if doJobText == 1:
379
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
380
             if doRegMarks == 1:
381
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
382
             # export one page
383
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
384
 
385
 
386
      saveDoc()
387
      closeDoc()
388
 
389
      messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
390
 
391
      openDoc(leftPageName)
392
 
393
      messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
394
 
395
      seitenanzahl = pageCount()
396
      for xcounter in range(seitenanzahl ):
397
          seitennummer = xcounter + 1
398
          if seitennummer%2 == 0:  
399
             gotoPage(seitennummer)
400
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
401
             # draw marks etc
402
             if doColorSamples == 1:
403
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
404
             if doCropMarks == 1:
405
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
406
             if doJobText == 1:
407
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
408
             if doRegMarks == 1:
409
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
410
             # export one page
411
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
412
 
413
 
414
      saveDoc()
415
      closeDoc()
416
      os.remove(tmpFileName)
417
 
418
 
419
    if TypeOfPages == "s":
420
 
421
    ##and here we open it
422
 
423
      openDoc(leftPageName)
424
 
425
      messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
426
 
427
      seitenanzahl = pageCount()
428
 
429
      for xcounter in range(seitenanzahl):
430
          seitennummer = xcounter + 1
431
 
432
          gotoPage(seitennummer)
433
          resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
434
          # draw marks etc
435
          if doColorSamples == 1:
436
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
437
          if doCropMarks == 1:
438
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
439
          if doJobText == 1:
440
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
441
          if doRegMarks == 1:
442
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
443
 
444
             # export one page
445
          dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
446
 
447
 
448
      saveDoc()
449
      #closeDoc()
450
      os.remove(tmpFileName)
451
 
452
 
453
    if TypeOfPages == "dl":
454
 
455
 
456
      ##and here we open it
457
 
458
      openDoc(rightPageName)
459
 
460
      messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
461
 
462
      seitenanzahl = pageCount()
463
      for xcounter in range(seitenanzahl ):
464
          seitennummer = xcounter + 1
465
          if seitennummer%2 == 0:  
466
             gotoPage(seitennummer)
467
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
468
             # draw marks etc
469
             if doColorSamples == 1:
470
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
471
             if doCropMarks == 1:
472
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
473
             if doJobText == 1:
474
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
475
             if doRegMarks == 1:
476
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
477
             # export one page
478
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
479
 
480
 
481
      saveDoc()
482
      closeDoc()
483
      messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
484
      openDoc(leftPageName)
485
      messagebarText("Processing the Document, please wait - Dokument in Bearbeitung, bitte warten")
486
 
487
      seitenanzahl = pageCount()
488
      for xcounter in range(seitenanzahl ):
489
          seitennummer = xcounter + 1
490
          if seitennummer%2 > 0:  
491
             gotoPage(seitennummer)
492
             resultFileName = baseFileName + '_%(0)05i'% {"0":seitennummer} + "." + exportType
493
             # draw marks etc
494
             if doColorSamples == 1:
495
                DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt)
496
             if doCropMarks == 1:
497
                DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
498
             if doJobText == 1:
499
                PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType, seitennummer)
500
             if doRegMarks == 1:
501
                DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks)
502
             # export one page
503
             dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt)
504
 
505
      saveDoc()
506
      closeDoc()
507
      os.remove(tmpFileName)
508
 
509
 
510
    #setUnit(userUnit)
511
    #setRedraw(True) 
512
 
513
def dotheExport(exportType,resultFileName,seitennummer,bleedVal,UnitFakt):
514
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
515
    if exportType == "pdf":
516
      pdfExport =  PDFfile()
517
      pdfExport.bleedt = bleedVal*UnitFakt
518
      pdfExport.bleedb = bleedVal*UnitFakt
519
      pdfExport.bleedl = bleedVal*UnitFakt
520
      pdfExport.bleedr = bleedVal*UnitFakt
521
      pdfExport.info = resultFileName
522
      pdfExport.pages = [seitennummer]
523
      pdfExport.file = resultFileName
524
      pdfExport.save()
525
 
526
   # if exportType == "ps":
527
   #   psExport = Printer()
528
   #   psExport.file = resultFileName
529
   #   psExport.copies = 1
530
   #   psExport.pages = [seitennummer]
531
   #   psExport.printer = "File"
532
   #   psExport.print()
533
 
534
def PrintJobName(jobname, resultFileName, bleedVal,bgcol,fgcol,UnitFakt,UnitType,seitennummer):
535
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
536
 
537
    shortresultFileName = resultFileName[-23:] + "  Page-Seite: " + '%(0)05i'% {"0":seitennummer} + "  Date-Datum: " +  date.today().strftime("%Y-%m-%d")
538
    pageX,pageY = getPageSize()
539
    textboxT = createText(bleedVal*UnitFakt+2, 1, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-10)
540
    setTextColor(fgcol,textboxT)
541
    setLineWidth(0,textboxT)
542
    setLineColor(bgcol,textboxT)
543
    setFillColor(bgcol,textboxT)
544
    insertText(shortresultFileName, 0,textboxT )
545
    setFontSize(6, textboxT)
546
    textboxB1 = createText(bleedVal*UnitFakt+2, pageY-bleedVal*UnitFakt + 8, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-9)
547
    setTextColor(fgcol,textboxB1)
548
    setLineWidth(0,textboxB1)
549
    setLineColor(bgcol,textboxB1)
550
    setFillColor(bgcol,textboxB1)
551
    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 )
552
    setFontSize(6, textboxB1)
553
    setLineSpacing(8,textboxB1)
554
    textboxB2 = createText(pageX/2 + 10, pageY-bleedVal*UnitFakt + 8, pageX/2 - 12 - bleedVal*UnitFakt, bleedVal*UnitFakt-9)
555
    setTextColor(fgcol,textboxB2)
556
    setLineWidth(0,textboxB2)
557
    setLineColor(bgcol,textboxB2)
558
    setFillColor(bgcol,textboxB2)
559
    insertText(jobname , 0,textboxB2 )
560
    setFontSize(6, textboxB2)
561
    setLineSpacing(8,textboxB2)
562
 
563
 
564
 
565
 
566
def DrawColorSamples(bleedVal,bgcol,fgcol,UnitFakt):
567
 
568
    defineColor("bleed_export_c_100",255,  0,  0,  0)
569
    defineColor("bleed_export_c__80",204,  0,  0,  0)
570
    defineColor("bleed_export_c__40",102,  0,  0,  0)    
571
 
572
    defineColor("bleed_export_m_100",  0,255,  0,  0)
573
    defineColor("bleed_export_m__80",  0,204,  0,  0)
574
    defineColor("bleed_export_m__40",  0,102,  0,  0)
575
 
576
    defineColor("bleed_export_y_100",  0,  0,255,  0)
577
    defineColor("bleed_export_y__80",  0,  0,204,  0)
578
    defineColor("bleed_export_y__40",  0,  0,102,  0)
579
 
580
    defineColor("bleed_export_k_100",  0,  0,  0,255)
581
    defineColor("bleed_export_k__80",  0,  0,  0,204)
582
    defineColor("bleed_export_k__40",  0,  0,  0,102)
583
 
584
    defineColor("bleed_export_cmy50",128,128,128,  0)
585
 
586
    pageX,pageY = getPageSize()
587
    boxw = bleedVal*UnitFakt - 10
588
    if boxw > 20:
589
      boxw = 20
590
    FontSize = boxw/4
591
    if FontSize < 2 :
592
      FontSize = 2
593
    boxdist = 5
594
    boxh = ((pageY - 20 - bleedVal*UnitFakt*2 - 20)  /  13) - boxdist
595
    if boxh > boxw:
596
      boxh = boxw
597
    upperLeftx = pageX - boxw
598
    upperLefty = bleedVal*UnitFakt + 5
599
    gruppenListe = list()
600
    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"]:
601
 
602
       if upperLefty > pageY/2 - (FontSize * 1.5 + boxh + + 7 + 15):
603
         if upperLefty < pageY/2 - 15:
604
            upperLefty = pageY/2 + 20
605
 
606
 
607
       tbox = createText(upperLeftx, upperLefty, boxw, FontSize * 4)
608
       insertText(Farbe[len(Farbe)-5:len(Farbe)] , 0, tbox)
609
       setFontSize(FontSize, tbox)
610
       setLineSpacing(FontSize, tbox)
611
       setTextColor("regcol",tbox)
612
       setLineWidth(0, tbox)
613
       setLineColor(bgcol, tbox)
614
       setFillColor(bgcol, tbox)
615
 
616
       upperLefty = upperLefty + FontSize * 1.8
617
 
618
       cbox = createRect(upperLeftx, upperLefty, boxw, boxh)
619
       setLineWidth(0, cbox)
620
       setLineColor(Farbe, cbox)
621
       setFillColor(Farbe, cbox)      
622
 
623
       upperLefty = upperLefty + boxh + 7
624
 
625
       gruppenListe.append(cbox)
626
       gruppenListe.append(tbox)
627
 
628
 
629
    groupObjects(gruppenListe)
630
 
631
def DrawCropMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks):
632
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
633
    pageX,pageY = getPageSize()
634
    # line widths unit pt
635
    lwb = 3.0
636
    lwf = 0.25
637
 
638
    if whichMarks == "l" or whichMarks == "b":
639
       # top left:
640
       b01 = createLine(bleedVal*UnitFakt, bleedVal*UnitFakt - 9,  bleedVal*UnitFakt, 0)
641
       b02 = createLine(0,  bleedVal*UnitFakt, bleedVal*UnitFakt -9 , bleedVal*UnitFakt)
642
       setLineWidth(lwb, b01)
643
       setLineWidth(lwb, b02)
644
       setLineColor(bgcol,b01)
645
       setLineColor(bgcol,b02)
646
       f01 = createLine(bleedVal*UnitFakt, bleedVal*UnitFakt - 9,  bleedVal*UnitFakt, 0)
647
       f02 = createLine(0,  bleedVal*UnitFakt, bleedVal*UnitFakt -9 , bleedVal*UnitFakt)
648
       setLineWidth(lwf, f01)
649
       setLineWidth(lwf, f02)
650
       setLineColor(fgcol,f01)
651
       setLineColor(fgcol,f02)
652
 
653
       # bottom left:
654
       b05 = createLine(bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,  bleedVal*UnitFakt ,pageY)
655
       b06 = createLine(0,pageY-bleedVal*UnitFakt,  bleedVal*UnitFakt -9 ,pageY-bleedVal*UnitFakt)
656
       setLineWidth(lwb, b05)
657
       setLineWidth(lwb, b06)
658
       setLineColor(bgcol,b05)
659
       setLineColor(bgcol,b06)
660
       f05 = createLine(bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,  bleedVal*UnitFakt ,pageY)
661
       f06 = createLine(0,pageY-bleedVal*UnitFakt,  bleedVal*UnitFakt -9 ,pageY-bleedVal*UnitFakt)
662
       setLineWidth(lwf, f05)
663
       setLineWidth(lwf, f06)
664
       setLineColor(fgcol,f05)
665
       setLineColor(fgcol,f06)
666
 
667
    if whichMarks == "r" or whichMarks == "b":
668
       # top right:
669
       b03 = createLine(pageX - bleedVal*UnitFakt + 9, bleedVal*UnitFakt,  pageX ,bleedVal*UnitFakt)
670
       b04 = createLine(pageX - bleedVal*UnitFakt,0,  pageX-bleedVal*UnitFakt,bleedVal*UnitFakt - 9)
671
       setLineWidth(lwb, b03)
672
       setLineWidth(lwb, b04)
673
       setLineColor(bgcol,b03)
674
       setLineColor(bgcol,b04)
675
       f03 = createLine(pageX - bleedVal*UnitFakt + 9, bleedVal*UnitFakt,  pageX ,bleedVal*UnitFakt)
676
       f04 = createLine(pageX - bleedVal*UnitFakt,0,  pageX-bleedVal*UnitFakt,bleedVal*UnitFakt - 9)
677
       setLineWidth(lwf, f03)
678
       setLineWidth(lwf, f04)
679
       setLineColor(fgcol,f03)
680
       setLineColor(fgcol,f04)
681
 
682
       # bottom rigth:
683
       b07 = createLine(pageX-bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,   pageX-bleedVal*UnitFakt,pageY)
684
       b08 = createLine(pageX,pageY-bleedVal*UnitFakt, pageX-bleedVal*UnitFakt + 9 ,pageY-bleedVal*UnitFakt)
685
       setLineWidth(lwb, b07)
686
       setLineWidth(lwb, b08)
687
       setLineColor(bgcol,b07)
688
       setLineColor(bgcol,b08)
689
       f07 = createLine(pageX-bleedVal*UnitFakt ,pageY-bleedVal*UnitFakt + 9 ,   pageX-bleedVal*UnitFakt,pageY)
690
       f08 = createLine(pageX,pageY-bleedVal*UnitFakt, pageX-bleedVal*UnitFakt + 9 ,pageY-bleedVal*UnitFakt)
691
       setLineWidth(lwf, f07)
692
       setLineWidth(lwf, f08)
693
       setLineColor(fgcol,f07)
694
       setLineColor(fgcol,f08)
695
 
696
 
697
 
698
def DrawRegMarks(bleedVal,bgcol,fgcol,UnitFakt,whichMarks):
699
 
700
    # Die Dimension der Eingabewerte fuer bleedValue ist in der jeweiligen Einheit
701
    pageX,pageY = getPageSize()
702
 
703
    if whichMarks == "l" or whichMarks == "b":
704
       # left mark:
705
       DrawOneReg(bleedVal*UnitFakt-12.5,pageY/2,bgcol,fgcol)
706
 
707
    if whichMarks == "r" or whichMarks == "b":    
708
       # rigth mark:
709
       DrawOneReg(pageX-bleedVal*UnitFakt+12.5,pageY/2,bgcol,fgcol)
710
 
711
    # top mark:
712
    DrawOneReg(pageX/2,bleedVal*UnitFakt-12.5,bgcol,fgcol)
713
    # bottom mark:
714
    DrawOneReg(pageX/2,pageY-bleedVal*UnitFakt+12.5,bgcol,fgcol)
715
 
716
 
717
def DrawOneReg(centerX,centerY,bgcol,fgcol):
718
    # Diese Funktion muss in der Einheit Punkt aufgerufen werden
719
    outercircle = createEllipse(centerX-7.5,centerY-7.5 , 15, 15)
720
    middlecircle = createEllipse(centerX-5.5,centerY-5.5 , 11, 11)
721
    innercircle =  createEllipse(centerX-2.5,centerY-2.5 , 5, 5)
722
    lin01 = createLine(centerX-7.5, centerY,  centerX-2.5, centerY)
723
    lin02 = createLine(centerX+2.5, centerY,  centerX+7.5, centerY)
724
    lin03 = createLine(centerX, centerY-7.5,  centerX, centerY-2.5)
725
    lin04 = createLine(centerX, centerY+7.5,  centerX, centerY+2.5)
726
 
727
    lin05 = createLine(centerX-2.5, centerY,  centerX+2.5, centerY)
728
    lin06 = createLine(centerX, centerY-2.5,  centerX, centerY+2.5)
729
 
730
    # line widths in Poinzs
731
    lwb = 3.0
732
    lwf = 0.25
733
 
734
    setLineWidth(0,outercircle)
735
    setLineColor(bgcol,outercircle)
736
    setFillColor(bgcol,outercircle)
737
    setLineWidth(lwf,middlecircle)
738
    setLineColor(fgcol,middlecircle)
739
    setFillColor(bgcol,middlecircle)
740
    setLineWidth(lwf,innercircle)
741
    setLineColor(fgcol,innercircle)
742
    setFillColor(fgcol,innercircle)
743
    setLineWidth(lwf,lin01)
744
    setLineWidth(lwf,lin02)
745
    setLineWidth(lwf,lin03)
746
    setLineWidth(lwf,lin04)
747
    setLineWidth(lwf,lin05)
748
    setLineWidth(lwf,lin06)
749
    setLineColor(fgcol,lin01)
750
    setLineColor(fgcol,lin02)
751
    setLineColor(fgcol,lin03)
752
    setLineColor(fgcol,lin04)
753
    setLineColor(bgcol,lin05)
754
    setLineColor(bgcol,lin06)
755
 
756
 
757
if __name__ == '__main__':
758
    if haveDoc():
759
        main()
760
    else:
761
        messageBox("Bleed and Marks", "There must be an open document.", ICON_INFORMATION)