From ec19caddb60e748115adb562b46d007598dcdb95 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 2 Aug 2026 21:28:49 -0300 Subject: render PDFs as a continuous vertical page strip --- src/pdf.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/pdf.zig') diff --git a/src/pdf.zig b/src/pdf.zig index b06c85e8..a1c05681 100644 --- a/src/pdf.zig +++ b/src/pdf.zig @@ -72,6 +72,11 @@ pub const Render = struct { height: usize, }; +pub const PageSize = struct { + width: f32, + height: f32, +}; + pub const SearchQuad = struct { quad: Quad, /// Zero-based logical hit. One hit may have several oriented quads. @@ -150,6 +155,17 @@ pub const Document = struct { document.* = undefined; } + /// Return crop/rotation-aware page dimensions without allocating pixels. + pub fn pageSize(document: *Document, page: usize) !PageSize { + const page_number = try document.checkedPage(page); + var size: c.pardes_pdf_page_size = std.mem.zeroes(c.pardes_pdf_page_size); + if (c.pardes_pdf_get_page_size(document.handle, page_number, &size) != c.PARDES_PDF_OK or + !std.math.isFinite(size.width) or !std.math.isFinite(size.height) or + size.width <= 0 or size.height <= 0) + return error.BadPageSize; + return .{ .width = size.width, .height = size.height }; + } + /// Render one zero-based page, bounded before allocation. MuPDF supplies /// row-strided RGB; Pardes' attachment boundary is packed straight RGBA. pub fn render(document: *Document, gpa: std.mem.Allocator, page: usize) !Render { -- cgit v1.3