Zum Hauptinhalt springen

Mehrere zusammenführen PDF Dateien

PDF4me Zusammenführen ist ein REST Endpunkt, der mehrere PDFs in einem einzigen Dokument. POST eine Reihe von Base64-kodierte Dateien an /api/v2/Merge mit einem Ausgabenamen und dem API fügt sie in Array-Reihenfolge an und gibt das zusammengeführte Ergebnis zurück. PDF als Rohbytes. Festlegen async gilt für große Mengen und Umfrage Location URL bis das Ergebnis vorliegt.

Was dieser Endpunkt bewirkt

Benötigt zwei oder mehr PDFs und gibt Folgendes zurück: Rechnung plus Anhänge, Deckblatt plus Bericht, einen Ordner mit Scans, die in einer einzigen Datei zusammengefasst sind. Die Reihenfolge im Array entspricht der Seitenreihenfolge, sodass Ihr Code das Ergebnis vollständig steuert. Dies ist der Endpunkt für die einfache Verkettung; Überlagerung pages Übereinanderliegende Elemente werden separat bearbeitet (Überlagerung zusammenführen).

Verwandte Blog-Beiträge
Zu dieser Funktion gibt es noch keinen Blogbeitrag – folgt in Kürze.
Schauen Sie sich in der Zwischenzeit im PDF4me-Blog Tutorials und Arbeitsabläufe für alle Plattformen an.
Besuchen Sie den Blog

Authentifizierung Ihres API Anfrage

Jeder PDF4me REST Der Anruf muss Ihre API Schlüssel im Authorization Header als Basic Auth. Ihren Schlüssel erhalten oder ändern Sie ihn im Entwickler-Dashboard.

Endpunkt

POST/api/v2/Merge

Wichtige Fakten, die Sie nicht verpassen sollten

docContent Es handelt sich um ein Array, und die Reihenfolge ist wichtig.
Im Gegensatz zu den meisten PDF4me Endpunkte, an denen docContent ist eine einzelne Zeichenkette, hier ist es ein ARRAY von Base64 Zeichenketten. Die Array-Reihenfolge entspricht der Zusammenführungsreihenfolge; es gibt keinen separaten Sortierparameter.
Eine Antwort von 200 ist die PDF selbst
Der Körper ist roh binär, nicht a JSON Wrapper. Schreibe die Bytes direkt in ein .pdf Datei. JSON-die Antwort analysieren oder Base64-Das Dekodieren verfälscht die Ausgabe.
async true für große Batches
Mit "async": true Die API 202 Antworten Accepted mit einem Location Überschrift. Fragen Sie es ab mit GET etwa alle 10 Sekunden (die offiziellen Beispiele verwenden 10-Sekunden-Intervalle, bis zu 20 Wiederholungsversuche), bis 200 die zusammengeführte Datei zurückgibt.

HTTP aufstellen

Verfahren: POST
URL: https://api.pdf4me.com/api/v2/Merge
Inhaltstyp: application/json
Authorization: Basic <Ihre PDF4me API Schlüssel>

Der Antworttext des Statuscodes 200 ist der zusammengeführte Text. PDF als Rohbytes: direkt speichern. Eine 202-Antwort bedeutet, dass der Merge-Vorgang asynchron ausgeführt wird: regelmäßig abfragen. Location URL bis 200.

Worin unterscheiden sich synchrone und asynchrone Verarbeitung?

Der async Das Flag ändert den Antwortvertrag, nicht das Zusammenführungsergebnis. Auswahl anhand der Batchgröße.

Synchron vs. asynchron"async": false (Standard)"async": true
Antwort auf success200 mit der fusionierten PDF als Rohbytes202 Accepted mit einem Location Umfragen URL
VerbindungBleibt bis zum Abschluss der Zusammenführung offen.Rückgabe sofort
Wie erhalte ich die Datei?Speichern Sie den Antworttext direktGET Die Location URL alle ~10 Sekunden, bis es mit 200 und den Bytes antwortet.
Am besten geeignet fürein paar kleine DateienGroße Mengen und umfangreiche Dokumente

API Körperfelder

ParameterErforderlichTypWas es tutBeispiel
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

Beispielnutzlasten

Zwei zusammenführen PDFs synchron

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

Einen großen Batch asynchron zusammenführen

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

Tipps zur Postboten-Abholung

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.

Beispiel für curl

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

Was bedeutet das? API zurückkehren?

FeldTypWas es enthält
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.

Codebeispiele

Offizielle, ausführbare Beispiele für diesen exakten Endpunkt, pro language:

Häufig gestellte Fragen

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.

Warum fusionieren? PDFs via API statt eines Desktop-Tools?

Desktop- und Web-Zusammenführungstools eignen sich gut für einmalige Aufgaben, benötigen aber einen Benutzer, der Dateien auswählt, sie in die richtige Reihenfolge zieht und das Ergebnis herunterlädt. API Führt dieselbe Verkettung durch wie eine deterministische Anfrage pro Batch, wobei die Reihenfolge durch Ihren Code und nicht per Drag & Drop festgelegt wird. Die Ausgabe ist ein Standardformat. PDF in Übereinstimmung mit der ISO 32000 SpezifikationEs öffnet sich also in jedem Reader und wird nahtlos in den nächsten Pipeline-Schritt eingespeist, sei es die Komprimierung. OCRoder elektronische Signatur.

Ähnliche Aktionen

Dieselbe Aufgabe auf anderen Plattformen

Hilfe erhalten