- 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>
31 lines
891 B
C
31 lines
891 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <assert.h>
|
|
#include "../crates/pdftract-libpdftract/include/pdftract.h"
|
|
|
|
int main(void) {
|
|
printf("Testing stream API with tests/fixtures/test-minimal.pdf...\n");
|
|
|
|
void* handle = pdftract_extract_stream_open("tests/fixtures/test-minimal.pdf", "{}");
|
|
if (handle == NULL) {
|
|
const char* error = pdftract_last_error();
|
|
printf("Stream open failed: %s\n", error ? error : "(null)");
|
|
return 1;
|
|
}
|
|
|
|
printf("Stream opened successfully\n");
|
|
|
|
int page_count = 0;
|
|
char* page;
|
|
while ((page = pdftract_stream_next(handle)) != NULL) {
|
|
page_count++;
|
|
printf("Page %d: %zu bytes\n", page_count, strlen(page));
|
|
pdftract_free(page);
|
|
}
|
|
|
|
pdftract_stream_close(handle);
|
|
printf("Stream closed: %d pages\n", page_count);
|
|
|
|
return 0;
|
|
}
|