Get Page Offset
Contents
[
Hide
]
The ‘get_page_offsets’ function provides developers with the exact horizontal (X) and vertical (Y) offsets of pages in a PDF file. In PDF documents, each page may have an internal origin point that differs from the top-left corner of the page, which can affect the positioning of text, images, annotations, or other content.
By using Aspose.PDF Facades, this function extracts these offsets in points and converts them to inches for easy interpretation. It supports multi-page PDFs, making it suitable for automated workflows that require precise content placement.
- Create the PDF facade object.
- Get the number of pages in the PDF.
- Loop through each page to get offsets.
- Print or store the offsets.
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def get_page_offsets(infile):
# Get and display PDF information
pdf_info = pdf_facades.PdfFileInfo(infile)
page_x_offset = pdf_info.get_page_x_offset(1) / 72.0
page_y_offset = pdf_info.get_page_y_offset(1) / 72.0
print(f"Page X Offset: {page_x_offset} inches")
print(f"Page Y Offset: {page_y_offset} inches")