Appearance
Function: highlightPDF()
ts
function highlightPDF(
pdfFile: MwFile,
parsedItems: ParsedTextItem[],
keyword: string,
color?: Pick<RGB, "red" | "green" | "blue">): Promise<MwFile>;Defined in: src/file/pdf.ts:464
Highlight keyword occurrences in a PDF with colored rectangles.
Draws a semi-transparent rectangle behind each match.
Parameters
| Parameter | Type | Description |
|---|---|---|
pdfFile | MwFile | The source PDF as an MwFile. |
parsedItems | ParsedTextItem[] | Text items parsed from the PDF (with position data). |
keyword | string | The word or phrase to highlight. Case-insensitive. |
color | Pick<RGB, "red" | "green" | "blue"> | The rectangle fill color. Defaults to green. |
Returns
Promise<MwFile>
A new MwFile with highlights drawn on matching text.
Example
ts
const highlighted = await highlightPDF(
contractPdf,
parsedTextItems,
'confidential',
{ red: 1, green: 0.9, blue: 0 },
);
console.log(highlighted.name); // same as the original file name