ConvertPdfToPs.java 10.1 KB
/*
 * 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;
        }
    }
}