1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package cz.hobrasoft.pdfmu.operation.args;
18
19 import com.itextpdf.text.pdf.PdfReader;
20 import com.itextpdf.text.pdf.PdfStamper;
21 import cz.hobrasoft.pdfmu.operation.OperationException;
22 import net.sourceforge.argparse4j.inf.ArgumentParser;
23 import net.sourceforge.argparse4j.inf.Namespace;
24
25
26 public class InOutPdfArgs implements ArgsConfiguration, AutoCloseable {
27
28 private InPdfArgs in;
29 private OutPdfArgs out;
30
31 public InOutPdfArgs() {
32
33 this(true);
34 }
35
36 public InOutPdfArgs(boolean allowAppend) {
37 this("IN.pdf", allowAppend);
38 }
39
40 public InOutPdfArgs(String metavarIn) {
41
42 this(metavarIn, true);
43 }
44
45 public InOutPdfArgs(String metavarIn, boolean allowAppend) {
46 in = new InPdfArgs(metavarIn);
47 out = new OutPdfArgs(metavarIn, allowAppend);
48 }
49
50 @Override
51 public void addArguments(ArgumentParser parser) {
52 in.addArguments(parser);
53 out.addArguments(parser);
54 }
55
56 @Override
57 public void setFromNamespace(Namespace namespace) {
58 in.setFromNamespace(namespace);
59 out.setFromNamespace(namespace);
60 out.setDefaultFile(in.getFile());
61 }
62
63 public void open() throws OperationException {
64 open(false);
65 }
66
67 public void openSignature() throws OperationException {
68 open(true);
69 }
70
71 public void open(boolean signature) throws OperationException {
72 open(signature, '\0');
73 }
74
75 public void open(boolean signature, char pdfVersion) throws OperationException {
76 PdfReader reader = in.open();
77 out.open(reader, signature, pdfVersion);
78 }
79
80 public PdfReader getPdfReader() {
81 return in.getPdfReader();
82 }
83
84 public PdfStamper getPdfStamper() {
85 return out.getPdfStamper();
86 }
87
88 @Override
89 public void close() throws OperationException {
90 close(false);
91 }
92
93 public void close(boolean success) throws OperationException {
94 out.close(success);
95 in.close();
96 }
97
98 public InPdfArgs getIn() {
99 return in;
100 }
101
102
103 public OutPdfArgs getOut() {
104 return out;
105 }
106
107 }