• I want to upload pdf files via media->add new which should be automatically embedded to a unique page for displaying it. So that I can just give that page link to my client to view the uploaded pdf.

    Please help me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    You need an embedded viewer, it’s not that common, most people are content with the Adobe Reader browser plugin.

    I have not ever embedded a PDF viewer, you might try https://github.com/mozilla/pdf.js. This viewer is a pure HTML5/javascript implementation. At it’s most basic, your page only need provide a blank HTML canvas element, javascript handles everything else. You could create a simple page template for this, or create a custom post type. You’ll need to store the actual PDF URL somewhere associated with the page or CPT you add, a custom field would work.

    You will need to add code, either as a plugin or on a child theme functions.php to enqueue the required javascript files for any pages using this template. Your enqueue script needs some way to know when to enqueue script and when not to. It could either check the post type or page template, depending on which approach you use.

    You also need to pass the stored PDF URL to javascript so it knows which document to load. This can be done with wp_localize_script().

    Thread Starter Raja

    (@rajacse10)

    Hi bcworkz,

    Thank for your reply.

    I’m new to wordpress, sorry actually I don’t know how to create a CTP or template file.

    I’m editing the attachment page itself, is that good to edit the actual attachment page?

    Cheers.

    Moderator bcworkz

    (@bcworkz)

    I’m not sure what you mean by attachment page, I’m guessing it’s one of your theme’s template files? You should not edit any theme files because your changes will be lost when the theme is updated. Instead create a child theme. Copy the template you wish to edit to your child theme folder. You may edit away with this version with no concern for losing your changes when the theme updates.

    Custom page templates are easy. Custom post types are more involved but not too bad. New to WordPress (welcome!) shouldn’t be much of an issue if you have other HTML and javascript coding experience. Even if you don’t, you can probably eventually muddle your way through everything, but it’ll take a fair bit of work learning all the various aspects.

    You might get lucky and cut and paste your way into a solution that actually works, but if it doesn’t work you’ll be totally lost unless you understand what’s going on.

    Thread Starter Raja

    (@rajacse10)

    Thank you so much bcworkz, yes you are right, It is my theme’s template file. As you said, it is easy to edit that file.

    I can create a new template file from my theme’s template file, but I’m not sure when and where to call my temlpate to load.

    Anyway I’m going to learn it from the links you have given, let me try it.

    Once gain thank you so much for your kind reply.

    Cheers,

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Embed pdf automatically after upload via media’ is closed to new replies.