Adobe Portable Document Format
application/pdf
Magic Bytes
Offset: 0
25 50 44 46 2D
The Portable Document Format (PDF) is a standardized file format developed by Adobe and currently maintained by the International Organization for Standardization. This format preserves document layout and formatting across platforms, making it the global standard for distributing legal documents, electronic books, and professional print materials. Although generally categorized as safe, PDFs can contain interactive components like JavaScript or embedded attachments that require modern reader applications to utilize sandboxing for secure execution.
Validation Code
How to validate .pdf files in Python
Python
def is_pdf(file_path: str) -> bool:
"""Check if file is a valid PDF by magic bytes."""
signature = bytes([0x25, 0x50, 0x44, 0x46, 0x2D])
with open(file_path, "rb") as f:
return f.read(5) == signature
How to validate .pdf files in Node.js
Node.js
function isPDF(buffer: Buffer): boolean {
const signature = Buffer.from([0x25, 0x50, 0x44, 0x46, 0x2D]);
return buffer.subarray(0, 5).equals(signature);
}
Go
func IsPDF(data []byte) bool {
signature := []byte{0x25, 0x50, 0x44, 0x46, 0x2D}
if len(data) < 5 {
return false
}
return bytes.Equal(data[:5], signature)
}
API Endpoint
GET
/api/v1/pdf
curl https://filesignature.org/api/v1/pdf