2022-06-18 18:16:56 +00:00
|
|
|
#include <qpdf/Pl_StdioFile.hh>
|
|
|
|
#include <qpdf/QPDFJob.hh>
|
|
|
|
#include <qpdf/QPDFLogger.hh>
|
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
|
2023-05-27 17:19:52 +00:00
|
|
|
// This example demonstrates how we can redirect where saved output goes by calling the default
|
|
|
|
// logger's setSave method before running something with QPDFJob. See qpdfjob-c-save-attachment.c
|
|
|
|
// for an implementation that uses the C API.
|
2022-06-18 18:16:56 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
auto whoami = QUtil::getWhoami(argv[0]);
|
|
|
|
|
|
|
|
if (argc != 4) {
|
2023-05-21 17:35:09 +00:00
|
|
|
std::cerr << "Usage: " << whoami << " file attachment-key outfile" << std::endl;
|
2022-06-18 18:16:56 +00:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
char const* filename = argv[1];
|
|
|
|
char const* key = argv[2];
|
|
|
|
char const* outfilename = argv[3];
|
|
|
|
std::string attachment_arg = "--show-attachment=";
|
|
|
|
attachment_arg += key;
|
|
|
|
|
|
|
|
char const* j_argv[] = {
|
|
|
|
whoami,
|
|
|
|
filename,
|
|
|
|
attachment_arg.c_str(),
|
|
|
|
"--",
|
|
|
|
nullptr,
|
|
|
|
};
|
|
|
|
|
|
|
|
QUtil::FileCloser fc(QUtil::safe_fopen(outfilename, "wb"));
|
|
|
|
auto save = std::make_shared<Pl_StdioFile>("capture", fc.f);
|
|
|
|
QPDFLogger::defaultLogger()->setSave(save, false);
|
|
|
|
|
|
|
|
try {
|
|
|
|
QPDFJob j;
|
|
|
|
j.initializeFromArgv(j_argv);
|
|
|
|
j.run();
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
std::cerr << whoami << ": " << e.what() << std::endl;
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << whoami << ": wrote attachment to " << outfilename << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|