Initial commit

This commit is contained in:
Quantum 2019-03-16 17:48:17 -04:00
commit 417879d970
4 changed files with 132 additions and 0 deletions

41
.gitignore vendored Normal file
View file

@ -0,0 +1,41 @@
### Java template
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
### IntelliJ
.idea/
out/
*.iml

30
pom.xml Normal file
View file

@ -0,0 +1,30 @@
<?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>PDFSignatureRemover</groupId>
<artifactId>PDFSignatureRemover</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,59 @@
package xyz.quantum2;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class PDFSignatureRemover {
private static void help() {
System.out.println("Usage: java -jar PDFSignatureRemover.jar <input PDF> <output PDF>");
System.exit(1);
}
private static void error(String error) {
System.err.println("Error when removing PDF signature: " + error);
System.exit(1);
}
public static void main(String... args) {
if (args.length != 2) {
help();
}
File input = new File(args[0]);
File output = new File(args[1]);
if (!input.isFile()) {
error("Input file not found: " + input);
}
PdfReader reader;
try {
reader = new PdfReader(input.toString());
} catch (IOException e) {
error("Failed to read input PDF: " + e);
return;
}
try {
AcroFields acroFields = reader.getAcroFields();
for (String name : acroFields.getFields().keySet()) {
acroFields.removeField(name);
}
try {
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(output));
stamper.close();
} catch (IOException | DocumentException e) {
error("Failed to write output PDF: " + e);
}
} finally {
reader.close();
}
}
}

View file

@ -0,0 +1,2 @@
Manifest-Version: 1.0
Main-Class: xyz.quantum2.PDFSignatureRemover