Passa al contenuto principale

Unione multipla PDF File

PDF4me Unire è un REST punto finale che combina più PDFs in un unico documento. POST una matrice di Base64-file codificati in /api/v2/Merge con un nome di output e il API li aggiunge nell'ordine dell'array e restituisce il risultato unito PDF come byte grezzi. Imposta async vero per grandi lotti e sondare il Location URL fino a quando il risultato non sarà pronto.

Cosa fa questo endpoint

Ne servono due o più PDFs e restituisce uno: fattura più allegati, pagina di copertina più report, una cartella di scansioni consolidate in un unico file. L'ordine dell'array è l'ordine delle pagine, quindi il tuo codice controlla completamente il risultato. Questo è l'endpoint di concatenazione semplice; sovrapposizione pages Sovrapponendoli uno all'altro si esegue un'azione separata (Unisci sovrapposizione).

Articoli correlati del blog
Non ci sono ancora post sul blog dedicati a questa funzionalità — in arrivo a breve.
Nel frattempo, dai un'occhiata al blog di PDF4me per trovare tutorial e procedure operative su tutte le piattaforme.
Visita il blog

Autenticazione del tuo API Richiesta

Ogni PDF4me REST la chiamata deve includere il tuo API chiave nel Authorization Intestazione come autenticazione di base. Ottieni o ruota la tua chiave dalla dashboard dello sviluppatore.

Punto finale

POST/api/v2/Unione

Informazioni importanti da non perdere

docContent è un array e l'ordine è importante
A differenza della maggior parte PDF4me punti terminali in cui docContent è una singola stringa, qui è un ARRAY di Base64 stringhe. L'ordine dell'array corrisponde all'ordine di unione; non esiste un parametro di ordinamento separato.
Una risposta 200 è la PDF stessi
Il corpo è binario grezzo, non un JSON wrapper. Scrivi i byte direttamente in un .pdf file. JSON-analisi della risposta o Base64-decodificandolo si corrompe l'output.
asincrono vero per grandi quantità
Con "async": vero IL API risposte 202 Accepted con un Location intestazione. Interrogalo con GET circa ogni 10 secondi (i campioni ufficiali utilizzano intervalli di 10 secondi, fino a 20 tentativi) fino a quando 200 restituisce il file unito.

HTTP impostare

Metodo: POST
URL: https://api.pdf4me.com/api/v2/Merge
Tipo di contenuto: applicazione/json
Authorization: Base <il tuo PDF4me API chiave>

Un corpo di risposta di 200 è quello unito PDF come byte grezzi: salvalo direttamente. Una risposta 202 significa che l'unione è in esecuzione in modo asincrono: interroga il Location URL fino al 200.

Qual è la differenza tra elaborazione sincrona e asincrona?

IL async Il flag modifica il contratto di risposta, non il risultato dell'unione. Seleziona in base alla dimensione del batch.

Sincrono vs asincrono"async": false (predefinito)"async": true
Risposta su success200 con la fusione PDF come byte grezzi202 Accepted con un Location sondaggi URL
ConnessioneRimane aperto fino al termine della fusione.Restituisce immediatamente
Come ottenere il fileSalva direttamente il corpo della rispostaGET IL Location URL ogni ~10 secondi finché non risponde 200 con i byte
Ideale perAlcuni piccoli fileGrandi lotti e documenti di grandi dimensioni

API campi corporei

ParametroNecessarioTipoCosa faEsempio
docContentRequiredarray of stringsAn array of Base64-encoded PDF files, at least two entries. The array order is the merge order of the output document.["JVBERi0x...", "JVBERi0x..."]
docNameRequiredstringOutput filename for the merged PDF.merged.pdf
asyncOptionalbooleanfalse (default) returns the merged PDF directly on 200. true returns 202 plus a Location URL to poll, for large batches.true

Esempi di carichi utili

Unire due PDFs in modo sincrono

{
"docContent": [
"JVBERi0xLjcKJb...first PDF Base64...",
"JVBERi0xLjcKJb...second PDF Base64..."
],
"docName": "merged.pdf"
}

Unire un batch di grandi dimensioni in modo asincrono

{
"docContent": [
"JVBERi0x...cover...",
"JVBERi0x...report...",
"JVBERi0x...appendix-a...",
"JVBERi0x...appendix-b..."
],
"docName": "quarterly-pack.pdf",
"async": true
}

Consigli per la raccolta del postino

Headers
Content-Type: application/json + Authorization: Basic <apiKey>.
Body
raw JSON. docContent is an ARRAY of Base64 strings, one per source PDF, in merge order.
Response
On 200, switch Postman to "Send and Download": the body is the PDF itself, not JSON.
Async
With async true, copy the Location header from the 202 response into a GET request and poll it until 200.

esempio di riccio

curl -X POST https://api.pdf4me.com/api/v2/Merge \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"docContent": [
"'"$(base64 -w 0 first.pdf)"'",
"'"$(base64 -w 0 second.pdf)"'"
],
"docName": "merged.pdf"
}' \
--output merged.pdf

Che cosa significa il API ritorno?

CampoTipoCosa contiene
200 response bodyBinary (application/pdf)The merged PDF file itself as raw bytes. Save it directly to disk; do not JSON-parse or Base64-decode.
202 Location headerURLAsync mode only: the polling URL. GET it about every 10 seconds until it returns 200 with the merged PDF bytes.
4xx/5xx response bodyJSON or textError details: 400 for malformed Base64 or a bad payload shape, 401 for a missing or invalid API key, 500 for server-side processing failures.

Esempi di codice

Esempi ufficiali e funzionanti per questo endpoint specifico, per language:

FAQ

How is the merge order decided?+
By the docContent array order. The first Base64 string becomes the first pages of the output, the second is appended after it, and so on. Reorder the array to reorder the merged document.
Is the response JSON with a Base64 file inside?+
No. A 200 response body is the merged PDF itself as raw binary bytes. Write response.content straight to a .pdf file; do not JSON-parse or Base64-decode it.
When should I set async to true?+
For large batches or big files. With async true the API returns 202 Accepted plus a Location header; poll that URL with GET requests about every 10 seconds until it returns 200 with the merged PDF.
Can I merge Word or Excel files with this endpoint?+
No. /api/v2/Merge accepts PDFs only. Merge Word files with the Merge Documents Word endpoint, or convert other formats to PDF first and then merge the results here.
How many PDFs can I merge in one call?+
The docContent array accepts multiple documents in a single request; two entries is the minimum meaningful merge. For very large batches, set async true so the merge runs server-side while you poll for the result.
What is the difference between Merge and Merge Overlay?+
Merge appends documents one after another, page by page. Merge Overlay stamps the pages of one PDF on top of the pages of another, which is what you want for letterheads and backgrounds.
Why am I getting a 400 Bad Request?+
The usual causes are a docContent that is a single string instead of an array, an entry that is not valid Base64, or a source file that is not actually a PDF. Encode each file separately and keep the array shape.

Perché fondersi PDFs via API invece di uno strumento da tavolo?

Gli strumenti di unione desktop e web vanno bene per lavori occasionali, ma hanno bisogno di una persona per selezionare i file, trascinarli nell'ordine corretto e scaricare il risultato. API esegue la stessa concatenazione di una richiesta deterministica per batch, con l'ordine fissato dal tuo codice anziché tramite trascinamento. L'output è uno standard PDF conforme al ISO Specifiche 32000, quindi si apre in qualsiasi lettore e si collega senza problemi al passaggio successivo della pipeline, che sia la compressione, OCR, o firma elettronica.

Azioni correlate

Stessa attività su altre piattaforme

Richiedi assistenza