Spire.PDF for Python 12.7.0 supports auto fitting text in signature fields

2026-07-16 12:47:27

We’re pleased to announce the release of Spire.PDF for Python 12.7.0. This version introduces the AutoFontSize property, which enables automatic resizing of text content to fit within a signature field. Additionally, it fixes a font issue that occurred when replacing text. Further details are provided below.

Here is a list of changes made in this release

Category ID Description
New Feature SPIREPDF-7319 Added the AutoFontSize property to support auto-fitting text content to the size of a signature field.
# Initialize a PDF document object
doc = PdfDocument()

# Load the PDF file that needs to be signed
doc.LoadFromFile(inputFile)

# Specify the password for the PFX certificate file
pfxPassword = "e-iceblue"

# Get the first page of the document
page = doc.Pages.get_Item(0)

# Create an ordinary signature maker using the certificate file
signatureMaker = PdfOrdinarySignatureMaker(doc, inputFile_pfx, pfxPassword)

# Set the signature validation layer (False indicates displaying the validity symbol)
signatureMaker.SetAcro6Layers(False)

# Get the signature object and configure the basic information of the signer
signature = signatureMaker.Signature
signature.Name = "Gary"              # Signer's name
signature.ContactInfo = "028-81705109" # Contact information
signature.Location = "Chengdu"       # Signature location
signature.Reason = "The certificate of this document" # Reason for signing

# Create a custom signature appearance object
appearance = PdfSignatureAppearance(signature)
appearance.NameLabel = "Signer: "          # Name label
appearance.ContactInfoLabel = "ContactInfo: " # Contact information label
appearance.LocationLabel = "Location: "    # Location label
appearance.ReasonLabel = "Reaseon: "       # Reason label
appearance.SignatureImage = PdfImage.FromFile(inputFile_image) # Load the signature image
appearance.GraphicMode = GraphicMode.SignImageAndSignDetail # Set to display both the signature image and detailed information
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges # Set document permissions to forbid changes
appearance.SignImageLayout = SignImageLayout.Stretch # Set the layout mode of the signature image to stretch
appearance.AutoFontSize = True  # Enable auto font size adjustment for text

# Generate and apply the signature at the specified position on the page (Parameters in order: signature field name, page, X coordinate, Y coordinate, width, height, appearance object)
signatureMaker.MakeSignature("signName", page, 54.0, page.Size.Height - 300.0, 40.0, 40.0, appearance)

# Save the signed PDF document
doc.SaveToFile(outputFile)

# Close the document and release resources
doc.Close()
Bug Fix SPIREPDF-8056 Fixed the issue where the font was incorrect after text replacement.
Click the link to download Spire.PDF for Python 12.7.0: