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.
Header
Content-Type: application/pdfAt a glance
- Extensions
- Kind
- Binary
- Parameters
- None
- In a browser
- Opens in the built-in viewer. With
Content-Disposition: attachmentit 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: inlineopens the PDF in the browser;attachmentdownloads it right away. Afilename="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
Rangerequests with206 Partial Contentand 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-streamorbinary/octet-stream(what S3 stores when an upload names no type), a PDF downloads instead of opening. Set the type when you upload it.