add_page_number_to_pdf
Add page numbers to PDFs by specifying a format, position, font, and margins. Customize with placeholders for current page and total count, and skip the first page if needed.
Instructions
Add page numbers to a PDF via PDF4me POST /api/v2/AddPageNumber. When helping a user, explain how to set page_number_format before calling: use the literal character # for the current page (1, 2, 3, …) and the literal substring {1} for the total page count. Those are placeholders, not Python format specifiers—pass them exactly as strings (e.g. '# of {1}' renders as '1 of 10', 'Page #' as 'Page 1', '# / {1}' as '1 / 10', '(#)' as '(1)', '#' alone as '1'). align_x must be left, center, or right; align_y must be top, middle, or bottom. Optional: margin_x_in_mm and margin_y_in_mm (integers 0–100 mm from the chosen edge), font_size (8–72), is_bold, is_italic, skip_first_page. Requires a local pdf_file_path; output defaults next to the source file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| align_x | No | Horizontal position of the page number text. | right |
| align_y | No | Vertical position of the page number text. | bottom |
| is_bold | No | If true, render page numbers in bold. | |
| font_size | No | Font size for the page number (allowed range 8–72 when set). | |
| is_italic | No | If true, render page numbers in italic. | |
| output_dir | No | Directory for the saved PDF; defaults to the input file's directory. | |
| pdf_file_path | Yes | Absolute or relative path to the input PDF file. | |
| margin_x_in_mm | No | Horizontal margin from the aligned edge, in millimeters (0–100). | |
| margin_y_in_mm | No | Vertical margin from the aligned edge, in millimeters (0–100). | |
| skip_first_page | No | If true, do not print a page number on the first page. | |
| output_file_name | No | File name for the saved PDF (e.g. numbered_report.pdf). | |
| request_doc_name | No | Output document name sent to the API (should end with .pdf). Defaults to the input file basename. | |
| page_number_format | Yes | Text pattern for each footer/header line. Use # for current page number and {1} for total pages (both are literal characters in the string). Examples: '# of {1}', 'Page #', '# / {1}', '(#)', '#'. |