Metadata & Watermarks
This section covers document metadata updates and adding custom semi-transparent watermark text to PDF pages.
1. Edit Metadata
Update author, subject, title, creator, keywords, and producer details.
Signature
interface MetadataOptions {
title?: string;
author?: string;
subject?: string;
creator?: string;
keywords?: string[];
producer?: string;
}
function editMetadata(
file: File | Blob | ArrayBuffer | Uint8Array,
metadataOptions: MetadataOptions
): Promise<Uint8Array>
Example
import { editMetadata } from "@manojcoder/pdf-utils";
async function updateMeta(file: File) {
const metadata = {
title: "Official Quarterly Report",
author: "Manoj Kumawat",
keywords: ["Finance", "Audit"]
};
const bytes = await editMetadata(file, metadata);
const blob = new Blob([bytes], { type: "application/pdf" });
// Process blob...
}
2. Add Watermark
Overlay a diagonal text stamp on all pages.
Signature
interface WatermarkOptions {
fontSize?: number;
opacity?: number;
rotation?: number; // angle in degrees
color?: string; // Hex color code
}
function addWatermark(
file: File | Blob | ArrayBuffer | Uint8Array,
text: string,
options?: WatermarkOptions
): Promise<Uint8Array>
Example
import { addWatermark } from "@manojcoder/pdf-utils";
async function stampFile(file: File) {
const options = {
fontSize: 60,
opacity: 0.2,
rotation: 45,
color: "#FF0000" // Red watermark
};
const bytes = await addWatermark(file, "INTERNAL ONLY", options);
const blob = new Blob([bytes], { type: "application/pdf" });
// Process blob...
}
Transparency: The default opacity is set to 0.3, which keeps the watermark visible without obscuring the underlying document text.