javascript - How to use the search feature in PDFObject? -
i'm using pdfobject try search pdf term , highlight it. website generates code such application automatically reason code isn't searching pdf @ all, nor highlighting word want highlight... know how can or rectify code?
here code website auto generates me (in html):
<!-- insert in document body --> <object data='sample#search=location&highlight=20,20,20,20' type='application/pdf' width='100%' height='100%'> <p>it appears web browser not configured display pdf files. no worries, <a href='sample'>click here download pdf file.</a></p> </object>
the search term want find (and have highlighted) in pdf object word called 'location'.
i've copied code overall html code, follows:
<html> <head> <title>pdfobject example</title> <script type="text/javascript" src="pdfobject.js"></script> <script type="text/javascript"> window.onload = function (){ var mypdf = new pdfobject({ url: "sample.pdf" }).embed(); }; </script> </head> <body> <object data='sample.pdf#search=location&highlight=20,20,20,20' type='application/pdf' width='100%' height='100%'> <p>it appears web browser not configured display pdf files. no worries, <a href='sample.pdf'>click here download pdf file.</a></p> </body> </object> </html>
thanks in advance!
update (7/13)
the code provided pipwerks works perfectly, thank you. have 1 remaining question; used 'this' code (see below) add highlight search term, highlighting not automatically show when search term; idea how resolve that? essentially, when pdf opens in acrobat, search function working fine, , in left menu pane, can see results of search; terms searching not automatically highlighted on screen upon pdf loading; there anyway set terms i'm searching highlighted upon loading pdf?
<html> <head> <script type="text/javascript" src="pdfobject.js"></script> <script type='text/javascript'> function embedpdf(){ var mypdf = new pdfobject({ url: 'sample.pdf', pdfopenparams: { search: 'b27-1', highlight: '30,30,30,10' } }).embed(); } window.onload = embedpdf; //feel free replace window.onload if needed. </script> </head> </object> </html>
here pdf looks when index.html (the search feature works correctly, term isn't highlighted default).
here want pdf upon loading index.html; if click search term, highlight box appears (as seen in image). highlight box load pdf whatever search term trying find on map.
any appreciated, you've been lifesaver pipwerks, help!
unfortunately, pdf open parameters adobe-specific , don't work in pdf readers, including built-in pdf viewers in chrome , firefox. in fact, it's been an issue/feature request in google's chromium project 5 years.
does work in adobe reader?
-- update --
re-reading post, code not correct. have mixed static , javascript options -- need pick 1 or other. have written it, javascript (which doesn't include search params) overwriting html version.
javascript method:
<html> <head> <title>pdfobject example</title> <script type="text/javascript" src="pdfobject.js"></script> <script type='text/javascript'> function embedpdf(){ var mypdf = new pdfobject({ url: 'sample.pdf', pdfopenparams: { search: 'location' } }).embed(); } window.onload = embedpdf; </script></head> <body> </body> </html>
static html method:
<html> <head> <title>pdfobject example</title> </head> <body> <object data='sample.pdf#search=location' type='application/pdf' width='100%' height='100%'> <p>it appears web browser not configured display pdf files. no worries, <a href='sample.pdf'>click here download pdf file.</a></p> </object> </body> </html>
Comments
Post a Comment