diff options
author | emusic <emina.music@egiz.gv.at> | 2018-01-31 09:21:54 +0100 |
---|---|---|
committer | emusic <emina.music@egiz.gv.at> | 2018-03-21 13:34:04 +0100 |
commit | f60b607e56700bb6b3130c2ad549b0b1c14267a4 (patch) | |
tree | df063fbf4168198b3f94ff566eb5fdc5d07ebd8e /pdf-as-cli | |
parent | 89f53d196e10a1874cd61e3ee42f57dfd77eb856 (diff) | |
download | pdf-as-4-f60b607e56700bb6b3130c2ad549b0b1c14267a4.tar.gz pdf-as-4-f60b607e56700bb6b3130c2ad549b0b1c14267a4.tar.bz2 pdf-as-4-f60b607e56700bb6b3130c2ad549b0b1c14267a4.zip |
protect pdf
Diffstat (limited to 'pdf-as-cli')
-rw-r--r-- | pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java index 6cae9b63..f6df73d5 100644 --- a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java +++ b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java @@ -33,6 +33,7 @@ import java.util.UUID; import javax.activation.DataSource; +import at.gv.egiz.pdfas.lib.api.*; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.GnuParser; @@ -40,15 +41,14 @@ import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.encryption.AccessPermission; +import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy; import org.slf4j.LoggerFactory; import org.slf4j.Logger; import at.gv.egiz.pdfas.common.exceptions.PDFASError; import at.gv.egiz.pdfas.common.utils.StreamUtils; -import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource; -import at.gv.egiz.pdfas.lib.api.Configuration; -import at.gv.egiz.pdfas.lib.api.PdfAs; -import at.gv.egiz.pdfas.lib.api.PdfAsFactory; import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner; import at.gv.egiz.pdfas.lib.api.sign.SignParameter; import at.gv.egiz.pdfas.lib.api.sign.SignResult; @@ -60,6 +60,8 @@ import at.gv.egiz.pdfas.sigs.pades.PAdESSigner; import at.gv.egiz.pdfas.sigs.pades.PAdESSignerKeystore; import at.gv.egiz.sl.util.BKUSLConnector; +import static at.gv.egiz.pdfas.lib.api.IConfigurationConstants.DEFAULT_CONFIG_PROTECT_PDF; + public class Main { public static final String CLI_ARG_MODE_SHORT = "m"; @@ -451,6 +453,24 @@ public class Main { fos.close(); System.out.println("Signed document " + outputFile); + //make output file protected from copying and extraction content + + if(configuration.hasValue(DEFAULT_CONFIG_PROTECT_PDF) && IConfigurationConstants.TRUE.equalsIgnoreCase(configuration.getValue(DEFAULT_CONFIG_PROTECT_PDF))) + { + PDDocument document = PDDocument.load(outputPdfFile); + AccessPermission accessPermission = new AccessPermission(); + accessPermission.setCanExtractContent(false); + accessPermission.setCanExtractForAccessibility(true); + StandardProtectionPolicy spp = new StandardProtectionPolicy("1234","",accessPermission); + spp.setEncryptionKeyLength(128); + spp.setPermissions(accessPermission); + document.protect(spp); + document.save(outputPdfFile); + document.close(); + //accessPermission.setCanModify(false); + // accessPermission.setReadOnly(); + logger.info("Added Protection Parameters"); + } } private static void perform_verify(CommandLine cli) throws Exception { |