commit 417879d970eace849e484a2c90baa4c0df4d770d Author: Quantum Date: Sat Mar 16 17:48:17 2019 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00e6cae --- /dev/null +++ b/.gitignore @@ -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 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e00a0e0 --- /dev/null +++ b/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + PDFSignatureRemover + PDFSignatureRemover + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + + + + + com.itextpdf + itextpdf + 5.5.13 + + + diff --git a/src/main/java/xyz/quantum2/PDFSignatureRemover.java b/src/main/java/xyz/quantum2/PDFSignatureRemover.java new file mode 100644 index 0000000..2eb9427 --- /dev/null +++ b/src/main/java/xyz/quantum2/PDFSignatureRemover.java @@ -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 "); + 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(); + } + } +} diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6bc9bef --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Main-Class: xyz.quantum2.PDFSignatureRemover