Skip to content

Commit

Permalink
Refactored PDFBox 1.8 into separate bundle
Browse files Browse the repository at this point in the history
Issue: #4449
  • Loading branch information
buchen committed Jan 3, 2025
1 parent 5cddf16 commit e3abc4f
Show file tree
Hide file tree
Showing 16 changed files with 697 additions and 135 deletions.
6 changes: 6 additions & 0 deletions name.abuchen.portfolio.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ For purposes of the EPL, "Program" will mean the Content.
</license>

<plugin
id="name.abuchen.portfolio.pdfbox1"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

id="name.abuchen.portfolio"
download-size="0"
install-size="0"
Expand Down
10 changes: 10 additions & 0 deletions name.abuchen.portfolio.pdfbox1/.checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<local-check-config name="Portfolio Performance Checkstyle Configuration" location="/portfolio-app/portfolioCheckstyle.xml" type="project" description="">
<additional-data name="protect-config-file" value="false"/>
</local-check-config>
<fileset name="all" enabled="true" check-config-name="Portfolio Performance Checkstyle Configuration" local="true">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
</fileset-config>
11 changes: 11 additions & 0 deletions name.abuchen.portfolio.pdfbox1/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions name.abuchen.portfolio.pdfbox1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
44 changes: 44 additions & 0 deletions name.abuchen.portfolio.pdfbox1/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>name.abuchen.portfolio.pdfbox1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.sonarlint.eclipse.core.sonarlintBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
411 changes: 411 additions & 0 deletions name.abuchen.portfolio.pdfbox1/.settings/org.eclipse.jdt.core.prefs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
formatter_profile=_portfolio
formatter_settings_version=23
13 changes: 13 additions & 0 deletions name.abuchen.portfolio.pdfbox1/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: name.abuchen.portfolio.pdfbox1
Bundle-Version: 0.73.1.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-21
Export-Package: name.abuchen.portfolio.pdfbox1
Import-Package: org.osgi.framework
Require-Bundle: org.apache.pdfbox;bundle-version="[1.8.17,2.0.0)"
Bundle-ClassPath: .
Bundle-Vendor: %Bundle-Vendor
Automatic-Module-Name: name.abuchen.portfolio.pdfbox1
Bundle-ActivationPolicy: lazy
4 changes: 4 additions & 0 deletions name.abuchen.portfolio.pdfbox1/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
.
42 changes: 42 additions & 0 deletions name.abuchen.portfolio.pdfbox1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>name.abuchen.portfolio</groupId>
<artifactId>portfolio-app</artifactId>
<version>0.73.1-SNAPSHOT</version>
<relativePath>../portfolio-app</relativePath>
</parent>

<artifactId>name.abuchen.portfolio.pdfbox1</artifactId>
<packaging>eclipse-plugin</packaging>

<properties>
<sonar.coverage.jacoco.xmlReportPaths>../name.abuchen.portfolio.tests/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-versions</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package name.abuchen.portfolio.pdfbox1;

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.exceptions.CryptographyException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
import org.osgi.framework.FrameworkUtil;

public class PDFBox1
{
public String convertToText(File file) throws IOException
{
try (PDDocument document = PDDocument.load(file))
{
boolean isProtected = document.isEncrypted();
if (isProtected)
{
document.decrypt(""); //$NON-NLS-1$
document.setAllSecurityToBeRemoved(true);
}

PDFTextStripper textStripper = new PDFTextStripper();
textStripper.setSortByPosition(true);
var text = textStripper.getText(document);

// replace horizontal whitespace characters by normal whitespace
text = text.replaceAll("\\h", " "); //$NON-NLS-1$ //$NON-NLS-2$

// without carriage returns
return text.replace("\r", ""); //$NON-NLS-1$ //$NON-NLS-2$

}
catch (CryptographyException e)
{
throw new IOException(e);
}
}

public String getPDFBoxVersion()
{
return FrameworkUtil.getBundle(PDDocument.class).getVersion().toString();
}
}
Loading

0 comments on commit e3abc4f

Please sign in to comment.