Frequently Asked Question:
How can I highlight text in an existing pdf?
Question
How can I highlight text in an existing pdf? I can get coordinates of the required text by GetPageText(4) but do not know what methods can take those coordinates and highlight the text? Please advise...
Answer
I figured out how to highlight. Before, I looked a way to add a highlight annotation, but highlighting can be done by adding a background layout and a colored rectangle to it. See the following snippet:
QuickPDFAX0718.PDFLibrary qp = new QuickPDFAX0718.PDFLibrary();
qp.UnlockKey(LicenseKey);
if (qp.LoadFromFile(input_pdf) == 0)
{
message("Could not load file " + input_pdf);
return;
}
qp.SelectPage(1);
int l = qp.NewLayer();
if (qp.MoveLayer(l, 1) == 0
|| qp.SelectLayer(1) == 0
|| qp.SetFillColor(1, 0, 0) == 0
|| qp.DrawBox(229.92, 679, 169, 27, 1) == 0
)
{
message("Could not highlight text");
return;
}
if (qp.SaveToFile(output_pdf) == 0)
{
message("Could not save file " + output_pdf);
return;
}