-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from datalogics-saharay/add-pdfa-convert-kotli…
…n-sample Add PDFAConverter Kotlin sample
- Loading branch information
Showing
4 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,231 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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> | ||
<groupId>com.datalogics.pdfl.samples</groupId> | ||
<artifactId>PDFAConverter</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<repositories> | ||
<repository> | ||
<id>mavenCentral</id> | ||
<url>https://repo1.maven.org/maven2/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<kotlin.code.style>official</kotlin.code.style> | ||
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<profiles> | ||
<profile> | ||
<id>Windows64</id> | ||
<activation> | ||
<os> | ||
<family>windows</family> | ||
<arch>amd64</arch> | ||
</os> | ||
</activation> | ||
<properties> | ||
<jni.classifier>win-x86-64-jni</jni.classifier> | ||
</properties> | ||
</profile> | ||
<profile> | ||
<id>MacArm</id> | ||
<activation> | ||
<os> | ||
<family>mac</family> | ||
<arch>aarch64</arch> | ||
</os> | ||
</activation> | ||
<properties> | ||
<jni.classifier>mac-arm-64-jni</jni.classifier> | ||
</properties> | ||
</profile> | ||
<profile> | ||
<id>Linux64</id> | ||
<activation> | ||
<os> | ||
<!-- Use OS <name> instead of <family> because the "unix" <family> also includes Mac --> | ||
<name>Linux</name> | ||
<arch>amd64</arch> | ||
</os> | ||
</activation> | ||
<properties> | ||
<jni.classifier>linux-x86-64-jni</jni.classifier> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib-jdk8</artifactId> | ||
<version>1.9.21</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.datalogics.pdfl</groupId> | ||
<artifactId>pdfl</artifactId> | ||
<version>18.31.0</version> | ||
<type>pom</type> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.datalogics.pdfl</groupId> | ||
<artifactId>pdfl</artifactId> | ||
<version>18.31.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.datalogics.pdfl</groupId> | ||
<artifactId>pdfl</artifactId> | ||
<version>18.31.0</version> | ||
<type>zip</type> | ||
<classifier>${jni.classifier}</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.datalogics.pdfl</groupId> | ||
<artifactId>pdfl</artifactId> | ||
<version>18.31.0</version> | ||
<type>zip</type> | ||
<classifier>resources</classifier> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.datalogics.pdfl</groupId> | ||
<artifactId>pdfl</artifactId> | ||
<version>18.31.0</version> | ||
<classifier>javadoc</classifier> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>src/main/kotlin</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>1.9.21</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<configuration> | ||
<mainClass>PDFAConverter</mainClass> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>unpack-resources</id> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>unpack</goal> | ||
</goals> | ||
<configuration> | ||
<artifactItems> | ||
<artifactItem> | ||
<groupId>com.datalogics.pdfl</groupId> | ||
<artifactId>pdfl</artifactId> | ||
<classifier>resources</classifier> | ||
<type>zip</type> | ||
<outputDirectory>${project.build.directory}/lib/Resources</outputDirectory> | ||
</artifactItem> | ||
</artifactItems> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>unpack-jni</id> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>unpack</goal> | ||
</goals> | ||
<configuration> | ||
<artifactItems> | ||
<artifactItem> | ||
<groupId>com.datalogics.pdfl</groupId> | ||
<artifactId>pdfl</artifactId> | ||
<classifier>${jni.classifier}</classifier> | ||
<type>zip</type> | ||
<outputDirectory>${project.build.directory}/lib</outputDirectory> | ||
</artifactItem> | ||
</artifactItems> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>unpack-license</id> | ||
<phase>generate-resources</phase> | ||
<goals> | ||
<goal>unpack</goal> | ||
</goals> | ||
<configuration> | ||
<artifactItems> | ||
<artifactItem> | ||
<groupId>com.datalogics.pdfl</groupId> | ||
<artifactId>pdfl</artifactId> | ||
<classifier>license</classifier> | ||
<type>zip</type> | ||
<outputDirectory>${project.build.directory}/lib</outputDirectory> | ||
</artifactItem> | ||
</artifactItems> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<addClasspath>true</addClasspath> | ||
<mainClass>com.datalogics.pdfl.samples.PDFAConverterKt</mainClass> | ||
</manifest> | ||
</archive> | ||
<descriptorRefs> | ||
<descriptorRef>jar-with-dependencies</descriptorRef> | ||
</descriptorRefs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
|
||
</project> |
60 changes: 60 additions & 0 deletions
60
PDFAConverter/src/main/kotlin/com/datalogics/pdfl/samples/PDFAConverter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.datalogics.pdfl.samples | ||
|
||
import com.datalogics.PDFL.* | ||
|
||
/* | ||
* | ||
* This program demonstrates converting a standard PDF document into a | ||
* PDF Archive, or PDF/A, compliant version of a PDF file. | ||
* | ||
* Copyright (c) 2024, Datalogics, Inc. All rights reserved. | ||
* | ||
*/ | ||
|
||
fun main(args: Array<String>) { | ||
println("PDFAConverter Sample:") | ||
val lib = Library() | ||
try { | ||
println("Initialized the library.") | ||
var sInput = Library.getResourceDirectory() + "Sample_Input/ducky.pdf" | ||
var sOutput = "PDFAConverter-out.pdf" | ||
|
||
if (args.isNotEmpty()) { | ||
sInput = args[0] | ||
} | ||
|
||
if (args.size > 1) { | ||
sOutput = args[1] | ||
} | ||
println("Converting $sInput") | ||
|
||
val doc = Document(sInput) | ||
|
||
// Make a conversion parameters object | ||
val pdfaParams = PDFAConvertParams().apply { | ||
abortIfXFAIsPresent = true | ||
ignoreFontErrors = false | ||
noValidationErrors = false | ||
validateImplementationLimitsOfDocument = true | ||
} | ||
|
||
// Create a PDF/A compliant version of the document | ||
val pdfaResult = doc.cloneAsPDFADocument(PDFAConvertType.RGB_3B, pdfaParams) | ||
|
||
// The conversion may have failed: we must check if the result has a valid Document | ||
if (pdfaResult.pdfaDocument == null) { | ||
println("ERROR: Could not convert $sInput to PDF/A.") | ||
} else { | ||
println("Successfully converted $sInput to PDF/A.") | ||
|
||
val pdfaDoc = pdfaResult.pdfaDocument | ||
|
||
// Save the result. | ||
pdfaDoc.save(pdfaResult.pdfaSaveFlags, sOutput) | ||
} | ||
|
||
doc.delete() | ||
} finally { | ||
lib.delete() | ||
} | ||
} |