DevToolsmith

PDF MIME Type

application/pdf is the MIME type for PDF documents. Here is the Content-Type header to send, the file signature, and how to configure servers and code.

MIME type
application/pdf
Extensions
.pdf
Content-Type header
application/pdf
Registered
Yes, with IANA
Compress with gzip
No, it is already compressed
Category
Documents

About PDF document files

With application/pdf, browsers open the file in their built-in PDF viewer. Add Content-Disposition: attachment to make them download it instead. PDF content streams are usually compressed already, so gzip on the fly saves little.

  • A PDF that downloads as file.pdf.html or shows as garbage was almost always sent as text/html or application/octet-stream, often by an error page or a misconfigured proxy.
  • For uploads, check that the file starts with %PDF-; the type the browser reports is based only on the extension.

Other types seen for these files: application/x-pdf . Accept them when reading uploads, but send application/pdf yourself.

File signature

PDF files start with 25 50 44 46 2D ("%PDF-"). The extension and the type a browser reports for an upload both come from the file name, so check these bytes on the server before trusting a file.

Serve .pdf with the right Content-Type

Response header
Content-Type: application/pdf
nginx (a line in the types { } block of mime.types)
application/pdf pdf;
Apache (.htaccess or server config)
AddType application/pdf .pdf
Caddy
@pdf path *.pdf
header @pdf Content-Type "application/pdf"
Check what a server sends
curl -sI https://example.com/file.pdf | grep -i '^content-type'
# Content-Type: application/pdf

Set the type in code

Node.js (Express)
res.set('Content-Type', 'application/pdf');
// Or make the browser download it:
res.attachment('file.pdf');
Python
import mimetypes

mimetypes.add_type('application/pdf', '.pdf')  # if your system doesn't know it
mimetypes.guess_type('file.pdf')[0]  # 'application/pdf'
Go
mime.AddExtensionType(".pdf", "application/pdf")
w.Header().Set("Content-Type", "application/pdf")

Accept .pdf uploads

HTML
<input type="file" accept=".pdf,application/pdf">

The accept attribute only filters the file picker; users can still choose another file. Listing the extension as well as the type matters, because operating systems don’t always report the type you expect.

Related types

  • .docx (application/vnd.openxmlformats-officedocument.wordprocessingml.document): Word document
  • .epub (application/epub+zip): EPUB e-book
  • .txt (text/plain): Plain text

More documents

.doc , .xls , .xlsx , .ppt , .pptx , .odt , .rtf . Look up any extension or type with the MIME type lookup.

Sources

Spotted a mistake? Email hello@devtoolsmith.com and we’ll fix it.

Frequently asked questions

What is the MIME type for .pdf files?

application/pdf. You may also see application/x-pdf, which is older or unofficial; send application/pdf. The full header is "Content-Type: application/pdf".

Why does my server send the wrong Content-Type for .pdf?

Web servers pick the type from the file extension using a table (mime.types in nginx and Apache). If .pdf is missing from that table, they send a default such as application/octet-stream or text/plain. Add the mapping as shown on this page, then check the response with "curl -sI".

How can I check that a file really is PDF?

Look at the first bytes rather than the extension or the type the browser reports, which both come from the file name. PDF files start with 25 50 44 46 2D ("%PDF-"). The MIME type lookup on this site reads them for you when you drop a file on it.