From 6d0e60bf3fe84745586e869bc17364b4d99cf267 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 6 Aug 2010 00:37:39 +0000 Subject: rename git-svn-id: svn+q:///qpdf/trunk@998 71b93d88-0707-0410-a8cf-f5a4172ac649 --- examples/double-page-size.cc | 113 --------------------------------------- examples/pdf-double-page-size.cc | 113 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 113 deletions(-) delete mode 100644 examples/double-page-size.cc create mode 100644 examples/pdf-double-page-size.cc diff --git a/examples/double-page-size.cc b/examples/double-page-size.cc deleted file mode 100644 index e933b5ac..00000000 --- a/examples/double-page-size.cc +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -static char const* whoami = 0; - -void usage() -{ - 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); -} - -static void doubleBoxSize(QPDFObjectHandle& page, char const* box_name) -{ - QPDFObjectHandle box = page.getKey(box_name); - if (box.isNull()) - { - return; - } - if (! (box.isArray() && (box.getArrayNItems() == 4))) - { - throw std::runtime_error(std::string("box ") + box_name + - " is not an array of four elements"); - } - std::vector doubled; - for (unsigned int i = 0; i < 4; ++i) - { - doubled.push_back( - QPDFObjectHandle::newReal( - QUtil::double_to_string( - box.getArrayItem(i).getNumericValue() * 2.0, 2))); - } - page.replaceKey(box_name, QPDFObjectHandle::newArray(doubled)); -} - -int main(int argc, char* argv[]) -{ - whoami = QUtil::getWhoami(argv[0]); - - // For libtool's sake.... - if (strncmp(whoami, "lt-", 3) == 0) - { - whoami += 3; - } - - if (! ((argc == 3) || (argc == 4))) - { - usage(); - } - - char const* infilename = argv[1]; - char const* outfilename = argv[2]; - char const* password = (argc == 4) ? argv[3] : ""; - - // Text to prepend to each page's contents - char const* content = "2 0 0 2 0 0 cm\n"; - - // Copy text into a buffer without the null terminator - PointerHolder b = new Buffer(strlen(content)); - unsigned char* bp = b.getPointer()->getBuffer(); - memcpy(bp, (unsigned char*)content, strlen(content)); - - try - { - QPDF qpdf; - qpdf.processFile(infilename, password); - - std::vector pages = qpdf.getAllPages(); - for (std::vector::iterator iter = pages.begin(); - iter != pages.end(); ++iter) - { - QPDFObjectHandle& page = *iter; - - // Prepend the buffer to the page's contents - page.addPageContents(QPDFObjectHandle::newStream(&qpdf, b), true); - - // Double the size of each of the content boxes - doubleBoxSize(page, "/MediaBox"); - doubleBoxSize(page, "/CropBox"); - doubleBoxSize(page, "/BleedBox"); - doubleBoxSize(page, "/TrimBox"); - doubleBoxSize(page, "/ArtBox"); - } - - // Write out a new file - QPDFWriter w(qpdf, outfilename); - if (QUtil::get_env("IN_TESTSUITE")) - { - // For the test suite, uncompress streams and use static - // IDs. - w.setStaticID(true); - w.setStreamDataMode(qpdf_s_uncompress); - } - w.write(); - std::cout << whoami << ": new file written to " << outfilename - << std::endl; - } - catch (std::exception &e) - { - std::cerr << whoami << " processing file " << infilename << ": " - << e.what() << std::endl; - exit(2); - } - - return 0; -} diff --git a/examples/pdf-double-page-size.cc b/examples/pdf-double-page-size.cc new file mode 100644 index 00000000..e933b5ac --- /dev/null +++ b/examples/pdf-double-page-size.cc @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include + +static char const* whoami = 0; + +void usage() +{ + 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); +} + +static void doubleBoxSize(QPDFObjectHandle& page, char const* box_name) +{ + QPDFObjectHandle box = page.getKey(box_name); + if (box.isNull()) + { + return; + } + if (! (box.isArray() && (box.getArrayNItems() == 4))) + { + throw std::runtime_error(std::string("box ") + box_name + + " is not an array of four elements"); + } + std::vector doubled; + for (unsigned int i = 0; i < 4; ++i) + { + doubled.push_back( + QPDFObjectHandle::newReal( + QUtil::double_to_string( + box.getArrayItem(i).getNumericValue() * 2.0, 2))); + } + page.replaceKey(box_name, QPDFObjectHandle::newArray(doubled)); +} + +int main(int argc, char* argv[]) +{ + whoami = QUtil::getWhoami(argv[0]); + + // For libtool's sake.... + if (strncmp(whoami, "lt-", 3) == 0) + { + whoami += 3; + } + + if (! ((argc == 3) || (argc == 4))) + { + usage(); + } + + char const* infilename = argv[1]; + char const* outfilename = argv[2]; + char const* password = (argc == 4) ? argv[3] : ""; + + // Text to prepend to each page's contents + char const* content = "2 0 0 2 0 0 cm\n"; + + // Copy text into a buffer without the null terminator + PointerHolder b = new Buffer(strlen(content)); + unsigned char* bp = b.getPointer()->getBuffer(); + memcpy(bp, (unsigned char*)content, strlen(content)); + + try + { + QPDF qpdf; + qpdf.processFile(infilename, password); + + std::vector pages = qpdf.getAllPages(); + for (std::vector::iterator iter = pages.begin(); + iter != pages.end(); ++iter) + { + QPDFObjectHandle& page = *iter; + + // Prepend the buffer to the page's contents + page.addPageContents(QPDFObjectHandle::newStream(&qpdf, b), true); + + // Double the size of each of the content boxes + doubleBoxSize(page, "/MediaBox"); + doubleBoxSize(page, "/CropBox"); + doubleBoxSize(page, "/BleedBox"); + doubleBoxSize(page, "/TrimBox"); + doubleBoxSize(page, "/ArtBox"); + } + + // Write out a new file + QPDFWriter w(qpdf, outfilename); + if (QUtil::get_env("IN_TESTSUITE")) + { + // For the test suite, uncompress streams and use static + // IDs. + w.setStaticID(true); + w.setStreamDataMode(qpdf_s_uncompress); + } + w.write(); + std::cout << whoami << ": new file written to " << outfilename + << std::endl; + } + catch (std::exception &e) + { + std::cerr << whoami << " processing file " << infilename << ": " + << e.what() << std::endl; + exit(2); + } + + return 0; +} -- cgit v1.2.3-54-g00ecf