-
Notifications
You must be signed in to change notification settings - Fork 26
/
ExportPDFWithOptions.py
127 lines (115 loc) · 5.6 KB
/
ExportPDFWithOptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""
Exports the current document as PDF.
Assumes you have a document open.
document.exportFile parameters are:
Format: use either the ExportFormat.pdfType constant or the string "Adobe PDF"
To: a file path as a string
Using: PDF export preset (or a string that is the name of a PDF export preset)
The default PDF export preset names are surrounded by square brackets (e.g., "[Screen]").
"""
import win32com.client
import os
app = win32com.client.Dispatch('InDesign.Application.CC.2017')
myInddFile = r'C:\ServerTestFiles\TestDocument.indd'
myDocument = app.Open(myInddFile)
myPDFFile = r'C:\ServerTestFiles\TestDocument.pdf'
directory = os.path.dirname(myPDFFile)
# def setattrs(_self, **kwargs):
# for k, v in kwargs.items():
# setattr(_self, k, v)
#
# pdfExportPreferences = app.PDFExportPreferences
# pdfExportPreferences.setattr(pdfExportPreferences,
# ExportGuidesAndGrids=False,
# ExportLayers=False,
# ExportNonPrintingObjects=False,
# ExportReaderSpreads=False,
# GenerateThumbnails=False
# )
try:
if not os.path.exists(directory):
os.makedirs(directory)
if os.path.exists(directory):
try:
pdfExportPreferences = app.PDFExportPreferences
# Basic PDF output options.
idAllPages = 1886547553
idAcrobat6 = 1097020976
pdfExportPreferences.PageRange = idAllPages
pdfExportPreferences.AcrobatCompatibility = idAcrobat6
pdfExportPreferences.ExportGuidesAndGrids = False
pdfExportPreferences.ExportLayers = False
#pdfExportPreferences.ExportNonPrintingObjects = False
pdfExportPreferences.ExportReaderSpreads = False
pdfExportPreferences.GenerateThumbnails = False
try:
pdfExportPreferences.IgnoreSpreadOverrides = False
except Exception as e:
print("IgnoreSpreadOverrides: " + str(e))
pdfExportPreferences.IncludeBookmarks = True
pdfExportPreferences.IncludeHyperlinks = True
pdfExportPreferences.IncludeICCProfiles = True
pdfExportPreferences.IncludeSlugWithPDF = False
pdfExportPreferences.IncludeStructure = False
#pdfExportPreferences.InteractiveElements = False
"""
Setting subsetFontsBelow to zero disallows font subsetting
set subsetFontsBelow to some other value to use font subsetting.
"""
pdfExportPreferences.SubsetFontsBelow = 0
# Bitmap compression/sampling/quality options
idZip = 2053730371
idEightBit = 1701722210
idNone = 1852796517
pdfExportPreferences.ColorBitmapCompression = idZip
pdfExportPreferences.ColorBitmapQuality = idEightBit
pdfExportPreferences.ColorBitmapSampling = idNone
# thresholdToCompressColor is not needed in this example
# colorBitmapSamplingDPI is not needed when colorBitmapSampling is set to none
pdfExportPreferences.GrayscaleBitmapCompression = idZip
pdfExportPreferences.GrayscaleBitmapQuality = idEightBit
pdfExportPreferences.GrayscaleBitmapSampling = idNone
# thresholdToCompressGray is not needed in this example
# grayscaleBitmapSamplingDPI is not needed when grayscaleBitmapSampling is set to none
pdfExportPreferences.MonochromeBitmapCompression = idZip
pdfExportPreferences.MonochromeBitmapSampling = idNone
# thresholdToCompressMonochrome is not needed in this example
# monochromeBitmapSamplingDPI is not needed when monochromeBitmapSampling is set to none
# Other compression options
idCompressNone = 1131368047
pdfExportPreferences.CompressionType = idCompressNone
pdfExportPreferences.CompressTextAndLineArt = True
pdfExportPreferences.CropImagesToFrames = True
pdfExportPreferences.OptimizePDF = True
# Printers marks and prepress options.
# Get the bleed amounts from the document's bleed.
bleedBottom = app.Documents.Item(1).DocumentPreferences.DocumentBleedBottomOffset
bleedTop = app.Documents.Item(1).DocumentPreferences.DocumentBleedTopOffset
bleedInside = app.Documents.Item(1).DocumentPreferences.DocumentBleedInsideOrLeftOffset
bleedOutside = app.Documents.Item(1).DocumentPreferences.DocumentBleedOutsideOrRightOffset
# If any bleed area is greater than zero, then export the bleed marks.
if bleedBottom is 0 and bleedTop is 0 and bleedInside is 0 and bleedOutside is 0:
pdfExportPreferences.BleedMarks = True
else:
pdfExportPreferences.BleedMarks = False
# Default mark type
idDefault = 1147563124
pdfExportPreferences.PDFMarkType = idDefault
idP125pt = 825374064
printerMarkWeight = idP125pt
pdfExportPreferences.RegistrationMarks = True
try:
pdfExportPreferences.SimulateOverprint = False
except Exception as e:
print("SimulateOverprint: " + str(e))
pdfExportPreferences.UseDocumentBleedWithPDF = True
# Set viewPDF to true to open the PDF in Acrobat or Adobe Reader
pdfExportPreferences.ViewPDF = True
except Exception as e:
print(e)
# Now do the export
idPDFType = 1952403524
myDocument.Export(idPDFType, myPDFFile)
except Exception as e:
print('Export to PDF failed: ' + str(e))
myDocument.Close()