PDF metadata allows you to embed document properties and searchable information within the PDF file itself. This metadata is visible in PDF readers' document properties/information dialogs and helps with document organization, search, and identification.
Key metadata fields:
- Title - Main document heading
- Author - Document creator
- Subject - Brief document description
- Keywords - Searchable tags
- Creator - Application that created the PDF
- Producer - PDF processing application
- Creation Date - Document generation timestamp
export interface PDFMetadata {
/** Document title */
title?: string;
/** Document author */
author?: string;
/** Document subject */
subject?: string;
/** Document keywords */
keywords?: string[];
/** Creator application name */
creator?: string;
/** Producer application name */
producer?: string;
/** Creation date */
creationDate?: Date;
}import { PDFGenerator } from '@html-to-pdf/generator';
const generator = new PDFGenerator();
const element = document.getElementById('content');
const result = await generator.generate(element, {
metadata: {
title: 'Annual Report 2024',
author: 'Finance Department',
subject: 'Financial Performance Summary',
creator: 'My Application v1.0'
}
});const result = await generator.generate(element, {
metadata: {
title: 'Q4 2024 Business Report',
author: 'John Smith',
subject: 'Quarterly Financial Analysis and Performance Review',
keywords: ['Q4', 'finance', 'report', '2024', 'quarterly'],
creator: 'Company Reporting System',
producer: 'pdf-generator v2.0',
creationDate: new Date()
}
});const result = await generator.generate(element, {
metadata: {
title: 'Product Catalog 2024',
author: 'Marketing Team',
subject: 'Complete Product Listing'
},
headerTemplate: {
template: '<div style="text-align: center;">{{title}}</div>',
height: 12
},
footerTemplate: {
template: '<div style="text-align: right; font-size: 9px;">Page {{pageNumber}}</div>',
height: 10
}
});function generateDocumentWithMetadata(
content: HTMLElement,
title: string,
documentType: 'report' | 'invoice' | 'proposal'
) {
const metadataMap = {
report: {
subject: 'Business Report',
keywords: ['report', 'business', 'analysis'],
creator: 'Report Generator'
},
invoice: {
subject: 'Invoice Document',
keywords: ['invoice', 'billing', 'payment'],
creator: 'Billing System'
},
proposal: {
subject: 'Business Proposal',
keywords: ['proposal', 'business', 'opportunity'],
creator: 'Proposal System'
}
};
const baseMetadata = metadataMap[documentType];
return generator.generate(content, {
metadata: {
title: title,
author: 'System Generated',
...baseMetadata,
creationDate: new Date()
}
});
}const orgMetadata = {
companyName: 'Acme Corporation',
department: 'Finance',
year: 2024
};
const result = await generator.generate(element, {
metadata: {
title: `${orgMetadata.companyName} - ${orgMetadata.department} Report ${orgMetadata.year}`,
author: `${orgMetadata.department} Department`,
subject: `${orgMetadata.companyName} Financial Report`,
keywords: [
'company',
'report',
orgMetadata.companyName.toLowerCase(),
orgMetadata.department.toLowerCase(),
String(orgMetadata.year)
],
creator: 'Acme Reporting System',
creationDate: new Date()
}
});function getTimestampedMetadata(baseTitle: string) {
const now = new Date();
const dateString = now.toLocaleDateString();
const timeString = now.toLocaleTimeString();
return {
title: `${baseTitle} - ${dateString}`,
subject: `Generated on ${dateString} at ${timeString}`,
creator: 'PDF Generator v2.0',
producer: 'jsPDF + html2canvas',
creationDate: now
};
}
const result = await generator.generate(element, {
metadata: getTimestampedMetadata('Monthly Sales Report')
});const result = await generator.generate(element, {
metadata: {
title: 'Comprehensive Guide to PDF Generation | Best Practices',
author: 'Documentation Team',
subject: 'A comprehensive guide covering PDF generation best practices, tips, and techniques',
keywords: [
'PDF',
'generation',
'guide',
'best practices',
'tutorial',
'documentation',
'HTML to PDF',
'how-to'
],
creator: 'Documentation System v1.0',
creationDate: new Date()
}
});const corporateMetadata: PDFMetadata = {
title: 'Corporate Financial Statement Q4 2024',
author: 'Corporate Finance Division',
subject: 'Quarterly Financial Report and Analysis',
keywords: ['financial', 'corporate', 'Q4', '2024', 'statement'],
creator: 'Corporate Finance Portal',
creationDate: new Date()
};const academicMetadata: PDFMetadata = {
title: 'Research Paper: Machine Learning in Healthcare',
author: 'Dr. Jane Doe, Dr. John Smith',
subject: 'An exploration of machine learning applications in healthcare industry',
keywords: ['machine learning', 'healthcare', 'AI', 'research', 'medical'],
creator: 'Academic Publishing System',
creationDate: new Date()
};const legalMetadata: PDFMetadata = {
title: 'Contract Agreement - Service Terms',
author: 'Legal Department',
subject: 'Service Agreement Contract - Effective January 2024',
keywords: ['contract', 'legal', 'agreement', 'terms', 'service'],
creator: 'Legal Document Management System',
creationDate: new Date()
};const invoiceMetadata: PDFMetadata = {
title: 'Invoice #INV-2024-001234',
author: 'Accounting Department',
subject: 'Invoice for Services Rendered',
keywords: ['invoice', 'billing', 'payment', 'receipt'],
creator: 'Billing System v3.0',
creationDate: new Date()
};| Property | Type | Description | Example |
|---|---|---|---|
title |
string | Document title (visible in PDF properties) | "Annual Report 2024" |
author |
string | Creator/author name | "John Smith" |
subject |
string | Short description of document | "Financial Report" |
keywords |
string[] | Searchable tags | ["report", "2024", "finance"] |
creator |
string | Application that created PDF | "My App v1.0" |
producer |
string | PDF processing tool | "jsPDF v2.5" |
creationDate |
Date | Document generation time | new Date() |
-
Consistent Titling: Keep titles concise (under 100 characters) and descriptive
-
Author Information: Use consistent author names across your organization's documents
-
Keywords Strategy:
- Include 5-10 relevant keywords
- Use lowercase and separate with commas
- Think about how users would search for documents
-
Subject Line: Write a brief but informative subject (50-150 characters)
-
Creator Attribution: Include your application name and version for tracking
-
Date Management: Always include creation date for audit trails and document versioning
-
Special Characters: Avoid special characters in metadata fields for maximum compatibility
-
Multilingual: Use English for broader compatibility unless targeting specific locales
-
Document Tracking: Include document IDs or version numbers in title for better organization
-
Searchability: Structure keywords to support your organization's document retrieval processes
- Headers & Footers - Reference document title in headers/footers
- Watermarks - Add document branding
- Security - Protect document with encryption