Skip to content

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

ParameterTypeDescription
pdfFileMwFileThe source PDF as an MwFile.
parsedItemsParsedTextItem[]Text items parsed from the PDF (with position data).
keywordstringThe word or phrase to highlight. Case-insensitive.
colorPick<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

Matterway Assistant SDK Documentation