summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2023-05-21 19:35:09 +0200
committerJay Berkenbilt <ejb@ql.org>2023-05-21 19:35:09 +0200
commit60965d5f4d608bdccc2ffd4e8753e12cbbbd71d2 (patch)
treea707602da466c02ff1a54b3263c3a881cd7204a4 /examples
parent6b077332d38c093de2618d5e1481b42222106065 (diff)
downloadqpdf-60965d5f4d608bdccc2ffd4e8753e12cbbbd71d2.tar.zst
Rerun clang-format
Diffstat (limited to 'examples')
-rw-r--r--examples/pdf-attach-file.cc3
-rw-r--r--examples/pdf-bookmarks.cc25
-rw-r--r--examples/pdf-c-objects.c14
-rw-r--r--examples/pdf-count-strings.cc3
-rw-r--r--examples/pdf-create.cc35
-rw-r--r--examples/pdf-custom-filter.cc33
-rw-r--r--examples/pdf-double-page-size.cc18
-rw-r--r--examples/pdf-filter-tokens.cc23
-rw-r--r--examples/pdf-invert-images.cc30
-rw-r--r--examples/pdf-linearize.c8
-rw-r--r--examples/pdf-mod-info.cc9
-rw-r--r--examples/pdf-name-number-tree.cc32
-rw-r--r--examples/pdf-overlay-page.cc7
-rw-r--r--examples/pdf-parse-content.cc9
-rw-r--r--examples/pdf-set-form-values.cc12
-rw-r--r--examples/pdf-split-pages.cc6
-rw-r--r--examples/qpdfjob-c-save-attachment.c3
-rw-r--r--examples/qpdfjob-remove-annotations.cc13
-rw-r--r--examples/qpdfjob-save-attachment.cc3
19 files changed, 96 insertions, 190 deletions
diff --git a/examples/pdf-attach-file.cc b/examples/pdf-attach-file.cc
index 9cb55741..b5a1c64a 100644
--- a/examples/pdf-attach-file.cc
+++ b/examples/pdf-attach-file.cc
@@ -71,8 +71,7 @@ process(
// Create a file spec.
std::string key = QUtil::path_basename(attachment);
- std::cout << whoami << ": attaching " << attachment << " as " << key
- << std::endl;
+ std::cout << whoami << ": attaching " << attachment << " as " << key << std::endl;
auto fs = QPDFFileSpecObjectHelper::createFileSpec(q, key, attachment);
if (mimetype) {
diff --git a/examples/pdf-bookmarks.cc b/examples/pdf-bookmarks.cc
index 8128fed1..d40ded6a 100644
--- a/examples/pdf-bookmarks.cc
+++ b/examples/pdf-bookmarks.cc
@@ -23,16 +23,12 @@ static std::map<QPDFObjGen, int> page_map;
void
usage()
{
- std::cerr
- << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl
- << "Options:" << std::endl
- << " --numbers give bookmarks outline-style numbers"
- << std::endl
- << " --lines draw lines to show bookmark hierarchy"
- << std::endl
- << " --show-open indicate whether a bookmark is initially open"
- << std::endl
- << " --show-targets show target if possible" << std::endl;
+ std::cerr << "Usage: " << whoami << " [options] file.pdf [password]" << std::endl
+ << "Options:" << std::endl
+ << " --numbers give bookmarks outline-style numbers" << std::endl
+ << " --lines draw lines to show bookmark hierarchy" << std::endl
+ << " --show-open indicate whether a bookmark is initially open" << std::endl
+ << " --show-targets show target if possible" << std::endl;
exit(2);
}
@@ -120,16 +116,14 @@ show_bookmark_details(QPDFOutlineObjectHelper outline, std::vector<int> numbers)
}
void
-extract_bookmarks(
- std::vector<QPDFOutlineObjectHelper> outlines, std::vector<int>& numbers)
+extract_bookmarks(std::vector<QPDFOutlineObjectHelper> outlines, std::vector<int>& numbers)
{
// For style == st_numbers, numbers.at(n) contains the numerical
// label for the outline, so we count up from 1.
// For style == st_lines, numbers.at(n) == 0 indicates the last
// outline at level n, and we don't otherwise care what the value
// is, so we count up to zero.
- numbers.push_back(
- (style == st_lines) ? -QIntC::to_int(outlines.size()) : 0);
+ numbers.push_back((style == st_lines) ? -QIntC::to_int(outlines.size()) : 0);
for (auto& outline: outlines) {
++(numbers.back());
show_bookmark_details(outline, numbers);
@@ -196,8 +190,7 @@ main(int argc, char* argv[])
std::cout << filename << " has no bookmarks" << std::endl;
}
} catch (std::exception& e) {
- std::cerr << whoami << " processing file " << filename << ": "
- << e.what() << std::endl;
+ std::cerr << whoami << " processing file " << filename << ": " << e.what() << std::endl;
exit(2);
}
diff --git a/examples/pdf-c-objects.c b/examples/pdf-c-objects.c
index 78a4a746..f4b872a7 100644
--- a/examples/pdf-c-objects.c
+++ b/examples/pdf-c-objects.c
@@ -33,8 +33,7 @@ modify_file(qpdf_data qpdf)
qpdf_oh_remove_key(qpdf, root, "/OpenAction");
/* 0 is never a valid qpdf_oh */
qpdf_oh pagemode = 0;
- if (qpdf_oh_is_dictionary(
- qpdf, qpdf_oh_get_key(qpdf, root, "/PageLabels"))) {
+ if (qpdf_oh_is_dictionary(qpdf, qpdf_oh_get_key(qpdf, root, "/PageLabels"))) {
pagemode = qpdf_oh_new_name(qpdf, "/UseOutlines");
} else {
pagemode = qpdf_oh_new_null(qpdf);
@@ -71,8 +70,7 @@ main(int argc, char* argv[])
password = argv[2];
outfile = argv[3];
- if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
- modify_file(qpdf) &&
+ if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && modify_file(qpdf) &&
((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) {
/* Use static ID for testing only. For production, a
* non-static ID is used. See also
@@ -82,15 +80,11 @@ main(int argc, char* argv[])
}
while (qpdf_more_warnings(qpdf)) {
warnings = 1;
- printf(
- "warning: %s\n",
- qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
+ printf("warning: %s\n", qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
}
if (qpdf_has_error(qpdf)) {
errors = 1;
- printf(
- "error: %s\n",
- qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
+ printf("error: %s\n", qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
}
qpdf_cleanup(&qpdf);
if (errors) {
diff --git a/examples/pdf-count-strings.cc b/examples/pdf-count-strings.cc
index e9eb827d..c70e183e 100644
--- a/examples/pdf-count-strings.cc
+++ b/examples/pdf-count-strings.cc
@@ -97,8 +97,7 @@ main(int argc, char* argv[])
page.filterContents(&counter, &out);
std::cout << "\n% end " << pageno << std::endl;
}
- std::cout << "Page " << pageno
- << ": strings = " << counter.getCount() << std::endl;
+ std::cout << "Page " << pageno << ": strings = " << counter.getCount() << std::endl;
}
} catch (std::exception& e) {
std::cerr << whoami << ": " << e.what() << std::endl;
diff --git a/examples/pdf-create.cc b/examples/pdf-create.cc
index 641572d0..e0fa93b1 100644
--- a/examples/pdf-create.cc
+++ b/examples/pdf-create.cc
@@ -41,8 +41,7 @@ class ImageProvider: public QPDFObjectHandle::StreamDataProvider
J_COLOR_SPACE j_color_space;
};
-ImageProvider::ImageProvider(
- std::string const& color_space, std::string const& filter) :
+ImageProvider::ImageProvider(std::string const& color_space, std::string const& filter) :
width(400),
stripe_height(80),
color_space(color_space),
@@ -107,8 +106,7 @@ ImageProvider::provideStreamData(QPDFObjGen const&, Pipeline* pipeline)
to_delete.push_back(p_new);
p = p_new.get();
} else if (filter == "/RunLengthDecode") {
- p_new = std::make_shared<Pl_RunLength>(
- "image encoder", pipeline, Pl_RunLength::a_encode);
+ p_new = std::make_shared<Pl_RunLength>("image encoder", pipeline, Pl_RunLength::a_encode);
to_delete.push_back(p_new);
p = p_new.get();
}
@@ -184,8 +182,7 @@ add_page(
image.replaceDict(image_dict);
// Provide the stream data.
- image.replaceStreamData(
- provider, QPDFObjectHandle::parse(filter), QPDFObjectHandle::newNull());
+ image.replaceStreamData(provider, QPDFObjectHandle::parse(filter), QPDFObjectHandle::newNull());
// Create direct objects as needed by the page dictionary.
QPDFObjectHandle procset = "[/PDF /Text /ImageC]"_qpdf;
@@ -202,8 +199,7 @@ add_page(
resources.replaceKey("/XObject", xobject);
// Create the page content stream
- QPDFObjectHandle contents =
- createPageContents(pdf, color_space + " with filter " + filter);
+ QPDFObjectHandle contents = createPageContents(pdf, color_space + " with filter " + filter);
// Create the page dictionary
QPDFObjectHandle page = pdf.makeIndirectObject("<<"
@@ -256,8 +252,7 @@ check(
}
// Check filter and color space.
- std::string desired_color_space =
- color_spaces[(pageno - 1) / n_color_spaces];
+ std::string desired_color_space = color_spaces[(pageno - 1) / n_color_spaces];
std::string desired_filter = filters[(pageno - 1) % n_filters];
// In the default mode, QPDFWriter will compress with
// /FlateDecode if no filters are provided.
@@ -271,16 +266,13 @@ check(
bool this_errors = false;
if (!filter.isNameAndEquals(desired_filter)) {
this_errors = errors = true;
- std::cout << "page " << pageno << ": expected filter "
- << desired_filter
+ std::cout << "page " << pageno << ": expected filter " << desired_filter
<< "; actual filter = " << filter.unparse() << std::endl;
}
if (!color_space.isNameAndEquals(desired_color_space)) {
this_errors = errors = true;
- std::cout << "page " << pageno << ": expected color space "
- << desired_color_space
- << "; actual color space = " << color_space.unparse()
- << std::endl;
+ std::cout << "page " << pageno << ": expected color space " << desired_color_space
+ << "; actual color space = " << color_space.unparse() << std::endl;
}
if (!this_errors) {
@@ -293,8 +285,7 @@ check(
std::shared_ptr<Buffer> desired_data(b_p.getBuffer());
if (desired_data->getSize() != actual_data->getSize()) {
- std::cout << "page " << pageno << ": image data length mismatch"
- << std::endl;
+ std::cout << "page " << pageno << ": image data length mismatch" << std::endl;
this_errors = errors = true;
} else {
// Compare bytes. For JPEG, allow a certain number of
@@ -308,8 +299,7 @@ check(
size_t len = actual_data->getSize();
unsigned int mismatches = 0;
int tolerance = (desired_filter == "/DCTDecode" ? 10 : 0);
- size_t threshold =
- (desired_filter == "/DCTDecode" ? len / 40U : 0);
+ size_t threshold = (desired_filter == "/DCTDecode" ? len / 40U : 0);
for (size_t i = 0; i < len; ++i) {
int delta = actual_bytes[i] - desired_bytes[i];
if ((delta > tolerance) || (delta < -tolerance)) {
@@ -317,9 +307,8 @@ check(
}
}
if (mismatches > threshold) {
- std::cout << "page " << pageno << ": "
- << desired_color_space << ", " << desired_filter
- << ": mismatches: " << mismatches << " of " << len
+ std::cout << "page " << pageno << ": " << desired_color_space << ", "
+ << desired_filter << ": mismatches: " << mismatches << " of " << len
<< std::endl;
this_errors = errors = true;
}
diff --git a/examples/pdf-custom-filter.cc b/examples/pdf-custom-filter.cc
index c2d4a441..57eedf74 100644
--- a/examples/pdf-custom-filter.cc
+++ b/examples/pdf-custom-filter.cc
@@ -132,8 +132,7 @@ SF_XORDecode::setDecodeParms(QPDFObjectHandle decode_parms)
this->key = buf->getBuffer()[0];
return true;
} catch (std::exception& e) {
- std::cerr << "Error extracting key for /XORDecode: " << e.what()
- << std::endl;
+ std::cerr << "Error extracting key for /XORDecode: " << e.what() << std::endl;
}
return false;
}
@@ -203,8 +202,7 @@ class StreamReplacer: public QPDFObjectHandle::StreamDataProvider
void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override;
void registerStream(
- QPDFObjectHandle stream,
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self);
+ QPDFObjectHandle stream, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self);
private:
bool maybeReplace(
@@ -300,12 +298,10 @@ StreamReplacer::maybeReplace(
// changes. For example, an image resampler might change the
// dimensions or other properties of the image.
dict_updates->replaceKey(
- "/OrigLength",
- QPDFObjectHandle::newInteger(QIntC::to_longlong(out->getSize())));
+ "/OrigLength", QPDFObjectHandle::newInteger(QIntC::to_longlong(out->getSize())));
// We are also storing the "key" that we will access when
// writing the data.
- this->keys[og] = QIntC::to_uchar(
- (og.getObj() * QIntC::to_int(out->getSize())) & 0xff);
+ this->keys[og] = QIntC::to_uchar((og.getObj() * QIntC::to_int(out->getSize())) & 0xff);
}
if (pipeline) {
@@ -319,8 +315,7 @@ StreamReplacer::maybeReplace(
void
StreamReplacer::registerStream(
- QPDFObjectHandle stream,
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self)
+ QPDFObjectHandle stream, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self)
{
QPDFObjGen og(stream.getObjGen());
@@ -344,8 +339,7 @@ StreamReplacer::registerStream(
try {
should_replace = maybeReplace(og, stream, nullptr, &dict_updates);
} catch (std::exception& e) {
- stream.warnIfPossible(
- std::string("exception while attempting to replace: ") + e.what());
+ stream.warnIfPossible(std::string("exception while attempting to replace: ") + e.what());
}
if (should_replace) {
@@ -369,8 +363,7 @@ StreamReplacer::registerStream(
// /XORDecode filter.
QPDFObjectHandle decode_parms =
QPDFObjectHandle::newDictionary({{"/KeyStream", dp_stream}});
- stream.replaceStreamData(
- self, QPDFObjectHandle::newName("/XORDecode"), decode_parms);
+ stream.replaceStreamData(self, QPDFObjectHandle::newName("/XORDecode"), decode_parms);
// Further, if /ProtectXOR = true, we disable filtering on write
// so that QPDFWriter will not decode the stream even though we
// have registered a stream filter for /XORDecode.
@@ -393,14 +386,12 @@ StreamReplacer::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline)
// Since this only gets called for streams we already
// determined we are replacing, a false return would indicate
// a logic error.
- throw std::logic_error(
- "should_replace return false in provideStreamData");
+ throw std::logic_error("should_replace return false in provideStreamData");
}
}
static void
-process(
- char const* infilename, char const* outfilename, bool decode_specialized)
+process(char const* infilename, char const* outfilename, bool decode_specialized)
{
QPDF qpdf;
qpdf.processFile(infilename);
@@ -434,8 +425,7 @@ static void
usage()
{
std::cerr << "\n"
- << "Usage: " << whoami
- << " [--decode-specialized] infile outfile\n"
+ << "Usage: " << whoami << " [--decode-specialized] infile outfile\n"
<< std::endl;
exit(2);
}
@@ -468,8 +458,7 @@ main(int argc, char* argv[])
// decode our streams. This is not a real filter, so no real
// PDF reading application would be able to interpret it. This
// is just for illustrative purposes.
- QPDF::registerStreamFilter(
- "/XORDecode", [] { return std::make_shared<SF_XORDecode>(); });
+ QPDF::registerStreamFilter("/XORDecode", [] { return std::make_shared<SF_XORDecode>(); });
// Do the actual processing.
process(infilename, outfilename, decode_specialized);
} catch (std::exception& e) {
diff --git a/examples/pdf-double-page-size.cc b/examples/pdf-double-page-size.cc
index 1c9cb3e5..6e1b4f8b 100644
--- a/examples/pdf-double-page-size.cc
+++ b/examples/pdf-double-page-size.cc
@@ -13,8 +13,7 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]"
- << std::endl
+ std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl
<< "Double size of all pages in infile.pdf;"
<< " write output to outfile.pdf" << std::endl;
exit(2);
@@ -33,16 +32,13 @@ doubleBoxSize(QPDFPageObjectHelper& page, char const* box_name)
}
if (!box.isRectangle()) {
throw std::runtime_error(
- std::string("box ") + box_name +
- " is not an array of four elements");
+ std::string("box ") + box_name + " is not an array of four elements");
}
std::vector<QPDFObjectHandle> doubled;
for (auto& item: box.aitems()) {
- doubled.push_back(
- QPDFObjectHandle::newReal(item.getNumericValue() * 2.0, 2));
+ doubled.push_back(QPDFObjectHandle::newReal(item.getNumericValue() * 2.0, 2));
}
- page.getObjectHandle().replaceKey(
- box_name, QPDFObjectHandle::newArray(doubled));
+ page.getObjectHandle().replaceKey(box_name, QPDFObjectHandle::newArray(doubled));
}
int
@@ -93,11 +89,9 @@ main(int argc, char* argv[])
w.setStreamDataMode(qpdf_s_uncompress);
}
w.write();
- std::cout << whoami << ": new file written to " << outfilename
- << std::endl;
+ std::cout << whoami << ": new file written to " << outfilename << std::endl;
} catch (std::exception& e) {
- std::cerr << whoami << " processing file " << infilename << ": "
- << e.what() << std::endl;
+ std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
exit(2);
}
diff --git a/examples/pdf-filter-tokens.cc b/examples/pdf-filter-tokens.cc
index 9cfd3949..68d6e149 100644
--- a/examples/pdf-filter-tokens.cc
+++ b/examples/pdf-filter-tokens.cc
@@ -22,8 +22,7 @@ void
usage()
{
std::cerr << "Usage: " << whoami << " infile outfile" << std::endl
- << "Applies token filters to infile and writes outfile"
- << std::endl;
+ << "Applies token filters to infile and writes outfile" << std::endl;
exit(2);
}
@@ -82,17 +81,13 @@ class ColorToGray: public QPDFObjectHandle::TokenFilter
bool
ColorToGray::isNumeric(QPDFTokenizer::token_type_e token_type)
{
- return (
- (token_type == QPDFTokenizer::tt_integer) ||
- (token_type == QPDFTokenizer::tt_real));
+ return ((token_type == QPDFTokenizer::tt_integer) || (token_type == QPDFTokenizer::tt_real));
}
bool
ColorToGray::isIgnorable(QPDFTokenizer::token_type_e token_type)
{
- return (
- (token_type == QPDFTokenizer::tt_space) ||
- (token_type == QPDFTokenizer::tt_comment));
+ return ((token_type == QPDFTokenizer::tt_space) || (token_type == QPDFTokenizer::tt_comment));
}
double
@@ -128,8 +123,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const& token)
// kinds of operands, replace the command. Flush any additional
// accumulated tokens to keep the stack only four tokens deep.
- while ((!this->all_stack.empty()) &&
- isIgnorable(this->all_stack.at(0).getType())) {
+ while ((!this->all_stack.empty()) && isIgnorable(this->all_stack.at(0).getType())) {
writeToken(this->all_stack.at(0));
this->all_stack.pop_front();
}
@@ -138,8 +132,7 @@ ColorToGray::handleToken(QPDFTokenizer::Token const& token)
if (!isIgnorable(token_type)) {
this->stack.push_back(token);
if ((this->stack.size() == 4) && token.isWord("rg") &&
- (isNumeric(this->stack.at(0).getType())) &&
- (isNumeric(this->stack.at(1).getType())) &&
+ (isNumeric(this->stack.at(0).getType())) && (isNumeric(this->stack.at(1).getType())) &&
(isNumeric(this->stack.at(2).getType()))) {
double r = numericValue(this->stack.at(0));
double g = numericValue(this->stack.at(1));
@@ -195,11 +188,9 @@ main(int argc, char* argv[])
// applied. See comments on the filters for additional
// details.
page.addContentTokenFilter(
- std::shared_ptr<QPDFObjectHandle::TokenFilter>(
- new StringReverser));
+ std::shared_ptr<QPDFObjectHandle::TokenFilter>(new StringReverser));
page.addContentTokenFilter(
- std::shared_ptr<QPDFObjectHandle::TokenFilter>(
- new ColorToGray));
+ std::shared_ptr<QPDFObjectHandle::TokenFilter>(new ColorToGray));
}
QPDFWriter w(pdf, outfilename);
diff --git a/examples/pdf-invert-images.cc b/examples/pdf-invert-images.cc
index a7fa15fd..5692e7b2 100644
--- a/examples/pdf-invert-images.cc
+++ b/examples/pdf-invert-images.cc
@@ -14,8 +14,7 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]"
- << std::endl
+ std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf [in-password]" << std::endl
<< "Invert some images in infile.pdf;"
<< " write output to outfile.pdf" << std::endl;
exit(2);
@@ -37,8 +36,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider
void provideStreamData(QPDFObjGen const& og, Pipeline* pipeline) override;
void registerImage(
- QPDFObjectHandle image,
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self);
+ QPDFObjectHandle image, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self);
private:
std::map<QPDFObjGen, QPDFObjectHandle> copied_images;
@@ -46,8 +44,7 @@ class ImageInverter: public QPDFObjectHandle::StreamDataProvider
void
ImageInverter::registerImage(
- QPDFObjectHandle image,
- std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self)
+ QPDFObjectHandle image, std::shared_ptr<QPDFObjectHandle::StreamDataProvider> self)
{
// replaceStreamData requires a pointer holder to the stream data
// provider, but there's no way for us to generate one ourselves,
@@ -76,8 +73,7 @@ ImageInverter::registerImage(
// filterable in the input QPDF object, so we don't have to deal
// with it explicitly here. We could explicitly use /DCTDecode and
// write through a DCT filter if we wanted.
- image.replaceStreamData(
- self, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
+ image.replaceStreamData(self, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull());
}
void
@@ -86,8 +82,7 @@ ImageInverter::provideStreamData(QPDFObjGen const& og, Pipeline* pipeline)
// Use the object and generation number supplied to look up the
// image data. Then invert the image data and write the inverted
// data to the pipeline.
- std::shared_ptr<Buffer> data =
- this->copied_images[og].getStreamData(qpdf_dl_all);
+ std::shared_ptr<Buffer> data = this->copied_images[og].getStreamData(qpdf_dl_all);
size_t size = data->getSize();
unsigned char* buf = data->getBuffer();
unsigned char ch;
@@ -133,18 +128,15 @@ main(int argc, char* argv[])
QPDFObjectHandle& image = iter.second;
QPDFObjectHandle image_dict = image.getDict();
QPDFObjectHandle color_space = image_dict.getKey("/ColorSpace");
- QPDFObjectHandle bits_per_component =
- image_dict.getKey("/BitsPerComponent");
+ QPDFObjectHandle bits_per_component = image_dict.getKey("/BitsPerComponent");
// For our example, we can only work with images 8-bit
// grayscale images that we can fully decode. Use
// pipeStreamData with a null pipeline to determine
// whether the image is filterable. Directly inspect
// keys to determine the image type.
- if (image.pipeStreamData(
- nullptr, qpdf_ef_compress, qpdf_dl_all) &&
- color_space.isNameAndEquals("/DeviceGray") &&
- bits_per_component.isInteger() &&
+ if (image.pipeStreamData(nullptr, qpdf_ef_compress, qpdf_dl_all) &&
+ color_space.isNameAndEquals("/DeviceGray") && bits_per_component.isInteger() &&
(bits_per_component.getIntValue() == 8)) {
inv->registerImage(image, p);
}
@@ -159,11 +151,9 @@ main(int argc, char* argv[])
w.setStaticID(true); // for testing only
}
w.write();
- std::cout << whoami << ": new file written to " << outfilename
- << std::endl;
+ std::cout << whoami << ": new file written to " << outfilename << std::endl;
} catch (std::exception& e) {
- std::cerr << whoami << " processing file " << infilename << ": "
- << e.what() << std::endl;
+ std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
exit(2);
}
diff --git a/examples/pdf-linearize.c b/examples/pdf-linearize.c
index f972fa71..3a7a335d 100644
--- a/examples/pdf-linearize.c
+++ b/examples/pdf-linearize.c
@@ -61,15 +61,11 @@ main(int argc, char* argv[])
}
while (qpdf_more_warnings(qpdf)) {
warnings = 1;
- printf(
- "warning: %s\n",
- qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
+ printf("warning: %s\n", qpdf_get_error_full_text(qpdf, qpdf_next_warning(qpdf)));
}
if (qpdf_has_error(qpdf)) {
errors = 1;
- printf(
- "error: %s\n",
- qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
+ printf("error: %s\n", qpdf_get_error_full_text(qpdf, qpdf_get_error(qpdf)));
}
qpdf_cleanup(&qpdf);
if (errors) {
diff --git a/examples/pdf-mod-info.cc b/examples/pdf-mod-info.cc
index a77070d2..3a9671e1 100644
--- a/examples/pdf-mod-info.cc
+++ b/examples/pdf-mod-info.cc
@@ -16,8 +16,7 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami
- << " --in in_file [--out out_file] [--key key [--val val]?]+\n"
+ std::cerr << "Usage: " << whoami << " --in in_file [--out out_file] [--key key [--val val]?]+\n"
<< "Modifies/Adds/Removes PDF /Info entries in the in_file\n"
<< "and stores the result in out_file\n"
<< "Special mode: " << whoami << " --dump file\n"
@@ -26,8 +25,7 @@ usage()
}
void
-dumpInfoDict(
- QPDF& pdf, std::ostream& os = std::cout, std::string const& sep = ":\t")
+dumpInfoDict(QPDF& pdf, std::ostream& os = std::cout, std::string const& sep = ":\t")
{
QPDFObjectHandle trailer = pdf.getTrailer();
if (trailer.hasKey("/Info")) {
@@ -164,8 +162,7 @@ main(int argc, char* argv[])
try {
(void)remove(fl_out);
QUtil::os_wrapper(
- "rename " + fl_tmp + " " + std::string(fl_out),
- rename(fl_tmp.c_str(), fl_out));
+ "rename " + fl_tmp + " " + std::string(fl_out), rename(fl_tmp.c_str(), fl_out));
} catch (std::exception& e) {
std::cerr << e.what() << std::endl;
exit(2);
diff --git a/examples/pdf-name-number-tree.cc b/examples/pdf-name-number-tree.cc
index e1dfde05..a14ad126 100644
--- a/examples/pdf-name-number-tree.cc
+++ b/examples/pdf-name-number-tree.cc
@@ -11,8 +11,7 @@ void
usage()
{
std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl
- << "Create some name/number trees and write to a file"
- << std::endl;
+ << "Create some name/number trees and write to a file" << std::endl;
exit(2);
}
@@ -61,24 +60,19 @@ main(int argc, char* argv[])
name_tree.insert("R", QPDFObjectHandle::newUnicodeString("rook"));
name_tree.insert("B", QPDFObjectHandle::newUnicodeString("bishop"));
name_tree.insert("N", QPDFObjectHandle::newUnicodeString("knight"));
- auto iter =
- name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn"));
+ auto iter = name_tree.insert("P", QPDFObjectHandle::newUnicodeString("pawn"));
// Look at the iterator
- std::cout << "just inserted " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "just inserted " << iter->first << " -> " << iter->second.unparse() << std::endl;
--iter;
- std::cout << "predecessor: " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "predecessor: " << iter->first << " -> " << iter->second.unparse() << std::endl;
++iter;
++iter;
- std::cout << "successor: " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "successor: " << iter->first << " -> " << iter->second.unparse() << std::endl;
// Use range-for iteration
std::cout << "Name tree items:" << std::endl;
for (auto i: name_tree) {
- std::cout << " " << i.first << " -> " << i.second.unparse()
- << std::endl;
+ std::cout << " " << i.first << " -> " << i.second.unparse() << std::endl;
}
// This is a small tree, so everything will be at the root. We can
@@ -107,14 +101,13 @@ main(int argc, char* argv[])
// 10.2 API
iter = name_tree.find("Q");
- std::cout << "Q: " << iter->first << " -> " << iter->second.unparse()
- << std::endl;
+ std::cout << "Q: " << iter->first << " -> " << iter->second.unparse() << std::endl;
iter = name_tree.find("W");
std::cout << "W found: " << (iter != name_tree.end()) << std::endl;
// Allow find to return predecessor
iter = name_tree.find("W", true);
- std::cout << "W's predecessor: " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "W's predecessor: " << iter->first << " -> " << iter->second.unparse()
+ << std::endl;
// We can also remove items
std::cout << "Remove P: " << name_tree.remove("P", &obj) << std::endl;
@@ -124,8 +117,8 @@ main(int argc, char* argv[])
iter = name_tree.find("K");
std::cout << "Find K: " << iter->second.unparse() << std::endl;
iter.remove();
- std::cout << "Iter after removing K: " << iter->first << " -> "
- << iter->second.unparse() << std::endl;
+ std::cout << "Iter after removing K: " << iter->first << " -> " << iter->second.unparse()
+ << std::endl;
std::cout << "Has K?: " << name_tree.hasName("K") << std::endl;
// Illustrate some more advanced usage using number trees. These
@@ -142,8 +135,7 @@ main(int argc, char* argv[])
example.replaceKey("/NumberTree", number_tree_oh);
auto iter2 = number_tree.begin();
for (int i = 7; i <= 350; i += 7) {
- iter2.insertAfter(
- i, QPDFObjectHandle::newString("-" + std::to_string(i) + "-"));
+ iter2.insertAfter(i, QPDFObjectHandle::newString("-" + std::to_string(i) + "-"));
}
std::cout << "Numbers:" << std::endl;
int n = 1;
diff --git a/examples/pdf-overlay-page.cc b/examples/pdf-overlay-page.cc
index 5b74d58b..6d1cd0b0 100644
--- a/examples/pdf-overlay-page.cc
+++ b/examples/pdf-overlay-page.cc
@@ -31,8 +31,7 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
stamppdf.processFile(stampfile);
// Get first page from other file
- QPDFPageObjectHelper stamp_page_1 =
- QPDFPageDocumentHelper(stamppdf).getAllPages().at(0);
+ QPDFPageObjectHelper stamp_page_1 = QPDFPageDocumentHelper(stamppdf).getAllPages().at(0);
// Convert page to a form XObject
QPDFObjectHandle foreign_fo = stamp_page_1.getFormXObjectForPage();
// Copy form XObject to the input file
@@ -48,8 +47,8 @@ stamp_page(char const* infile, char const* stampfile, char const* outfile)
// Generate content to place the form XObject centered within
// destination page's trim box.
QPDFMatrix m;
- std::string content = ph.placeFormXObject(
- stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m);
+ std::string content =
+ ph.placeFormXObject(stamp_fo, name, ph.getTrimBox().getArrayAsRectangle(), m);
if (!content.empty()) {
// Append the content to the page's content. Surround the
// original content with q...Q to the new content from the
diff --git a/examples/pdf-parse-content.cc b/examples/pdf-parse-content.cc
index 888656e5..743986a1 100644
--- a/examples/pdf-parse-content.cc
+++ b/examples/pdf-parse-content.cc
@@ -35,11 +35,9 @@ ParserCallbacks::contentSize(size_t size)
}
void
-ParserCallbacks::handleObject(
- QPDFObjectHandle obj, size_t offset, size_t length)
+ParserCallbacks::handleObject(QPDFObjectHandle obj, size_t offset, size_t length)
{
- std::cout << obj.getTypeName() << ", offset=" << offset
- << ", length=" << length << ": ";
+ std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": ";
if (obj.isInlineImage()) {
std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl;
} else {
@@ -67,8 +65,7 @@ main(int argc, char* argv[])
try {
QPDF pdf;
pdf.processFile(filename);
- std::vector<QPDFPageObjectHelper> pages =
- QPDFPageDocumentHelper(pdf).getAllPages();
+ std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(pdf).getAllPages();
if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) {
usage();
}
diff --git a/examples/pdf-set-form-values.cc b/examples/pdf-set-form-values.cc
index a41cb3f7..c2793142 100644
--- a/examples/pdf-set-form-values.cc
+++ b/examples/pdf-set-form-values.cc
@@ -11,10 +11,8 @@ static char const* whoami = nullptr;
void
usage()
{
- std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value"
- << std::endl
- << "Set the value of all text fields to a specified value"
- << std::endl;
+ std::cerr << "Usage: " << whoami << " infile.pdf outfile.pdf value" << std::endl
+ << "Set the value of all text fields to a specified value" << std::endl;
exit(2);
}
@@ -55,8 +53,7 @@ main(int argc, char* argv[])
for (auto& annot: afdh.getWidgetAnnotationsForPage(page)) {
// For each annotation, find its associated field. If
// it's a text field, set its value.
- QPDFFormFieldObjectHelper ffh =
- afdh.getFieldForAnnotation(annot);
+ QPDFFormFieldObjectHelper ffh = afdh.getFieldForAnnotation(annot);
if (ffh.getFieldType() == "/Tx") {
// Set the value. Passing false as the second
// value prevents qpdf from setting
@@ -79,8 +76,7 @@ main(int argc, char* argv[])
w.setStaticID(true); // for testing only
w.write();
} catch (std::exception& e) {
- std::cerr << whoami << " processing file " << infilename << ": "
- << e.what() << std::endl;
+ std::cerr << whoami << " processing file " << infilename << ": " << e.what() << std::endl;
exit(2);
}
diff --git a/examples/pdf-split-pages.cc b/examples/pdf-split-pages.cc
index e8320201..9890ccf4 100644
--- a/examples/pdf-split-pages.cc
+++ b/examples/pdf-split-pages.cc
@@ -22,13 +22,11 @@ process(char const* whoami, char const* infile, std::string outprefix)
{
QPDF inpdf;
inpdf.processFile(infile);
- std::vector<QPDFPageObjectHelper> pages =
- QPDFPageDocumentHelper(inpdf).getAllPages();
+ std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(inpdf).getAllPages();
int pageno_len = QIntC::to_int(std::to_string(pages.size()).length());
int pageno = 0;
for (auto& page: pages) {
- std::string outfile =
- outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf";
+ std::string outfile = outprefix + QUtil::int_to_string(++pageno, pageno_len) + ".pdf";
QPDF outpdf;
outpdf.emptyPDF();
QPDFPageDocumentHelper(outpdf).addPage(page, false);
diff --git a/examples/qpdfjob-c-save-attachment.c b/examples/qpdfjob-c-save-attachment.c
index 301bf635..c461f974 100644
--- a/examples/qpdfjob-c-save-attachment.c
+++ b/examples/qpdfjob-c-save-attachment.c
@@ -83,8 +83,7 @@ main(int argc, char* argv[])
* saved data. You can use other qpdf logger functions to capture
* informational output, warnings, and errors.
*/
- qpdflogger_set_save(
- l, qpdf_log_dest_custom, save_to_file, (void*)outfile, 0);
+ qpdflogger_set_save(l, qpdf_log_dest_custom, save_to_file, (void*)outfile, 0);
qpdflogger_cleanup(&l);
j = qpdfjob_init();
status = (qpdfjob_initialize_from_argv(j, j_argv) || qpdfjob_run(j));
diff --git a/examples/qpdfjob-remove-annotations.cc b/examples/qpdfjob-remove-annotations.cc
index 5334e7dc..b0afa2da 100644
--- a/examples/qpdfjob-remove-annotations.cc
+++ b/examples/qpdfjob-remove-annotations.cc
@@ -20,15 +20,10 @@ usageExit(std::string const& msg)
<< 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
+ << " " << 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);
}
diff --git a/examples/qpdfjob-save-attachment.cc b/examples/qpdfjob-save-attachment.cc
index 2c08620a..045e38bf 100644
--- a/examples/qpdfjob-save-attachment.cc
+++ b/examples/qpdfjob-save-attachment.cc
@@ -14,8 +14,7 @@ main(int argc, char* argv[])
auto whoami = QUtil::getWhoami(argv[0]);
if (argc != 4) {
- std::cerr << "Usage: " << whoami << " file attachment-key outfile"
- << std::endl;
+ std::cerr << "Usage: " << whoami << " file attachment-key outfile" << std::endl;
exit(2);
}