Zum Hauptinhalt springen

Linearisieren PDF

PDF4me Linearisieren PDF ist ein REST Endpunkt, der eine PDF für schnelle Webansicht. POST die Datei als Base64 Zu /api/v2/LinearizePdf mit einem optimizeProfileund die API Ordnet seine internen Objekte so um, dass die erste Seite gerendert wird, während der Rest noch heruntergeladen wird, und gibt dann die linearisierte Version zurück. PDF als Rohbytes. Neun Profile decken Web, Druck und Komprimierung ab.

Was dieser Endpunkt bewirkt

Benötigt eine PDF und gibt dasselbe Dokument in einer für progressives Laden neu organisierten Form zurück: Verzeichnisinformationen und Ressourcen der ersten Seite werden an den Anfang der Datei verschoben, sodass ein Browser oder eingebetteter Viewer die erste Seite fast sofort anzeigt, anstatt auf den vollständigen Download zu warten. pages Sie selbst bleiben unberührt. Ideal für Dokumentenportale, CDNs und alle anderen. PDF serviert über HTTPDie

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/LinearizePdf

Wichtige Fakten, die Sie nicht verpassen sollten

Das Flag ist async, nicht IsAsync.
Die offiziellen Beispiele senden den asynchronen Schalter als Kleinbuchstaben. asynchron, A JSON Boolescher Wert. Ein falsch geschriebener Schlüssel wird stillschweigend ignoriert und Ihre große Datei wird synchron verarbeitet.
Eine Antwort von 200 ist die PDF selbst
Der Textkörper ist roher Binärcode: Schreiben Sie ihn direkt in eine .pdf Datei. Die offiziellen Beispiele behandeln auch eine JSON-umwickelt Base64 Als Ausweichlösung dient der Schutz der Verteidigung, der primäre Vertrag besteht jedoch aus Bytes.
Dasselbe pagesunterschiedliche Byte-Reihenfolge
Die Linearisierung verändert niemals den Inhalt. Sie ordnet interne Objekte neu an, sodass Seite 1 und der Dokumentenkatalog am Anfang der Datei stehen, wodurch Betrachter die Datei rendern können, bevor der Download abgeschlossen ist.

HTTP aufstellen

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

Ein 200-Antwortkörper ist der linearisierte PDF als Rohbytes: direkt speichern. Eine 202-Antwort bedeutet asynchrone Verarbeitung: regelmäßig abfragen. Location URL mit GET etwa alle 10 Sekunden (die offiziellen Stichproben verwenden 10-Sekunden-Intervalle, bis zu 10 Wiederholungsversuche) bis 200.

Welches Optimierungsprofil sollte ich wählen?

Neun Profile wurden angenommen. Sie lassen sich in drei Gruppen mit unterschiedlichen Zielen einteilen.

Profil Familie vs. ZielProfileWofür sie optimieren
Webweb, WebMaxProgressive Displaydarstellung und schnelles Laden der ersten Seite im Browser; WebMax ist die aggressivste Weboptimierung.
DruckenPrint, PrintMax, PrintGrayDruckorientierte Ausgabe; PrintGray wandelt auch in Graustufendruck um
KompressionCompress, CompressMaxKleinste Dateigröße; CompressMax reduziert die Dateigröße durch höheren Rechenaufwand.
AllgemeinDefault, MaxDie Standardeinstellungen der Engine und das maximale Gesamtoptimierungsniveau

Für PDFs werden auf Websites bereitgestellt, beginnen Sie mit web und sich weiterentwickeln WebMax nur dann, wenn die Latenzzeit der ersten Seite nach den Tests immer noch relevant ist.

API Körperfelder

ParameterErforderlichTypWas es tutBeispiel
docContentRequiredstringBase64-encoded bytes of the source PDF.JVBERi0xLjcK...
docNameRequiredstringSource PDF filename with its .pdf extension.document.pdf
optimizeProfileRequiredstringOptimization profile. Allowed values: web, Max, Print, Default, WebMax, PrintMax, PrintGray, Compress, CompressMax. Values are case-sensitive as listed.web
asyncOptionalbooleanLowercase JSON boolean. true returns 202 plus a Location URL to poll, for large files. false or omitted returns the linearized PDF directly on 200.true

