Appearance
Function: highlightPDF()
ts
function highlightPDF(
pdfFile: MwFile,
parsedItems: ParsedTextItem[],
keyword: string,
color?: Pick<RGB, "blue" | "red" | "green">): Promise<MwFile>;Defined in: packages/pdf-tools/lib/pdf.d.ts:201
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, "blue" | "red" | "green"> | 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