Lewati ke konten utama

Linearisasi PDF

PDF4me Linearisasi PDF adalah sebuah REST titik akhir yang merestrukturisasi sebuah PDF untuk tampilan web yang cepat. POST berkas sebagai Base64 ke /api/v2/LinearizePdf dengan sebuah optimizeProfile, dan API Mengatur ulang objek internalnya sehingga halaman pertama ditampilkan sementara halaman lainnya masih diunduh, lalu mengembalikan versi yang telah dilinierkan. PDF sebagai byte mentah. Sembilan profil mencakup web, cetak, dan kompresi.

Fungsi dari endpoint ini

Mengambil PDF dan mengembalikan dokumen yang sama yang diatur ulang untuk pemuatan progresif: informasi direktori dan sumber daya halaman 1 dipindahkan ke bagian depan file, sehingga peramban atau penampil terintegrasi menampilkan halaman pertama hampir secara langsung alih-alih menunggu seluruh unduhan. pages Data itu sendiri tidak tersentuh. Ideal untuk portal dokumen, CDN, dan apa pun. PDF disajikan di atas HTTP.

Postingan Blog Terkait
Belum ada postingan blog untuk fitur ini — akan segera hadir.
Sementara itu, jelajahi blog PDF4me untuk menemukan tutorial dan alur kerja di berbagai platform.
Kunjungi blog ini

Memverifikasi Identitas Anda API Meminta

Setiap PDF4me REST panggilan harus menyertakan Anda API kunci di Authorization Header sebagai otentikasi Dasar. Dapatkan atau putar kunci Anda dari dasbor pengembang.

Titik akhir

POST/api/v2/LinearizePdf

Fakta Penting yang Tidak Boleh Anda Lewatkan

Benderanya adalah async, bukan IsAsync.
Contoh resmi mengirimkan saklar asinkron sebagai huruf kecil. asinkron, A JSON boolean. Kunci dengan penulisan huruf besar/kecil yang salah akan diabaikan secara diam-diam dan file besar Anda akan diproses secara sinkron.
Respons 200 adalah PDF dirinya sendiri
Isi datanya berupa biner mentah: tulis langsung ke sebuah .pdf berkas. Sampel resmi juga menangani sebuah JSON-dibungkus Base64 Sebagai cadangan defensif, tetapi kontrak utamanya adalah byte.
Sama pages, urutan byte yang berbeda
Linearisasi tidak pernah mengedit konten. Ia hanya mengatur ulang objek internal sehingga halaman 1 dan katalog dokumen berada di bagian depan file, yang memungkinkan penampil untuk melakukan rendering sebelum pengunduhan selesai.

HTTP pengaturan

Metode: POST
URL: https://api.pdf4me.com/api/v2/LinearizePdf
Tipe Konten: aplikasi/json
Authorization: Dasar <Anda PDF4me API kunci>

Badan respons 200 adalah yang dilinierkan. PDF Sebagai byte mentah: simpan langsung. Respons 202 berarti pemrosesan asinkron: lakukan polling. Location URL dengan GET kira-kira setiap 10 detik (sampel resmi menggunakan interval 10 detik, hingga 10 kali percobaan ulang) sampai 200.

OptimizeProfile mana yang harus saya pilih?

Sembilan profil diterima. Mereka terbagi menjadi tiga kelompok dengan tujuan yang berbeda.

Profil keluarga vs tujuanProfilApa yang mereka optimalkan
Webweb, WebMaxTampilan progresif dan rendering halaman pertama yang cepat di browser; WebMax adalah optimasi web yang paling agresif.
MencetakPrint, PrintMax, PrintGrayOutput berorientasi cetak; PrintGray juga mengkonversi ke pencetakan skala abu-abu.
KompresiCompress, CompressMaxUkuran file terkecil; CompressMax mengorbankan lebih banyak pemrosesan untuk pengurangan ukuran file yang lebih besar.
UmumDefault, MaxPengaturan default mesin, dan tingkat optimasi keseluruhan maksimum.

Untuk PDFs disajikan di situs web, dimulai dengan web dan melangkah maju WebMax hanya jika latensi halaman pertama masih penting setelah pengujian.

API bidang tubuh

ParameterDiperlukanJenisApa fungsinya?Contoh
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

Contoh muatan

Linearisasi untuk tampilan web

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

File besar, asinkron

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

Tips pengambilan oleh tukang pos

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.

contoh curl

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

Apa yang dimaksud dengan API kembali?

BidangJenisIsi di dalamnya
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.

Contoh kode

Contoh resmi yang dapat dijalankan untuk endpoint persis ini, sesuai dengan language:

Pertanyaan yang Sering Diajukan (FAQ)

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.

Mengapa melakukan linearisasi? PDFs untuk web?

Standar PDF menyimpan informasi direktori di akhir file, sehingga penampil harus mengunduh hampir semua hal sebelum menampilkan halaman 1. Linearized PDF, didefinisikan sebagai lampiran normatif dari ISO Spesifikasi 32000, memindahkan direktori tersebut dan halaman pertama ke depan, memungkinkan akses bertahap. HTTPUntuk portal dokumen atau CDN, yang mengubah penantian kosong selama beberapa detik menjadi halaman pertama yang muncul sementara halaman lainnya masuk secara bertahap.

Tindakan terkait

Tugas yang sama di platform lain

Dapatkan Bantuan