ConvertPdfToPs.java
10.1 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.aemfd.docmanager.Document
* com.adobe.fd.cpdf.api.ConvertPdfService
* com.adobe.fd.cpdf.api.ToPSOptionsSpec
* com.adobe.fd.cpdf.api.enumeration.Color
* com.adobe.fd.cpdf.api.enumeration.FontInclusion
* com.adobe.fd.cpdf.api.enumeration.LineWeight
* com.adobe.fd.cpdf.api.enumeration.PSLevel
* com.adobe.fd.cpdf.api.enumeration.PageSize
* com.adobe.fd.cpdf.api.enumeration.Style
* com.adobe.granite.workflow.WorkflowException
* com.adobe.granite.workflow.WorkflowSession
* com.adobe.granite.workflow.exec.WorkItem
* com.adobe.granite.workflow.metadata.MetaDataMap
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.fd.workflow.cpdf.impl;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.fd.cpdf.api.ConvertPdfService;
import com.adobe.fd.cpdf.api.ToPSOptionsSpec;
import com.adobe.fd.cpdf.api.enumeration.Color;
import com.adobe.fd.cpdf.api.enumeration.FontInclusion;
import com.adobe.fd.cpdf.api.enumeration.LineWeight;
import com.adobe.fd.cpdf.api.enumeration.PSLevel;
import com.adobe.fd.cpdf.api.enumeration.PageSize;
import com.adobe.fd.cpdf.api.enumeration.Style;
import com.adobe.fd.workflow.forms.internal.common.FormsUtil;
import com.adobe.fd.workflow.internal.common.AEMFDWorkflowProcess;
import com.adobe.granite.workflow.WorkflowException;
import com.adobe.granite.workflow.WorkflowSession;
import com.adobe.granite.workflow.exec.WorkItem;
import com.adobe.granite.workflow.metadata.MetaDataMap;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@Service
@Properties(value={@Property(name="service.description", value={"ConvertPdfToPs"}), @Property(name="service.vendor", value={"Adobe"}), @Property(name="process.label", value={"ConvertPdfToPs"})})
public class ConvertPdfToPs
extends AEMFDWorkflowProcess {
private static Logger logger = LoggerFactory.getLogger(ConvertPdfToPs.class);
private static final String PS_LEVEL = "psLevel";
private static final String ALLOW_BINARY_CONTENT = "allowBinaryContent";
private static final String FONT_INCLUSION = "fontInclusion";
private static final String INCLUDE_COMMENTS = "includeComments";
private static final String CONVERT_TRUE_TYPE_TO_TYPE1 = "convertTrueTypeToType1";
private static final String COLOR = "color";
private static final String USE_MAX_JPEG_IMAGE_RESOLUTION = "useMaxJPEGImageResolution";
private static final String TRIM_MARKS = "trimMarks";
private static final String BLEED_MARKS = "bleedMarks";
private static final String REGISTRATION_MARKS = "registrationMarks";
private static final String COLOR_BARS = "colorBars";
private static final String PAGE_INFORMATION = "pageInformation";
private static final String LINE_WEIGHT = "lineWeight";
private static final String EMIT_PS_FORM_OBJECTS = "emitPSFormObjects";
private static final String EMIT_CID_FONT_TYPE2 = "emitCIDFontType2";
private static final String SHRINK_TO_FIT = "shrinkToFit";
private static final String EXPAND_TO_FIT = "expandToFit";
private static final String ROTATE_AND_CENTER = "rotateAndCenter";
private static final String PAGE_SIZE_WIDTH = "pageSizeWidth";
private static final String PAGE_SIZE_HEIGHT = "pageSizeHeight";
private static final String REVERSE = "reverse";
private static final String STYLE = "style";
private static final String PAGE_SIZE = "pageSize";
private static final String PAGE_RANGE = "pageRange";
public static final String LEGACY_TO_SIMPLEPS = "legacyToSimplePSFlag";
private static final String DATA_PARAM = "inputpath";
private static final String OUTPUT_PARAM = "output";
@Reference
private ConvertPdfService convertPdfService;
@Override
protected void internal_execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
try {
Document dataDoc = FormsUtil.getDocument(workItem, "inputpath");
ToPSOptionsSpec specs = this.getPSOptionsSpec(workItem, workflowSession, metaDataMap);
Document document = this.convertPdfService.toPS(dataDoc, specs);
FormsUtil.saveDocument(workItem, workflowSession, document, "output");
}
catch (Exception e) {
throw new WorkflowException((Throwable)e);
}
}
private ToPSOptionsSpec getPSOptionsSpec(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) {
ToPSOptionsSpec specs = new ToPSOptionsSpec();
specs.setPsLevel(PSLevel.valueOf((String)((String)metaDataMap.get("psLevel", String.class))));
if (metaDataMap.get("allowBinaryContent", Boolean.class) != null) {
specs.setAllowBinaryContent(((Boolean)metaDataMap.get("allowBinaryContent", Boolean.class)).booleanValue());
}
if (metaDataMap.get("fontInclusion", String.class) != null) {
specs.setFontInclusion(FontInclusion.valueOf((String)((String)metaDataMap.get("fontInclusion", String.class))));
}
if (metaDataMap.get("includeComments", Boolean.class) != null) {
specs.setIncludeComments(((Boolean)metaDataMap.get("includeComments", Boolean.class)).booleanValue());
}
if (metaDataMap.get("convertTrueTypeToType1", Boolean.class) != null) {
specs.setConvertTrueTypeToType1(((Boolean)metaDataMap.get("convertTrueTypeToType1", Boolean.class)).booleanValue());
} else {
specs.setConvertTrueTypeToType1(false);
}
if (metaDataMap.get("color", String.class) != null) {
specs.setColor(Color.valueOf((String)((String)metaDataMap.get("color", String.class))));
}
if (metaDataMap.get("useMaxJPEGImageResolution", Boolean.class) != null) {
specs.setUseMaxJPEGImageResolution(((Boolean)metaDataMap.get("useMaxJPEGImageResolution", Boolean.class)).booleanValue());
} else {
specs.setUseMaxJPEGImageResolution(false);
}
if (metaDataMap.get("trimMarks", Boolean.class) != null) {
specs.setTrimMarks(((Boolean)metaDataMap.get("trimMarks", Boolean.class)).booleanValue());
}
if (metaDataMap.get("bleedMarks", Boolean.class) != null) {
specs.setBleedMarks(((Boolean)metaDataMap.get("bleedMarks", Boolean.class)).booleanValue());
}
if (metaDataMap.get("registrationMarks", Boolean.class) != null) {
specs.setRegistrationMarks(((Boolean)metaDataMap.get("registrationMarks", Boolean.class)).booleanValue());
}
if (metaDataMap.get("colorBars", Boolean.class) != null) {
specs.setColorBars(((Boolean)metaDataMap.get("colorBars", Boolean.class)).booleanValue());
}
if (metaDataMap.get("pageInformation", Boolean.class) != null) {
specs.setPageInformation(((Boolean)metaDataMap.get("pageInformation", Boolean.class)).booleanValue());
}
if (metaDataMap.get("lineWeight", String.class) != null) {
specs.setLineWeight(LineWeight.valueOf((String)((String)metaDataMap.get("lineWeight", String.class))));
}
if (metaDataMap.get("emitPSFormObjects", Boolean.class) != null) {
specs.setEmitPSFormObjects(((Boolean)metaDataMap.get("emitPSFormObjects", Boolean.class)).booleanValue());
}
if (metaDataMap.get("emitCIDFontType2", Boolean.class) != null) {
specs.setEmitCIDFontType2(((Boolean)metaDataMap.get("emitCIDFontType2", Boolean.class)).booleanValue());
}
if (metaDataMap.get("shrinkToFit", Boolean.class) != null) {
specs.setShrinkToFit(((Boolean)metaDataMap.get("shrinkToFit", Boolean.class)).booleanValue());
}
if (metaDataMap.get("expandToFit", Boolean.class) != null) {
specs.setExpandToFit(((Boolean)metaDataMap.get("expandToFit", Boolean.class)).booleanValue());
}
if (metaDataMap.get("rotateAndCenter", Boolean.class) != null) {
specs.setRotateAndCenter(((Boolean)metaDataMap.get("rotateAndCenter", Boolean.class)).booleanValue());
}
if (metaDataMap.get("pageSizeWidth", String.class) != null) {
specs.setPageSizeWidth((String)metaDataMap.get("pageSizeWidth", String.class));
}
if (metaDataMap.get("pageSizeHeight", String.class) != null) {
specs.setPageSizeHeight((String)metaDataMap.get("pageSizeHeight", String.class));
}
if (metaDataMap.get("reverse", Boolean.class) != null) {
specs.setReverse(((Boolean)metaDataMap.get("reverse", Boolean.class)).booleanValue());
}
if (metaDataMap.get("style", String.class) != null) {
specs.setStyle(Style.valueOf((String)((String)metaDataMap.get("style", String.class))));
}
if (metaDataMap.get("pageSize", String.class) != null) {
specs.setPageSize(PageSize.valueOf((String)((String)metaDataMap.get("pageSize", String.class))));
}
if (metaDataMap.get("pageRange", String.class) != null) {
specs.setPageRange((String)metaDataMap.get("pageRange", String.class));
}
if (metaDataMap.get("legacyToSimplePSFlag", Boolean.class) != null) {
specs.setLegacyToSimplePSFlag(((Boolean)metaDataMap.get("legacyToSimplePSFlag", Boolean.class)).booleanValue());
}
return specs;
}
protected void bindConvertPdfService(ConvertPdfService convertPdfService) {
this.convertPdfService = convertPdfService;
}
protected void unbindConvertPdfService(ConvertPdfService convertPdfService) {
if (this.convertPdfService == convertPdfService) {
this.convertPdfService = null;
}
}
}