Developer Toolbox

application/pdf

application/pdf is the registered type for PDF documents (RFC 8118). Browsers have a built-in viewer for it, so the response headers decide whether a PDF opens in a tab or downloads.

Open in cURL Builder A request with this type is filled in.

Header

Content-Type: application/pdf

At a glance

Extensions
.pdf
Kind
Binary
Parameters
None
In a browser
Opens in the built-in viewer. With Content-Disposition: attachment it downloads instead.

With curl

curl -o invoice.pdf -H 'Accept: application/pdf' https://api.example.com/invoices/42

With fetch

const res = await fetch('https://api.example.com/invoices/42', { headers: { Accept: 'application/pdf' } });
const url = URL.createObjectURL(await res.blob());
// A download link: after an await, popup blockers stop a new window.
const a = Object.assign(document.createElement('a'), { href: url, download: 'invoice.pdf' });
a.click();

Common mistakes

  • Inline or attachment

    Content-Disposition: inline opens the PDF in the browser; attachment downloads it right away. A filename="invoice.pdf" suggests the name to save it under, which some built-in viewers ignore in favour of the URL.

  • Large files and Range

    A viewer can show the first pages before the rest arrives when the server answers Range requests with 206 Partial Content and the PDF is saved for fast web view. Static file servers do this; a handler that streams the file itself usually does not.

  • Stored with the wrong type

    Served as application/octet-stream or binary/octet-stream (what S3 stores when an upload names no type), a PDF downloads instead of opening. Set the type when you upload it.