pdftract/tests/c-client/create_valid_pdf.c
jedarden 9b5fbc9b5e feat(pdftract-bf-2y2rp): implement lazy stream decoding for PDF extraction
- 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>
2026-05-23 12:30:26 -04:00

51 lines
1.4 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Create a minimal valid PDF with proper trailer and content stream */
int create_valid_pdf(const char* path) {
FILE* f = fopen(path, "wb");
if (!f) return 1;
/* A valid minimal PDF with proper trailer and content stream */
const char* pdf_content =
"%PDF-1.4\n"
"1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj\n"
"2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj\n"
"3 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 612 792]"
"/Resources<</Font<</F1 4 0 R>>>>/Contents 5 0 R>>endobj\n"
"4 0 obj<</Type/Font/Subtype/Type1/BaseFont/Helvetica>>endobj\n"
"5 0 obj<</Length 44>>stream\n"
"BT\n"
"/F1 12 Tf\n"
"50 700 Td\n"
"(Hello World) Tj\n"
"ET\n"
"endstream\n"
"endobj\n"
"xref\n"
"0 6\n"
"0000000000 65535 f\n"
"0000000009 00000 n\n"
"0000000058 00000 n\n"
"0000000115 00000 n\n"
"0000000262 00000 n\n"
"0000000331 00000 n\n"
"trailer<</Size 6/Root 1 0 R>>\n"
"startxref\n"
"430\n"
"%%EOF\n";
fwrite(pdf_content, 1, strlen(pdf_content), f);
fclose(f);
return 0;
}
int main(void) {
if (create_valid_pdf("/tmp/test-valid.pdf") != 0) {
fprintf(stderr, "Failed to create PDF\n");
return 1;
}
printf("Created /tmp/test-valid.pdf\n");
return 0;
}