Why This Guide Needed an Update
Replacing pages inside a PDF used to be a “hands-on” job. Someone opened a PDF editor, hunted down the right pages, inserted the new ones, exported the file, then checked everything again—often more than once. That approach still works for occasional edits, but it breaks down fast when documents change frequently or when multiple people are involved.
Modern teams increasingly treat PDFs like outputs in a larger system—contracts, proposals, onboarding packets, and compliance bundles are generated, revised, and distributed continuously. In that world, a page swap isn’t a manual chore; it’s an operation that should be repeatable and predictable.
This updated article explains how to call the “Replace Pages from PDF” endpoint in the Zoho PDF Editor API, what the request must include, and what the response flow looks like. It also highlights what has changed “from before to today” in how developers implement this endpoint—especially around validation, job handling, and production readiness.
What “Replace Pages from PDF” Actually Does
At its core, this endpoint performs a targeted swap:
- You start with an original PDF you want to modify.
- You provide a replacement PDF that contains the pages you want to insert.
- You specify two page ranges:
- pages in the original document to replace
- pages in the replacement document to pull in
- You receive an updated PDF as the output.
The value is simple: instead of rebuilding the entire file, you replace only the pages that changed and preserve everything else.
The One Rule You Can’t Ignore
Page replacement is strict about structure. The number of pages you remove must match the number of pages you insert.
Replacing pages 1–4 means you must insert exactly 4 pages from the replacement file. If those counts don’t match, your call is effectively invalid—and you’ll waste time chasing errors that could have been prevented with a basic pre-check.
Before vs Today: What Changed in Real Implementations
Before: One-Off Scripts and Manual Safety Nets
Earlier integrations often looked like quick utility scripts:
A developer would build a simple call, run it when needed, and download the output. If it failed, someone usually stepped in and fixed the PDF manually. Logging was minimal, validation was inconsistent, and the “status check” step was frequently handled with aggressive polling or a best-effort retry.
That approach was fine when page replacement was rare and the businessBusiness-to-business (B2B), also known as B-to-B, is a form of transaction between businesses, such ... More tolerated occasional rework.
LOOKING FOR A ONE-STOP SOLUTION TO YOUR GROWTH NEEDS?
Today: Production Patterns and Workflow Integration
Current implementations treat page replacement as a first-class capability inside a broader document process.
Instead of relying on manual fallback, teams now:
- validate page ranges before sending the request
- store region configuration so calls go to the correct data center
- track job status cleanly until the result is ready
- adopt consistent output naming to reduce version confusion
- enforce file/page limits early (such as the commonly referenced 50 MB file limit and 150-page cap)
In short, developers moved from “get it working” to “make it reliable at scale.”
Step 1: Select the Correct Regional Domain
The Zoho PDF Editor API uses regional domains (US, EU, IN, and others). Getting this wrong can derail your integration even when everything else looks correct.
A best practice is to treat the region as configuration, not a hard-coded constant. Some teams store the domain per tenant or per environment to support multi-region deployments cleanly.
Base Path Format
The base path typically follows this pattern:
https://{zohoapis_domain}/pdfeditor/api/v1
Using the correct {zohoapis_domain} is foundational. If your OAuth token was issued for one region but you call another, authentication failures and confusing “resource not found” behavior become far more likely.
Step 2: Call the Correct Endpoint
For replacing pages (and retrieving an updated PDF), the endpoint is:
POST /pdf/pages/replace
Even if you’ve seen alternative wording in older notes, modern implementations standardize around this canonical path to avoid drift across teams and codebases.
Step 3: Send the Request as Multipart Form Data
This endpoint expects a multipart request. That matters because you’re sending files (or file URLs) plus structured JSON options.
You’ll include these required form fields:
original_pdf_file (File or String)
You can provide the original PDF in either of two ways:
- Upload a PDF file directly, or
- Provide a publicly accessible URL using the same field
Choosing between upload and URL depends on your architecture. Uploading is simple and often safer for sensitive documents. URL-based inputs can reduce bandwidth when files are already stored in a system that can serve them securely.
replacement_pdf_file (File or String)
This is the source of the pages you’ll insert.
Like the original file, you can:
- upload it as a file, or
- provide a publicly accessible URL
input_options (JSON)
This field defines the page ranges:
original_page_ranges: the pages you want to replace in the original PDFreplacement_page_ranges: the pages you want to extract from the replacement PDF
Example:
{
"original_page_ranges": "1-4",
"replacement_page_ranges": "5-8"
}
A quick reminder: the page counts must match.
output_settings (JSON)
This field defines the output name:
name: the filename of the updated PDF
Example:
{
"name": "ModifiedFile.pdf"
}
In “today” workflows, naming is not an afterthought. Teams commonly embed identifiers like deal IDs, client names, or version tags to prevent confusion once outputs start piling up.
Step 4: Use a Correct and Readable cURL Template
The following template is a clean starting point. Replace placeholders with your real values:
curl --location --request POST "https://{zohoapis_domain}/pdfeditor/api/v1/pdf/pages/replace" \
--header "Authorization: Zoho-oauthtoken YOUR_ACCESS_TOKEN" \
--form 'original_pdf_file=@"/path/to/Original.pdf"' \
--form 'replacement_pdf_file=@"/path/to/Replacement.pdf"' \
--form 'input_options={"original_page_ranges":"1-4","replacement_page_ranges":"5-8"}' \
--form 'output_settings={"name":"ModifiedFile.pdf"}'
Common Formatting Mistakes to Avoid
Small formatting errors cause big headaches with multipart requests.
Watch for these pitfalls:
- Broken JSON quotes inside
input_optionsoroutput_settings - Missing braces or stray commas in the JSON
- Accidentally nesting
--formflags incorrectly - Using the wrong authorization headerThe term header means either the high top section of a web page which normally holds the brand info ... More label or token format
Multipart requests are unforgiving. Keeping the template clean makes troubleshooting significantly easier.
Respect File and Page Constraints
Your notes mention typical constraints such as:
- 50 MB maximum file size
- 150 pages maximum length
Even if your PDFs usually fall within those limits, build checks early so users receive fast feedback rather than waiting for a job to fail later.
Step 5: Understand the Job-Based Response Flow
Replacing pages is usually processed as a job rather than a single synchronous response. That’s a feature, not a bug: job-based processing avoids timeouts and improves reliability for larger documents.
Initial Response: The Job Has Started
The first response typically includes:
- a
status_check_url - a status that often begins as “in progress”
Your application should treat this as a receipt. The output file is not guaranteed to be ready immediately.
Success Response: The Output Is Ready
When the job completes successfully, you can expect:
- a
download_url - a status that indicates success
From there, your system can download the PDF, store it, send it onward, or attach it to a workflow step.
Step 6: Authenticate with the Proper OAuth Scope
The endpoint requires OAuth access with the scope:
ZohoWriter.pdfEditor.ALL
Many integration issues trace back to authentication details, not request payloads. A token can be valid yet still fail if it lacks the required scope.
What’s Different Today in Auth Handling
In older implementations, developers sometimes pasted tokens into scripts and rotated them manually.
Production systems now handle auth more systematically:
- tokens are refreshed automatically
- scopes are validated during onboarding
- failures are logged with enough context to diagnose quickly
- region configuration is aligned with token issuance
That shift alone reduces a huge percentage of “mysterious” failures.
Modern Best Practices That Make the Endpoint Feel “Easy”
Validate Page Ranges Before You Call the API
This is the fastest win.
Before sending a request, confirm:
- the range format is valid (for example, “3-7”)
- the ranges are within each PDF’s page count
- the page counts match between original and replacement ranges
Catching a mismatch early saves time and prevents avoidable job failures.
Choose Upload vs URL Inputs Deliberately
Both options work, but each has trade-offs.
Uploads simplify access control because the file is transmitted directly. URLs can be efficient, but only when your storage environment can serve the file reliably and securely.
For sensitive content, avoid broad public exposure. When URL inputs are necessary, teams often prefer short-lived, controlled-access URLs to reduce risk.
Handle the Status Check Like a Real Workflow
Polling is easy to get wrong.
A production-friendly approach often includes:
- backoff between status checks rather than rapid looping
- a maximum wait limit with a clear timeout path
- persisted job metadata so a restart doesn’t lose state
- user-visible “processing” status in your UI if applicable
This is one of the biggest “before vs today” differences. Scripts can brute-force polling; platforms must be respectful and resilient.
Standardize Output Naming to Reduce Chaos
Once your integration runs frequently, output naming becomes operationally important.
Good names help users and systems locate the right file quickly. A solid naming pattern might include:
- a document type label (Contract, Proposal, Policy)
- an identifier (client name or ID)
- a version or date marker
Even a basic naming convention dramatically reduces “Which file is the latest?” confusion.
Troubleshooting the Issues You’re Most Likely to See
Page Count Mismatch
Symptoms:
- The job fails or returns an error.
Fix:
- Ensure both page ranges represent the same number of pages.
Wrong Region Domain
Symptoms:
- Auth errors despite a token that “should work.”
Fix:
- Confirm your
{zohoapis_domain}matches the region associated with your account and token.
Missing OAuth Scope
Symptoms:
- Permission failures even though authentication appears correct.
Fix:
- Request and grant
ZohoWriter.pdfEditor.ALLduring OAuth flow.
Bad JSON in Multipart Fields
Symptoms:
- “Bad request” style errors or parsing failures.
Fix:
- Validate JSON formatting and escaping in
input_optionsandoutput_settings.
When Replace Pages Is the Right Tool (And When It Isn’t)
Ideal Use Cases
Page replacement is a great fit when the document structure stays stable and only certain sections change:
- contract terms pages updated while signatures remain untouched
- proposal pricing pages swapped without changing the rest of the deck
- compliance pages refreshed across multiple PDFs
- localized pages substituted while keeping a shared base document
When You Need a Different Operation
If your goal is to edit text inside a page, reflow layouts, or redact content embedded within a page, page replacement may not be enough. In those cases, you typically need content-level PDF editing operations instead of a range swap.
Summary: The Updated “Today” Way to Call This Endpoint
Calling the “Replace Pages from PDF” endpoint is straightforward once you structure the request correctly:
- Use the correct regional domain and base API path.
- Send a multipart POST request to
/pdf/pages/replace. - Provide
original_pdf_fileandreplacement_pdf_fileas uploads or public URLs. - Include
input_optionsJSON withoriginal_page_rangesandreplacement_page_ranges. - Include
output_settingsJSON with the outputname. - Expect a job flow with
status_check_urlfirst, thendownload_urlon success. - Authenticate using an OAuth token with
ZohoWriter.pdfEditor.ALL.
What’s changed from before to today is the mindset: developers now treat page replacement as a reliable building block inside larger workflows—validated up front, monitored cleanly, and delivered with consistent outputs.
If you’d like, paste your original (older) version of this tutorial, and I’ll rewrite it into a true “updated edition” that preserves your voice while making the “before vs today” changes more explicit—without adding links or using any tables.
© Image credits to Steve Johnson
LOOKING FOR A ONE-STOP SOLUTION TO YOUR GROWTH NEEDS?