Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vsr061 committed Apr 11, 2021
0 parents commit a8eb9b0
Show file tree
Hide file tree
Showing 17 changed files with 1,621 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Created by https://www.gitignore.io/api/eclipse,java,maven

### Eclipse ###
*.pydevproject
.metadata
.gradle
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific
.buildpath

# sbteclipse plugin
.target

# TeXlipse plugin
.texlipse


### Java ###
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*


### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties

### Vault ###
.vlt

### IntelliJ ###
.idea/
*.iml
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# PDF Watermark Workflow Model & Step

This project is built to demonstrate how to create custom workflow steps and models in AEM.

**Use case:** Adding a watermark to a PDF using AEM Asset Workflow.

This project uses [Apache PDFBox library](https://pdfbox.apache.org/) to parse PDF documents and to add a watermark layer for each page. These dependencies are embedded in the project bundle JAR file **(Check core module's POM file for more details: core/pom.xml, line 67)**.

**Add PDF Watermark Model:** `/var/workflow/models/add-pdf-watermark`

**PDF Watermark Process Step Component:** `/apps/custom-workflow-step/components/workflow/pdf-watermark`

**PDF Watermark Process Step JAVA Class:** `com.hashout.core.workflows.PDFWatermarkProcess`

## How to build

To build all the modules run in the project root directory the following command with Maven 3:

mvn clean install

If you have a running AEM instance you can build and package the whole project and deploy into AEM with

mvn clean install -PautoInstallPackage

Or to deploy it to a publish instance, run

mvn clean install -PautoInstallPackagePublish

Or alternatively

mvn clean install -PautoInstallPackage -Daem.port=4503

Or to deploy only the bundle to the author, run

mvn clean install -PautoInstallBundle

## Maven settings

The project comes with the auto-public repository configured. To setup the repository in your Maven settings, refer to:

http://helpx.adobe.com/experience-manager/kb/SetUpTheAdobeMavenRepository.html
167 changes: 167 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
| Copyright 2017 Adobe Systems Incorporated
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.hashout</groupId>
<artifactId>custom-workflow-step</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>custom-workflow-step.core</artifactId>
<packaging>bundle</packaging>
<name>Custom Workflow Step - Core</name>
<description>Core bundle for Custom Workflow Step</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>generate-osgi-metadata-for-unittests</id>
<goals>
<goal>manifest</goal>
</goals>
<phase>process-classes</phase>
</execution>
<execution>
<id>scr-metadata</id>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<supportIncrementalBuild>true</supportIncrementalBuild>
</configuration>
</execution>
</executions>
<configuration>
<exportScr>true</exportScr>
<instructions>
<!-- Import any version of javax.inject and javax.annotation, to allow running on multiple versions of AEM -->
<Import-Package>
javax.inject;version=0.0.0,
javax.annotation;version=0.0.0,
*
</Import-Package>
<Embed-Dependency>
pdfbox,
fontbox,
bcprov-jdk15on,
bcpkix-jdk15on
</Embed-Dependency>
<Sling-Model-Packages>
com.hashout.core
</Sling-Model-Packages>
<_dsannotations>*</_dsannotations>
<_metatypeannotations>*</_metatypeannotations>
<_plugin>
<!-- Enable registration of Sling Models classes via bnd plugin -->
org.apache.sling.bnd.models.ModelsScannerPlugin,
<!-- Allow the processing of SCR annotations via a bnd plugin -->
org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin;destdir=${project.build.outputDirectory}
</_plugin>
</instructions>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.bnd</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.bnd.models</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>

<dependencies>
<!-- OSGi Dependencies -->
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.annotation</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<!-- Other Dependencies -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>uber-jar</artifactId>
<classifier>apis</classifier>
</dependency>
<dependency>
<groupId>uk.org.lidalia</groupId>
<artifactId>slf4j-test</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
</dependency>
</dependencies>
</project>
19 changes: 19 additions & 0 deletions core/src/main/java/com/hashout/core/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2015 Adobe Systems Incorporated
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Version("1.0")
package com.hashout.core;

import org.osgi.annotation.versioning.Version;
84 changes: 84 additions & 0 deletions core/src/main/java/com/hashout/core/utils/PDFHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.hashout.core.utils;

import org.apache.commons.lang3.StringUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

public final class PDFHelper {

private static final Map<String, PDFont> FONT_MAP = new HashMap<String, PDFont>() {{
put("Times Roman", PDType1Font.TIMES_ROMAN);
put("Times Roman Bold", PDType1Font.TIMES_BOLD);
put("Times Roman Italic", PDType1Font.TIMES_ITALIC);
put("Times Roman Bold Italic", PDType1Font.TIMES_BOLD_ITALIC);
put("Helvetica", PDType1Font.HELVETICA);
put("Helvetica Bold", PDType1Font.HELVETICA_BOLD);
put("Helvetica Oblique", PDType1Font.HELVETICA_OBLIQUE);
put("Helvetica Bold Oblique", PDType1Font.HELVETICA_BOLD_OBLIQUE);
put("Courier", PDType1Font.COURIER);
put("Courier Bold", PDType1Font.COURIER_BOLD);
put("Courier Oblique", PDType1Font.COURIER_OBLIQUE);
put("Courier Bold Oblique", PDType1Font.COURIER_BOLD_OBLIQUE);
}};

public static PDFont getFontFromName(String name) {
return FONT_MAP.getOrDefault(name, PDType1Font.TIMES_ROMAN);
}

public static float getFontSize(String fontSize) {
return StringUtils.isNumeric(fontSize) ? Float.parseFloat(fontSize) : 20;
}

public static Color getColor(String color) {
return StringUtils.startsWith(color, "#") && StringUtils.length(color) == 7
? Color.decode(color)
: Color.BLACK;
}

public static float getOpacity(String opacity) {
return StringUtils.isNumeric(opacity) ? Float.parseFloat(opacity) / 100 : 0.2f;
}

public static float getXOffsetFromPosition(String position, float textWidth, PDDocument doc) {
if (position != null) {
switch (position) {
case "TOP_LEFT":
case "BOTTOM_LEFT":
return 0;
case "TOP_RIGHT":
case "BOTTOM_RIGHT":
return doc.getPage(0).getMediaBox().getWidth() - textWidth;
case "CENTER":
default:
return (doc.getPage(0).getMediaBox().getWidth() - textWidth) / 2;
}
}
return (doc.getPage(0).getMediaBox().getWidth() - textWidth) / 2;
}

public static float getYOffsetFromPosition(String position, float textHeight, PDDocument doc) {
if (position != null) {
switch (position) {
case "TOP_LEFT":
case "TOP_RIGHT":
return doc.getPage(0).getMediaBox().getHeight() - textHeight;
case "BOTTOM_LEFT":
case "BOTTOM_RIGHT":
return 0;
case "CENTER":
default:
return (doc.getPage(0).getMediaBox().getHeight() - textHeight) / 2;
}
}
return (doc.getPage(0).getMediaBox().getHeight() - textHeight) / 2;
}

public static double getOrientation(String angle) {
return StringUtils.isNumeric(angle) ? Math.toRadians(Double.parseDouble(angle)) : Math.toRadians(45);
}
}
Loading

0 comments on commit a8eb9b0

Please sign in to comment.