Wordpress shortcode : Simple embedding PDF


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.  * Code modified by: Street.Walker [at] masedi [dot] net
  3.  * Simple embedding PDF, Presentation file to blog post with Google view.
  4.  * ex: http://docs.google.com/viewer?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true
  5.  * or: http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true
  6.  * embed it with HTML iFrame: <iframe src="http://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
  7.  * Source from: http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html
  8.  * implementation for WordPress: use shortcodes
  9.  * usage: [embedpdf width="600px" height="500px"]http://infolab.stanford.edu/pub/papers/google.pdf[/embedpdf]
  10.  * adopted from: http://www.wprecipes.com/wordpress-tip-create-a-pdf-viewer-shortcode
  11.  *
  12.  * Copy the code and paste it to your functions.php file under your active theme
  13.  */
  14.  
  15. function viewpdf($attr, $url) {
  16. return '<iframe src="http://docs.google.com/viewer?url=' . $url . '&embedded=true" style="width:' .$attr['width']. '; height:' .$attr['height']. ';" frameborder="0">Your browser should support iFrame to view this PDF document</iframe>';
  17. }
  18. add_shortcode('embedpdf', 'viewpdf');

URL: http://www.wprecipes.com/wordpress-tip-create-a-pdf-viewer-shortcode

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.