Subversion Repositories Scribus

Rev

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