aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qpdfjob-remove-annotations.cc
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-03-05 16:13:34 +0100
committerm-holger <m-holger@kubitscheck.org>2023-03-09 18:29:39 +0100
commit99231c437860d3b07d99ff12e41529492419f6a7 (patch)
tree6328671e93f3da53dca00108183014d113a58f17 /examples/qpdfjob-remove-annotations.cc
parent43d9ee56ea958428ce3a8e395a029035d81f914f (diff)
downloadqpdf-99231c437860d3b07d99ff12e41529492419f6a7.tar.zst
Add example qpdfjob-remove-annotations
Diffstat (limited to 'examples/qpdfjob-remove-annotations.cc')
-rw-r--r--examples/qpdfjob-remove-annotations.cc78
1 files changed, 78 insertions, 0 deletions
diff --git a/examples/qpdfjob-remove-annotations.cc b/examples/qpdfjob-remove-annotations.cc
new file mode 100644
index 00000000..dfab3f7b
--- /dev/null
+++ b/examples/qpdfjob-remove-annotations.cc
@@ -0,0 +1,78 @@
+#include <qpdf/QPDFJob.hh>
+#include <qpdf/QPDFUsage.hh>
+#include <qpdf/QUtil.hh>
+
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+
+// This example demonstrates how we can use the QPDFJob createQPDF and writeQPDF
+// methods to add custom transformations to the output produced by QPDFJob runs.
+// The example is a full copy of the qpdf program modified to allways remove all
+// annotations from the final output.
+
+static char const* whoami = 0;
+
+static void
+usageExit(std::string const& msg)
+{
+ std::cerr << std::endl
+ << whoami << ": " << msg << std::endl
+ << std::endl
+ << "For help:" << std::endl
+ << " " << whoami << " --help=usage usage information"
+ << std::endl
+ << " " << whoami << " --help=topic help on a topic"
+ << std::endl
+ << " " << whoami << " --help=--option help on an option"
+ << std::endl
+ << " " << whoami
+ << " --help general help and a topic list"
+ << std::endl
+ << std::endl;
+ exit(QPDFJob::EXIT_ERROR);
+}
+
+int
+realmain(int argc, char* argv[])
+{
+ whoami = QUtil::getWhoami(argv[0]);
+ QUtil::setLineBuf(stdout);
+
+ QPDFJob j;
+ try {
+ // See "HOW TO ADD A COMMAND-LINE ARGUMENT" in README-maintainer.
+ j.initializeFromArgv(argv);
+ auto qpdf_sp = j.createQPDF();
+ auto& pdf = *qpdf_sp;
+ for (auto page: pdf.getAllPages()) {
+ page.replaceKey("/Annots", "null"_qpdf);
+ }
+ j.writeQPDF(pdf);
+ } catch (QPDFUsage& e) {
+ usageExit(e.what());
+ } catch (std::exception& e) {
+ std::cerr << whoami << ": " << e.what() << std::endl;
+ return QPDFJob::EXIT_ERROR;
+ }
+ return j.getExitCode();
+}
+
+#ifdef WINDOWS_WMAIN
+
+extern "C" int
+wmain(int argc, wchar_t* argv[])
+{
+ return QUtil::call_main_from_wmain(argc, argv, realmain);
+}
+
+#else
+
+int
+main(int argc, char* argv[])
+{
+ return realmain(argc, argv);
+}
+
+#endif