diff options
author | m-holger <m-holger@kubitscheck.org> | 2022-02-20 17:49:31 +0100 |
---|---|---|
committer | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2022-02-25 17:23:43 +0100 |
commit | 527810e939816190e491db7c0a308100d255da85 (patch) | |
tree | 6a078b97a6a328b92c7ca1c6177e2c487e63829d | |
parent | 56b4d5a6108f9b633d890e7cdc2d769128479651 (diff) | |
download | qpdf-527810e939816190e491db7c0a308100d255da85.tar.zst |
Tidy pdf-attach-file example
-rw-r--r-- | examples/pdf-attach-file.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/examples/pdf-attach-file.cc b/examples/pdf-attach-file.cc index 5f60bdb5..c9c5caea 100644 --- a/examples/pdf-attach-file.cc +++ b/examples/pdf-attach-file.cc @@ -11,7 +11,8 @@ // This example attaches a file to an input file, adds a page to the // beginning of the file that includes a file attachment annotation, // and writes the result to an output file. It also illustrates a -// number of new API calls that were added in qpdf 10.2. +// number of new API calls that were added in qpdf 10.2 as well as +// the use of the qpdf literal syntax introduced in qpdf 10.6. // static char const* whoami = 0; @@ -24,8 +25,8 @@ static void usage(std::string const& msg) << " --infile infile.pdf" << std::endl << " --outfile outfile.pdf" << std::endl << " --attachment attachment" << std::endl - << " [ --password infile-password ]" << std::endl - << " [ --mimetype attachment mime type ]" << std::endl; + << " [--password infile-password]" << std::endl + << " [--mimetype attachment mime type]" << std::endl; exit(2); } @@ -90,9 +91,16 @@ static void process(char const* infilename, char const* password, "0 0 20 20 re\n" "S\n"); auto apdict = ap.getDict(); - apdict.replaceKey("/Resources", QPDFObjectHandle::newDictionary()); - apdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); - apdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); + + // The following four lines demonstrate the use of the qpdf literal syntax + // introduced in qpdf 10.6. They could have been written as: + // apdict.replaceKey("/Resources", QPDFObjectHandle::newDictionary()); + // apdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); + // apdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); + // apdict.replaceKey("/BBox", QPDFObjectHandle::parse("[ 0 0 20 20 ]")); + apdict.replaceKey("/Resources", "<< >>"_qpdf""); + apdict.replaceKey("/Type", "/XObject"_qpdf); + apdict.replaceKey("/Subtype", "/Form"_qpdf); apdict.replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf); auto annot = q.makeIndirectObject( QPDFObjectHandle::parse( |