Beispielnutzlasten

Linearisieren für die Webansicht

{
"docContent": "JVBERi0xLjcKJb...",
"docName": "report.pdf",
"optimizeProfile": "web"
}

Große Datei, asynchron

{
"docContent": "JVBERi0xLjcKJb...",
"docName": "catalog-2026.pdf",
"optimizeProfile": "WebMax",
"async": true
}

Tipps zur Postboten-Abholung

Headers
Content-Type: application/json + Authorization: Basic <apiKey>.
Body
raw JSON with docContent, docName, optimizeProfile, and optionally async (lowercase, boolean).
Response
On 200, use "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 every ~10 seconds until 200.

curl-Beispiel

curl -X POST https://api.pdf4me.com/api/v2/LinearizePdf \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"docContent": "'"$(base64 -w 0 report.pdf)"'",
"docName": "report.pdf",
"optimizeProfile": "web"
}' \
--output linearized.pdf

Was bedeutet das? API zurückkehren?

FeldTypWas es enthält
200 response bodyBinary (application/pdf)The linearized PDF as raw bytes. Save it directly. The official samples also handle a JSON-wrapped Base64 fallback, but binary is the primary contract.
202 Location headerURLAsync mode only: the polling URL. GET it about every 10 seconds (samples: 10 retries) until it returns 200 with the PDF bytes.
4xx/5xx response bodyJSON or textError details: 400 for malformed Base64 or an unknown optimizeProfile value, 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

What is a linearized PDF?+
A PDF whose internal objects are reordered so the first page and its resources sit at the front of the file. A viewer can render page 1 while the rest is still downloading, which is why linearization is also called fast web view.
Does linearization change how the PDF looks?+
No. Pages, text, and images stay identical. Only the internal object order and structure change so browsers and viewers can start rendering before the full file arrives.
Which optimizeProfile should I use for websites?+
Start with web. If load speed matters more than anything else, WebMax applies the most aggressive web optimization. The print and compress profiles target paper output and file size instead of progressive display.
Is the async flag called IsAsync?+
No. The official samples send it as lowercase async, a JSON boolean. Sending true switches the API to 202-plus-polling mode; false or omitting it returns the linearized PDF directly in the response body.
Is the response JSON with a Base64 file inside?+
Normally no: a 200 response body is the linearized PDF as raw bytes, ready to save. The official samples also defensively handle a JSON-wrapped Base64 variant, but the primary contract is binary.
How is this different from Compress PDF?+
Compress PDF exists to shrink file size. Linearize PDF exists to reorder the file for progressive display; the Compress and CompressMax profiles borrow some size reduction, but if pure size is the goal, use the dedicated Compress PDF endpoint.
Does my web server need special support?+
For the full benefit the server should support HTTP byte-range requests, which mainstream web servers and CDNs do by default. The linearized file still opens normally everywhere, even without range support.

Warum linearisieren? PDFs fürs Web?

Ein Standard PDF Die Verzeichnisinformationen werden am Ende der Datei gespeichert, daher muss ein Betrachter praktisch alles herunterladen, bevor Seite 1 gerendert werden kann. Linearisiert PDF, definiert als ein normativer Anhang der ISO 32000 Spezifikationverschiebt dieses Verzeichnis und die erste Seite an den Anfang und ermöglicht so den inkrementellen Zugriff über HTTPFür ein Dokumentenportal oder CDNDadurch wird eine mehrsekündige Wartezeit ohne Inhalt in eine erste Seite umgewandelt, die erscheint, während der Rest nachgeladen wird.

Ähnliche Aktionen

Dieselbe Aufgabe auf anderen Plattformen

Hilfe erhalten