2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-05 11:50:53 +00:00

Add qpdfjob_register_progress_reporter

This commit is contained in:
Jay Berkenbilt 2022-06-18 21:04:44 -04:00
parent 87412eb05b
commit bb0ea2f8e7
8 changed files with 53 additions and 9 deletions

View File

@ -1,5 +1,10 @@
2022-06-18 Jay Berkenbilt <ejb@ql.org> 2022-06-18 Jay Berkenbilt <ejb@ql.org>
* Add QPDFJob::registerProgressReporter, making it possible to
override the progress reporter that is used when --progress (or
the equivalent) is configured with QPDFJob. This is
qpdfjob_register_progress_reporter in the C API.
* Add examples that show how to capture QPDFJob's output by * Add examples that show how to capture QPDFJob's output by
configuring the default logger (qpdfjob-save-attachment.cc, configuring the default logger (qpdfjob-save-attachment.cc,
qpdfjob-c-save-attachment.c). Fixes #691. qpdfjob-c-save-attachment.c). Fixes #691.

4
TODO
View File

@ -14,9 +14,7 @@ Next:
Pending changes: Pending changes:
* Allow users to supply a custom progress reporter for QPDFJob. If one * Consider also exposing a way to set a new logger and to get the
is provided, use it instead of creating one. Then expose to the C
API. Consider also exposing a way to set a new logger and to get the
logger from QPDF and QPDFJob in the C API. logger from QPDF and QPDFJob in the C API.
* Check about runpath in the linux-bin distribution. I think the * Check about runpath in the linux-bin distribution. I think the
appimage build specifically is setting the runpath, which is appimage build specifically is setting the runpath, which is

View File

@ -125,6 +125,16 @@ extern "C" {
QPDF_DLL QPDF_DLL
int qpdfjob_run(qpdfjob_handle j); int qpdfjob_run(qpdfjob_handle j);
/* Allow specification of a custom progress reporter. The progress
* reporter is only used if progress is otherwise requested (with
* the --progress option or "progress": "" in the JSON).
*/
QPDF_DLL
void qpdfjob_register_progress_reporter(
qpdfjob_handle j,
void (*report_progress)(int percent, void* data),
void* data);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -120,3 +120,12 @@ int qpdfjob_run_from_json(char const* json)
}); });
} }
void
qpdfjob_register_progress_reporter(
qpdfjob_handle j,
void (*report_progress)(int percent, void* data),
void* data)
{
j->j.registerProgressReporter(
std::bind(report_progress, std::placeholders::_1, data));
}

View File

@ -186,8 +186,8 @@ For a detailed list of changes, please see the file
- Add new ``Pipeline`` type ``Pl_String`` to append to a - Add new ``Pipeline`` type ``Pl_String`` to append to a
``std::string``. ``std::string``.
- Add methods to QUtil for converting PDF timestamps and QPDFTime - Add methods to ``QUtil`` for converting PDF timestamps and
objects to ISO-8601 timestamps. ``QPDFTime`` objects to ISO-8601 timestamps.
- Enhance JSON class to better support incrementally reading and - Enhance JSON class to better support incrementally reading and
writing large amounts of data without having to keep everything writing large amounts of data without having to keep everything
@ -200,6 +200,12 @@ For a detailed list of changes, please see the file
interface offers more flexibility than the old interface, which interface offers more flexibility than the old interface, which
remains available. remains available.
- Add ``QPDFJob::registerProgressReporter`` and
``qpdfjob_register_progress_reporter`` to allow a custom
progress reporter to be used with ``QPDFJob``. The ``QPDFJob``
object must be configured to report progress (via command-line
argument or otherwise) for this to be used.
- Other changes - Other changes
- In JSON v1 mode, the ``"objects"`` key now reflects the repaired - In JSON v1 mode, the ``"objects"`` key now reflects the repaired

View File

@ -20,18 +20,30 @@ wide_test()
} }
#endif // QPDF_NO_WCHAR_T #endif // QPDF_NO_WCHAR_T
static void
custom_progress(int progress, void* data)
{
printf("%s: write progress: %d%%\n", (char const*)data, progress);
}
static void static void
run_tests() run_tests()
{ {
/* Be sure to use a different output file for each test. */ /* Be sure to use a different output file for each test. */
qpdfjob_handle j = NULL;
char const* argv[5]; char const* argv[6];
argv[0] = "qpdfjob"; argv[0] = "qpdfjob";
argv[1] = "minimal.pdf"; argv[1] = "minimal.pdf";
argv[2] = "a.pdf"; argv[2] = "a.pdf";
argv[3] = "--deterministic-id"; argv[3] = "--deterministic-id";
argv[4] = NULL; argv[4] = "--progress";
assert(qpdfjob_run_from_argv(argv) == 0); argv[5] = NULL;
j = qpdfjob_init();
qpdfjob_register_progress_reporter(j, custom_progress, (void*)"potato");
assert(qpdfjob_initialize_from_argv(j, argv) == 0);
assert(qpdfjob_run(j) == 0);
qpdfjob_cleanup(&j);
printf("argv test passed\n"); printf("argv test passed\n");
assert(qpdfjob_run_from_json("{\n\ assert(qpdfjob_run_from_json("{\n\

View File

@ -1,3 +1,6 @@
potato: write progress: 0%
....other write progress....
potato: write progress: 100%
argv test passed argv test passed
json test passed json test passed
WARNING: xref-with-short-size.pdf (xref stream, offset 16227): Cross-reference stream data has the wrong size; expected = 52; actual = 56 WARNING: xref-with-short-size.pdf (xref stream, offset 16227): Cross-reference stream data has the wrong size; expected = 52; actual = 56

View File

@ -100,7 +100,8 @@ $td->runtest("json output from job",
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);
$td->runtest("C job API", $td->runtest("C job API",
{$td->COMMAND => "qpdfjob-ctest"}, {$td->COMMAND => "qpdfjob-ctest",
$td->FILTER => "perl filter-progress.pl"},
{$td->FILE => "qpdfjob-ctest.out", $td->EXIT_STATUS => 0}, {$td->FILE => "qpdfjob-ctest.out", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);
foreach my $i (['a.pdf', 1], ['b.pdf', 2], ['c.pdf', 3]) foreach my $i (['a.pdf', 1], ['b.pdf', 2], ['c.pdf', 3])