From f8f8e3366cc78886d10f5a6cd74b164ad1d4a2d5 Mon Sep 17 00:00:00 2001 From: Sahara Yousuf Date: Tue, 13 Feb 2024 12:55:57 -0600 Subject: [PATCH 1/2] Add ConvertToOffice Kotlin sample --- .github/workflows/test-kotlin-samples.yml | 5 +- .../runConfigurations/ConvertToOffice.xml | 14 ++ ConvertToOffice/pom.xml | 231 ++++++++++++++++++ .../pdfl/samples/ConvertToOffice.kt | 66 +++++ 4 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 ConvertToOffice/.idea/runConfigurations/ConvertToOffice.xml create mode 100644 ConvertToOffice/pom.xml create mode 100644 ConvertToOffice/src/main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt diff --git a/.github/workflows/test-kotlin-samples.yml b/.github/workflows/test-kotlin-samples.yml index 552a164..99d2962 100644 --- a/.github/workflows/test-kotlin-samples.yml +++ b/.github/workflows/test-kotlin-samples.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] - dir: ['TextExtract', 'FlattenTransparency', 'SplitPDF'] + dir: ['TextExtract', 'FlattenTransparency', 'SplitPDF', 'ConvertToOffice'] steps: - name: Checkout uses: actions/checkout@v4 @@ -59,3 +59,6 @@ jobs: path: | ${{matrix.dir}}/*.txt ${{matrix.dir}}/*.pdf + ${{matrix.dir}}/*.docx + ${{matrix.dir}}/*.xlsx + ${{matrix.dir}}/*.pptx diff --git a/ConvertToOffice/.idea/runConfigurations/ConvertToOffice.xml b/ConvertToOffice/.idea/runConfigurations/ConvertToOffice.xml new file mode 100644 index 0000000..a123f46 --- /dev/null +++ b/ConvertToOffice/.idea/runConfigurations/ConvertToOffice.xml @@ -0,0 +1,14 @@ + + + + + + + diff --git a/ConvertToOffice/pom.xml b/ConvertToOffice/pom.xml new file mode 100644 index 0000000..edbafd6 --- /dev/null +++ b/ConvertToOffice/pom.xml @@ -0,0 +1,231 @@ + + + 4.0.0 + com.datalogics.pdfl.samples + ConvertToOffice + 1.0-SNAPSHOT + + + + mavenCentral + https://repo1.maven.org/maven2/ + + + + + UTF-8 + official + 1.8 + 1.8 + 1.8 + + + + + Windows64 + + + windows + amd64 + + + + win-x86-64-jni + + + + MacArm + + + mac + aarch64 + + + + mac-arm-64-jni + + + + Linux64 + + + + Linux + amd64 + + + + linux-x86-64-jni + + + + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + 1.9.21 + + + com.datalogics.pdfl + pdfl + 18.31.0 + pom + + + com.datalogics.pdfl + pdfl + 18.31.0 + + + com.datalogics.pdfl + pdfl + 18.31.0 + zip + ${jni.classifier} + + + com.datalogics.pdfl + pdfl + 18.31.0 + zip + resources + + + com.datalogics.pdfl + pdfl + 18.31.0 + javadoc + + + + + src/main/kotlin + + + org.jetbrains.kotlin + kotlin-maven-plugin + 1.9.21 + + + compile + compile + + compile + + + + + + maven-surefire-plugin + 2.22.2 + + + maven-failsafe-plugin + 2.22.2 + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + ConvertToOffice + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack-resources + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + resources + zip + ${project.build.directory}/lib/Resources + + + + + + unpack-jni + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + ${jni.classifier} + zip + ${project.build.directory}/lib + + + + + + unpack-license + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + license + zip + ${project.build.directory}/lib + + + + + + + + maven-assembly-plugin + + + package + + single + + + + + + + true + com.datalogics.pdfl.samples.ConvertToOfficeKt + + + + jar-with-dependencies + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.0.2 + + + + + + \ No newline at end of file diff --git a/ConvertToOffice/src/main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt b/ConvertToOffice/src/main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt new file mode 100644 index 0000000..c1b4d5d --- /dev/null +++ b/ConvertToOffice/src/main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt @@ -0,0 +1,66 @@ +package com.datalogics.pdfl.samples + +import com.datalogics.PDFL.Document +import com.datalogics.PDFL.Library + +/* + * + * This program converts sample PDF documents to Word, Excel, and PowerPoint files. + * + * Please note that the Office conversion APIs convertToWord, convertToExcel, and convertToPowerPoint are available on + * Windows only. + * + * Copyright (c) 2024, Datalogics, Inc. All rights reserved. + * + */ +class ConvertToOffice { + enum class OfficeType { + WORD, + EXCEL, + POWERPOINT + } + + companion object { + fun convertPDFToOffice(inputPath: String, outputPath: String, officeType: OfficeType) { + println("Converting $inputPath, output file is $outputPath") + + val result: Boolean = when (officeType) { + OfficeType.WORD -> Document.convertToWord(inputPath, outputPath) + OfficeType.EXCEL -> Document.convertToExcel(inputPath, outputPath) + OfficeType.POWERPOINT -> Document.convertToPowerPoint(inputPath, outputPath) + } + + if (result) { + println("Successfully converted $inputPath to $outputPath") + } else { + println("ERROR: Could not convert $inputPath") + } + } + } +} + +fun main(args: Array) { + println("ConvertToOffice Sample:") + + val lib = Library() + try { + println("Initialized the library.") + + val inputPathWord = Library.getResourceDirectory() + "Sample_Input/Word.pdf" + val outputPathWord = "word-out.docx" + val inputPathExcel = Library.getResourceDirectory() + "Sample_Input/Excel.pdf" + val outputPathExcel = "excel-out.xlsx" + val inputPathPowerPoint = Library.getResourceDirectory() + "Sample_Input/PowerPoint.pdf" + val outputPathPowerPoint = "powerpoint-out.pptx" + + ConvertToOffice.convertPDFToOffice(inputPathWord, outputPathWord, ConvertToOffice.OfficeType.WORD) + ConvertToOffice.convertPDFToOffice(inputPathExcel, outputPathExcel, ConvertToOffice.OfficeType.EXCEL) + ConvertToOffice.convertPDFToOffice( + inputPathPowerPoint, + outputPathPowerPoint, + ConvertToOffice.OfficeType.POWERPOINT + ) + } finally { + lib.delete() + } +} From 6084c7a146ba7298c754d9f3bce063dd5432d0c2 Mon Sep 17 00:00:00 2001 From: Sahara Yousuf Date: Tue, 13 Feb 2024 13:13:47 -0600 Subject: [PATCH 2/2] Fix comment about platform availability --- .../main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConvertToOffice/src/main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt b/ConvertToOffice/src/main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt index c1b4d5d..a32e4de 100644 --- a/ConvertToOffice/src/main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt +++ b/ConvertToOffice/src/main/kotlin/com/datalogics/pdfl/samples/ConvertToOffice.kt @@ -8,7 +8,7 @@ import com.datalogics.PDFL.Library * This program converts sample PDF documents to Word, Excel, and PowerPoint files. * * Please note that the Office conversion APIs convertToWord, convertToExcel, and convertToPowerPoint are available on - * Windows only. + * Windows 32/64-bit and Linux 64-bit only. * * Copyright (c) 2024, Datalogics, Inc. All rights reserved. *