Skip to main content

A-PDF

A-PDF is a fast, command-line tool designed to replace Unicode and Hex text directly within PDF content streams.

Features

  • Direct Stream Replacement: Modifies the underlying PDF streams directly for fast and precise text replacement.
  • Unicode & Hex Support: Replace text using standard string replacements that are automatically encoded to the document's fonts.
  • Spacing Compensation: Automatically compensates for TJ (Text Justification) width adjustments after text replacements to preserve document layout (can be disabled).
  • Strict Mode: Optionally fail replacements if text is missing or the font cannot encode the requested characters.
  • Fallback Font Support: Embed a custom TrueType font when the PDF's subset font lacks a glyph, or disable fallback entirely.
  • Page Selection: Select specific pages to process.

Installation

You can run the tool directly using uv, which will automatically handle dependencies:

uv add apdf # or As a tool: uv tool install apdf
# then Run it
uv run apdf --help

Or simply use it in your standard Python environment.

pip install apdf

# Run 
apdf --help

Usage As Library

from apdf import replace_pdf_text_detailed

rep = replace_pdf_text_detailed(
    input_pdf="Test1.pdf",
    output_pdf="Test1_out.pdf",
    replacements={
        "Old Text": "New Text",
        # "Hello": "World",
        # "2026": "2027", 
    },

    # Optional parameters:
    #pages={2, 3, 4},       # Only these pages
    # pages=2,             # Only page 2
    # pages=range(1, 6),   # Pages 1 through 5
    # pages=None,          # All pages (default)

    # fallback_font="FONT.ttf",
    # font_fallback=True,
    # strict=True,
)

print("Replacements:", rep.replacements)
print("Changed streams:", rep.changed_streams)
print("Scanned streams:", rep.scanned_streams)
print("Missing:", rep.missing)
print("Encoding failures:", rep.encoding_failures)

Usage As CLI Tool

apdf [-h] [-r OLD=NEW] [-nopa] [-s] [-ff FONT.ttf] [-no-ff] [-p PAGELIST] input [output]

Examples

Basic replacement:

apdf input.pdf output.pdf -r "OldText=NewText"

Multiple replacements:

apdf document.pdf updated_document.pdf \
    -r "Draft=Final" \
    -r "2023=2024"

Disable width compensation (if characters are bunching up or spacing is incorrect):

apdf input.pdf output.pdf -r "foo=bar" -nopa

Strict mode (fails if the replacement target is not found):

apdf input.pdf output.pdf -r "foo=bar" -s

Arguments

  • input: The source PDF file.
  • output: (Optional) The destination PDF file. Defaults to output.pdf.
  • -r OLD=NEW: Replace. The text replacement pair. You can supply this argument multiple times.
  • -p 2, -p 2,3,4, or -p 1-5 to edit only selected pages. Without -p, all pages are processed.
  • -nopa: No preserve advance. Do not compensate TJ text widths after making replacements.
  • -s: Strict. Fail if the original text is missing or the selected font cannot encode the new text.
  • -ff FONT.ttf: Fallback font. TrueType font to embed when the PDF's subset font lacks a glyph.
  • -no-ff: No font fallback. Reject missing glyphs instead of embedding a fallback font.

Metadata

Release files for apdf 1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apdf 1.7
File Size Uploaded Provenance
apdf-1.7.tar.gz 31.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for apdf 1.7
File Interpreter ABI Platform
apdf-1.7-py3-none-any.whl Python 3 none any Details

Total release size: 60.2 kB

Release files / apdf-1.7.tar.gz

Download URL apdf-1.7.tar.gz
Size 31.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9c5d11f8b0ec55915ccca0aeb93362d1c8b5b1d592ed916fc8c8e5343c1887b6
BLAKE2b-256 checksum
How to use checksums
1ab2fb82d142d157cf262e5f89f1ea1e0b6ec6314f97411f21e4e1c876cec51b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / apdf-1.7-py3-none-any.whl

Download URL apdf-1.7-py3-none-any.whl
Size 28.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0277b5aeff4c9ea6ce04dc2812962eb72a7d5c0f207cf5a76d7873e6b819171f
BLAKE2b-256 checksum
How to use checksums
450c2ddc017328f972a39bf78231c925119395e042acd47c204a3948093c90f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.3 {"installer":{"name":"uv","version":"0.13.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for apdf 1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.7 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page