Commit 527810e939816190e491db7c0a308100d255da85
Committed by
Jay Berkenbilt
1 parent
56b4d5a6
Tidy pdf-attach-file example
Showing
1 changed file
with
14 additions
and
6 deletions
examples/pdf-attach-file.cc
| ... | ... | @@ -11,7 +11,8 @@ |
| 11 | 11 | // This example attaches a file to an input file, adds a page to the |
| 12 | 12 | // beginning of the file that includes a file attachment annotation, |
| 13 | 13 | // and writes the result to an output file. It also illustrates a |
| 14 | -// number of new API calls that were added in qpdf 10.2. | |
| 14 | +// number of new API calls that were added in qpdf 10.2 as well as | |
| 15 | +// the use of the qpdf literal syntax introduced in qpdf 10.6. | |
| 15 | 16 | // |
| 16 | 17 | |
| 17 | 18 | static char const* whoami = 0; |
| ... | ... | @@ -24,8 +25,8 @@ static void usage(std::string const& msg) |
| 24 | 25 | << " --infile infile.pdf" << std::endl |
| 25 | 26 | << " --outfile outfile.pdf" << std::endl |
| 26 | 27 | << " --attachment attachment" << std::endl |
| 27 | - << " [ --password infile-password ]" << std::endl | |
| 28 | - << " [ --mimetype attachment mime type ]" << std::endl; | |
| 28 | + << " [--password infile-password]" << std::endl | |
| 29 | + << " [--mimetype attachment mime type]" << std::endl; | |
| 29 | 30 | exit(2); |
| 30 | 31 | } |
| 31 | 32 | |
| ... | ... | @@ -90,9 +91,16 @@ static void process(char const* infilename, char const* password, |
| 90 | 91 | "0 0 20 20 re\n" |
| 91 | 92 | "S\n"); |
| 92 | 93 | auto apdict = ap.getDict(); |
| 93 | - apdict.replaceKey("/Resources", QPDFObjectHandle::newDictionary()); | |
| 94 | - apdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); | |
| 95 | - apdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); | |
| 94 | + | |
| 95 | + // The following four lines demonstrate the use of the qpdf literal syntax | |
| 96 | + // introduced in qpdf 10.6. They could have been written as: | |
| 97 | + // apdict.replaceKey("/Resources", QPDFObjectHandle::newDictionary()); | |
| 98 | + // apdict.replaceKey("/Type", QPDFObjectHandle::newName("/XObject")); | |
| 99 | + // apdict.replaceKey("/Subtype", QPDFObjectHandle::newName("/Form")); | |
| 100 | + // apdict.replaceKey("/BBox", QPDFObjectHandle::parse("[ 0 0 20 20 ]")); | |
| 101 | + apdict.replaceKey("/Resources", "<< >>"_qpdf""); | |
| 102 | + apdict.replaceKey("/Type", "/XObject"_qpdf); | |
| 103 | + apdict.replaceKey("/Subtype", "/Form"_qpdf); | |
| 96 | 104 | apdict.replaceKey("/BBox", "[ 0 0 20 20 ]"_qpdf); |
| 97 | 105 | auto annot = q.makeIndirectObject( |
| 98 | 106 | QPDFObjectHandle::parse( | ... | ... |