Last active
July 6, 2020 12:41
-
-
Save jchristopher/a295bf2e63e0f45b94febb61fffe2c8c to your computer and use it in GitHub Desktop.
Use Apache Tika to extract PDF content in SearchWP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Use Apache Tika to extract PDF content in SearchWP. | |
add_filter( 'searchwp\parser\pdf', function( $content, $args ) { | |
// Ensure this path is updated to match your Tika installation path! | |
$path_to_tika = '/srv/bin/tika-app-1.18.jar'; | |
// Execute the command. | |
$cmd = "java -jar {$path_to_tika} -t {$args['file']}"; | |
@exec( $cmd, $output, $exitCode ); | |
// If there was a problem, send the output to the debug log. | |
if ( $exitCode ) { | |
do_action( 'searchwp\debug\log', 'Error running Tika, exit code: ' . $exitCode ); | |
} | |
return $output; | |
}, 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment