File Coverage

blib/lib/PDF/Make/RenderPage.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package PDF::Make::RenderPage;
2              
3 1     1   975 use strict;
  1         1  
  1         27  
4 1     1   3 use warnings;
  1         1  
  1         35  
5 1     1   3 use Carp qw(croak);
  1         1  
  1         54  
6 1     1   4 use PDF::Make (); # load XS so SCALE_*/ROTATE_* constants are defined
  1         1  
  1         64  
7              
8             our $VERSION = '0.03';
9              
10             =head1 NAME
11              
12             PDF::Make::RenderPage - Render PDF pages to pixel buffers
13              
14             =head1 SYNOPSIS
15              
16             use PDF::Make::Reader;
17             use PDF::Make::RenderPage;
18              
19             # Open a PDF
20             my $reader = PDF::Make::Reader->open('document.pdf');
21              
22             # Get page dimensions
23             my ($width, $height) = PDF::Make::RenderPage::get_page_render_size(
24             $reader, 0, 150 # page 0 at 150 DPI
25             );
26              
27             # Render the page
28             my $result = PDF::Make::RenderPage::render_page($reader, 0, {
29             dpi => 150,
30             background => 0xFFFFFFFF, # White background
31             antialias => 1,
32             });
33              
34             # Access the rendered data
35             my $pixels = $result->{pixels}; # Raw RGBA data
36             my $width = $result->{width};
37             my $height = $result->{height};
38              
39             # Render a region
40             my $region = PDF::Make::RenderPage::render_page_region(
41             $reader, 0,
42             100, 100, 200, 200, # x, y, w, h in PDF units
43             { dpi => 150 }
44             );
45              
46             =head1 DESCRIPTION
47              
48             PDF::Make::RenderPage provides the render pipeline for converting PDF pages
49             to rasterized pixel output. It integrates the content stream interpreter
50             with the path rendering engine to produce accurate visual representations
51             of PDF pages.
52              
53             =head1 FUNCTIONS
54              
55             =head2 get_page_render_size($reader, $page_num, $dpi)
56              
57             Returns the pixel dimensions (width, height) that a page will have when
58             rendered at the specified DPI.
59              
60             =head2 render_page($reader, $page_num, \%options)
61              
62             Render a page to a pixel buffer. Returns a hashref containing:
63              
64             {
65             pixels => $raw_rgba_data,
66             width => $pixel_width,
67             height => $pixel_height,
68             render_time_ms => $milliseconds,
69             effective_dpi => $actual_dpi,
70             path_objects => $path_count,
71             text_objects => $text_count,
72             image_objects => $image_count,
73             error => $error_message, # if any
74             }
75              
76             =head2 render_page_region($reader, $page_num, $x, $y, $w, $h, \%options)
77              
78             Render only a portion of a page. Coordinates are in PDF user space units.
79              
80             =head1 OPTIONS
81              
82             =over 4
83              
84             =item dpi
85              
86             Dots per inch for rendering. Default is 72 (1:1 with PDF units).
87              
88             =item scale_mode
89              
90             Scaling algorithm for images: SCALE_NEAREST, SCALE_BILINEAR, SCALE_BICUBIC.
91              
92             =item rotation
93              
94             Page rotation: ROTATE_0, ROTATE_90, ROTATE_180, ROTATE_270.
95              
96             =item antialias
97              
98             Enable antialiasing (1) or disable (0). Default is 1.
99              
100             =item background
101              
102             Background color as 0xAARRGGBB. Default is white (0xFFFFFFFF).
103              
104             =item clip_x, clip_y, clip_w, clip_h
105              
106             Render only a clipped region in pixel coordinates.
107              
108             =item render_text
109              
110             Render text objects (1) or skip them (0). Default is 1.
111              
112             =item render_images
113              
114             Render image XObjects (1) or skip them (0). Default is 1.
115              
116             =item render_vectors
117              
118             Render vector paths (1) or skip them (0). Default is 1.
119              
120             =back
121              
122             =head1 CONSTANTS
123              
124             =head2 Scale Modes
125              
126             SCALE_NEAREST = 0
127             SCALE_BILINEAR = 1
128             SCALE_BICUBIC = 2
129              
130             =head2 Rotation
131              
132             ROTATE_0 = 0
133             ROTATE_90 = 90
134             ROTATE_180 = 180
135             ROTATE_270 = 270
136              
137             =cut
138              
139             # SCALE_*, ROTATE_*, and the render_page/render_page_region/get_page_render_size
140             # functions are all provided by the XS loaded above.
141              
142             1;
143              
144             __END__