- Add decode_page_content_streams() function for per-page lazy decode - Update extract_page_from_dict() to support lazy stream decoding - Modify extract_pdf() and extract_pdf_ndjson() to enable lazy decoding - Fix borrow checker issue in LazyPageIter::next() This ensures content streams are decoded lazily per page and dropped immediately after processing, keeping peak RSS flat across page count. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
/* Copyright 2026 Jed Cabanino. MIT OR Apache-2.0 */
|
|
|
|
/*
|
|
* Sample C++ client for pdftract library.
|
|
* Demonstrates C++ compatibility (using extern "C").
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <memory>
|
|
#include "../../crates/pdftract-libpdftract/include/pdftract.h"
|
|
|
|
/* RAII wrapper for pdftract strings */
|
|
struct PdftractString {
|
|
char* ptr;
|
|
|
|
PdftractString(char* p) : ptr(p) {}
|
|
~PdftractString() { if (ptr) pdftract_free(ptr); }
|
|
|
|
// Disable copy
|
|
PdftractString(const PdftractString&) = delete;
|
|
PdftractString& operator=(const PdftractString&) = delete;
|
|
|
|
// Enable move
|
|
PdftractString(PdftractString&& other) noexcept : ptr(other.ptr) {
|
|
other.ptr = nullptr;
|
|
}
|
|
PdftractString& operator=(PdftractString&& other) noexcept {
|
|
if (this != &other) {
|
|
if (ptr) pdftract_free(ptr);
|
|
ptr = other.ptr;
|
|
other.ptr = nullptr;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
std::string_view view() const {
|
|
return ptr ? std::string_view(ptr) : std::string_view();
|
|
}
|
|
|
|
explicit operator bool() const { return ptr != nullptr; }
|
|
};
|
|
|
|
int main() {
|
|
std::cout << "pdftract C++ client test\n";
|
|
std::cout << "========================\n\n";
|
|
|
|
// Test version
|
|
std::cout << "Version: " << pdftract_version() << "\n\n";
|
|
|
|
// Test null handling
|
|
std::cout << "Testing null source handling...\n";
|
|
PdftractString null_result(pdftract_extract(nullptr, "{}"));
|
|
if (null_result && null_result.view().find("\"error\"") != std::string_view::npos) {
|
|
std::cout << "PASS: null source returns error JSON\n";
|
|
} else {
|
|
std::cout << "FAIL: null source did not return error JSON\n";
|
|
}
|
|
|
|
std::cout << "\nAll C++ client tests completed.\n";
|
|
return 0;
|
|
}
|