summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-02-05 15:18:58 +0100
committerJay Berkenbilt <ejb@ql.org>2022-02-05 17:29:25 +0100
commit7fb22740e131d997fb68bc113b8d9b4472e2c908 (patch)
tree93da9a3babdf591fa1cc286f71fb3d6f2277fa30 /examples
parentb48a0ff0e8e1861884b2dac62d98d39f8e194086 (diff)
downloadqpdf-7fb22740e131d997fb68bc113b8d9b4472e2c908.tar.zst
Add operator ""_qpdf for creating QPDFObjectHandle literals
Diffstat (limited to 'examples')
-rw-r--r--examples/pdf-attach-file.cc20
-rw-r--r--examples/pdf-create.cc29
-rw-r--r--examples/pdf-overlay-page.cc3
3 files changed, 24 insertions, 28 deletions
diff --git a/examples/pdf-attach-file.cc b/examples/pdf-attach-file.cc
index 0c046000..decc742f 100644
--- a/examples/pdf-attach-file.cc
+++ b/examples/pdf-attach-file.cc
@@ -36,16 +36,16 @@ static void process(char const* infilename, char const* password,
QPDF q;
q.processFile(infilename, password);
- // Create an indirect object for the built-in Helvetica font.
+ // Create an indirect object for the built-in Helvetica font. This
+ // uses the qpdf literal syntax introduced in qpdf 10.6.
auto f1 = q.makeIndirectObject(
- QPDFObjectHandle::parse(
- "<<"
- " /Type /Font"
- " /Subtype /Type1"
- " /Name /F1"
- " /BaseFont /Helvetica"
- " /Encoding /WinAnsiEncoding"
- ">>"));
+ "<<"
+ " /Type /Font"
+ " /Subtype /Type1"
+ " /Name /F1"
+ " /BaseFont /Helvetica"
+ " /Encoding /WinAnsiEncoding"
+ ">>"_qpdf);
// Create a resources dictionary with fonts. This uses the new
// parse introduced in qpdf 10.2 that takes a QPDF* and allows
@@ -93,7 +93,7 @@ static void process(char const* infilename, char const* password,
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("/BBox", "[ 0 0 20 20 ]"_qpdf);
auto annot = q.makeIndirectObject(
QPDFObjectHandle::parse(
&q,
diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc
index 52f02a0d..8d1e8ee6 100644
--- a/examples/pdf-create.cc
+++ b/examples/pdf-create.cc
@@ -182,12 +182,11 @@ void add_page(QPDFPageDocumentHelper& dh, QPDFObjectHandle font,
size_t width = p->getWidth();
size_t height = p->getHeight();
QPDFObjectHandle image = QPDFObjectHandle::newStream(&pdf);
- image.replaceDict(QPDFObjectHandle::parse(
- "<<"
- " /Type /XObject"
- " /Subtype /Image"
- " /BitsPerComponent 8"
- ">>"));
+ image.replaceDict("<<"
+ " /Type /XObject"
+ " /Subtype /Image"
+ " /BitsPerComponent 8"
+ ">>"_qpdf);
QPDFObjectHandle image_dict = image.getDict();
image_dict.replaceKey("/ColorSpace", newName(color_space));
image_dict.replaceKey("/Width", newInteger(width));
@@ -199,8 +198,7 @@ void add_page(QPDFPageDocumentHelper& dh, QPDFObjectHandle font,
QPDFObjectHandle::newNull());
// Create direct objects as needed by the page dictionary.
- QPDFObjectHandle procset = QPDFObjectHandle::parse(
- "[/PDF /Text /ImageC]");
+ QPDFObjectHandle procset = "[/PDF /Text /ImageC]"_qpdf;
QPDFObjectHandle rfont = QPDFObjectHandle::newDictionary();
rfont.replaceKey("/F1", font);
@@ -384,14 +382,13 @@ static void create_pdf(char const* filename)
// Add an indirect object to contain a font descriptor for the
// built-in Helvetica font.
QPDFObjectHandle font = pdf.makeIndirectObject(
- QPDFObjectHandle::parse(
- "<<"
- " /Type /Font"
- " /Subtype /Type1"
- " /Name /F1"
- " /BaseFont /Helvetica"
- " /Encoding /WinAnsiEncoding"
- ">>"));
+ "<<"
+ " /Type /Font"
+ " /Subtype /Type1"
+ " /Name /F1"
+ " /BaseFont /Helvetica"
+ " /Encoding /WinAnsiEncoding"
+ ">>"_qpdf);
std::vector<std::string> color_spaces;
color_spaces.push_back("/DeviceCMYK");
diff --git a/examples/pdf-overlay-page.cc b/examples/pdf-overlay-page.cc
index 1e06c40c..7b8888e4 100644
--- a/examples/pdf-overlay-page.cc
+++ b/examples/pdf-overlay-page.cc
@@ -65,8 +65,7 @@ static void stamp_page(char const* infile,
// Append the content to the page's content. Surround the
// original content with q...Q to the new content from the
// page's original content.
- resources.mergeResources(
- QPDFObjectHandle::parse("<< /XObject << >> >>"));
+ resources.mergeResources("<< /XObject << >> >>"_qpdf);
resources.getKey("/XObject").replaceKey(name, stamp_fo);
ph.addPageContents(
QPDFObjectHandle::newStream(&inpdf, "q\n"), true);