Highlight search text in embedded pdf

1,715 views
Skip to first unread message

Sally

unread,
Mar 10, 2016, 9:39:04 AM3/10/16
to Omeka Dev
Hi,

I am using PdfEmbed to display pdf files. Is there a way to highlight search text in the pdf document itself without using the "find tool" in the pdf viewer? Basically I want to pass the search term from the URL query and highlight all matches in the pdf document.

Thanks,

Anurag Spatzenegger

unread,
Mar 10, 2016, 10:18:10 AM3/10/16
to omek...@googlegroups.com
I was looking into this issue a while ago, and at that time it was not possible due to security restrictions of PDF.js preventing search terms to be directly passed to the script.

However, that was some time ago, and at least according to this thread things have changed - https://github.com/mozilla/pdf.js/issues/1875. Looks like you can pass the search parameters in the URL via GET, and modify viewer.js with the sample code towards the bottom of the page in order to parse them correctly.

If you decide to try it out, let me know how it works.

Anurag
--
You received this message because you are subscribed to the Google Groups "Omeka Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omeka-dev+...@googlegroups.com.
To post to this group, send email to omek...@googlegroups.com.
Visit this group at https://groups.google.com/group/omeka-dev.
For more options, visit https://groups.google.com/d/optout.


Sally

unread,
Mar 11, 2016, 10:30:29 AM3/11/16
to Omeka Dev
Thanks for link, Anurag.

 Actually, the feature is already implemented in the latest version of Pdf.js (1.4.20). I updated the pdf.js library to v.1.4.20 in PdfEmbed plugin. Yes, it works! Just need to append search param to src file path in PdfEmbedPlugin.php, function embedPdfJs($file, $options):

$query = htmlspecialchars($_GET["query"]);
$attrs['src'] = $pdfJsViewer
            . '?file=' . rawurlencode($file->getWebPath('original'))
            . $hash . '#zoom=100&' . 'search=' . $query;








Anurag Spatzenegger

unread,
Mar 11, 2016, 10:48:45 AM3/11/16
to omek...@googlegroups.com
Oh, excellent! Thanks for the update - I'll have to give it a try.
Reply all
Reply to author
Forward
0 new messages