The number_pages method allows you to add page numbers with various formatting, locations, and styles.
Basic usage:
pdf = CombinePDF.load "file_to_number.pdf"
pdf.number_pages
pdf.save "file_with_numbering.pdf"
Configuration Options
location: An array of locations (e.g., [:bottom_right], [:top, :bottom, :top_left, :top_right, :bottom_left, :bottom_right]).number_format: A string for formatting (e.g., " %s ").start_at: The starting value or character (e.g., 4 or "a").page_range: A range of pages to number (e.g., (0..2) or (3..-1)).box_color: RGB array for the box color.border_color: RGB array for the border color.border_width: Integer width of the border.box_radius: Integer radius for rounded corners.opacity: Float value for transparency.font_size: Integer for font size.
Example: Complex Numbering
To number the first 3 pages with letters (a, b, c) and the rest with numbers (4, 5, ...) with a semi-transparent box:
# Number first 3 pages as "a", "b", "c"
pdf.number_pages(number_format: " %s ",
location: [:top, :bottom, :top_left, :top_right, :bottom_left, :bottom_right],
start_at: "a",
page_range: (0..2),
box_color: [0.8,0.8,0.8],
border_color: [0.4, 0.4, 0.4],
border_width: 1,
box_radius: 6,
opacity: 0.75)
# Number the rest of the pages as 4, 5, ... etc
pdf.number_pages(number_format: " %s ",
location: [:top, :bottom, :top_left, :top_right, :bottom_left, :bottom_right],
start_at: 4,
page_range: (3..-1),
box_color: [0.8,0.8,0.8],
border_color: [0.4, 0.4, 0.4],
border_width: 1,
box_radius: 6,
opacity: 0.75)
pdf.number_pages(number_format: " %s ", location: :bottom_right, font_size: 44)