Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/capi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ export fn zpdf_extract_all_markdown(handle: ?*ZpdfDocument, out_len: *usize) ?[*
if (handle) |h| {
const doc: *zpdf.Document = @ptrCast(@alignCast(h));
const result = doc.extractAllMarkdown(c_allocator) catch return null;

// extractAllMarkdown returns an allocated slice; treat zero-length as "no data"
if (result.len == 0) {
c_allocator.free(result);
out_len.* = 0;
return null;
}

out_len.* = result.len;
return result.ptr;
}
Expand Down
22 changes: 22 additions & 0 deletions src/wapi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ export fn zpdf_extract_all(handle: i32, out_len: *usize) ?[*]u8 {
return null;
}

/// Extract text from all pages as Markdown with semantic formatting
/// Returns pointer to Markdown text buffer, sets out_len to buffer length
/// Caller must free with wasm_free
export fn zpdf_extract_all_markdown(handle: i32, out_len: *usize) ?[*]u8 {
if (handle < 0 or handle >= MAX_DOCUMENTS) return null;
const idx: usize = @intCast(handle);

if (documents[idx]) |doc| {
const result = doc.extractAllMarkdown(wasm_allocator) catch return null;

// extractAllMarkdown returns an allocated slice; treat zero-length as "no data"
if (result.len == 0) {
out_len.* = 0;
return null;
}

out_len.* = result.len;
return result.ptr;
}
return null;
}

/// Get page dimensions
/// Returns 0 on success, -1 on error
export fn zpdf_get_page_info(handle: i32, page_num: i32, width: *f64, height: *f64, rotation: *i32) i32 {
Expand Down