Skip to content

Instantly share code, notes, and snippets.

@ucheng
Last active June 23, 2022 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ucheng/9f322c78d0211fa3766757312f4f451e to your computer and use it in GitHub Desktop.
Save ucheng/9f322c78d0211fa3766757312f4f451e to your computer and use it in GitHub Desktop.
Display pdf content in browser
<?php
$response = wp_remote_post($url, $args = array());
$header_content = (array) wp_remote_retrieve_headers( $response );
$header = current($header_content);
$data = wp_remote_retrieve_body( $response );
if ( array_key_exists('content-type', $header) ) {
if ( $header['content-type'] === 'application/pdf') {
header("Content-type: application/pdf");
header('Content-Length: '.strlen( $data ));
header("Content-disposition: inline;filename=filename-pdf");
echo $data;
wp_die();
} else {
echo $data;
wp_die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment