Forums

wp-mpdf
[resolved] [Plugin : wp-mpdf] Add featured image and user avatar to pdf (10 posts)

  1. idonic
    Member
    Posted 6 months ago #

    Greetings!

    First of all, i have to say i just found out your plugin and its just great! :)

    I'm trying to costumize it a little but am having a few dificulties doing so.. (probably due to my lack of php skills..)

    I'm wandering if it is possible to display the post's featured image on the pdf top, and also add the logged-in user's avatar on the pdf header..

    Also, where can i edit the css defaults?

    Can you please advise? Thanks in advance!

    http://wordpress.org/extend/plugins/wp-mpdf/

  2. fkrauthan
    Member
    Posted 6 months ago #

    At first you need to add the PHP Code to create the Post image to the PDF Template. You find the PDF templates in /wp-content/wp-mpdf-themes . Just copy default.php and default.css to any Name you like (But the basename for the php and css file should be the same. For example: myTemplate.php and myTemplate.css) Then you can manipulatet it and select it on the mpdf admin settings dialog.

  3. idonic
    Member
    Posted 6 months ago #

    Thanks for your reply!

    The css part is going ok but the php one doesn't..

    I'm currently using the line below to dynamically load the current user's avatar into the homepage header:

    <?php global $current_user; $current_user = wp_get_current_user(); _e(get_avatar($current_user)); ?>

    I was trying to get the same functionality to work with your plugin; it already displays the general avatar on the pdf but i can't get it to make a distinction between users.. :(

    So far i've added these two lines to get the output mentioned:

    (top)
    global $current_user;

    <h1>' . $pdf_output .= (get_avatar('$avatar')) . '</h1>

    (yes, i'm really new to this "php stuff" :))
    Can you point me out on the right direction?

    Thanks again

  4. idonic
    Member
    Posted 6 months ago #

    Got it!

    . get_avatar( wp_get_current_user('user_email', $id), '252')

    I was waaaayy off on this one. :) Now it dynamically loads the current user's avatar on the pdf.

    Thanks again for your help.

  5. fkrauthan
    Member
    Posted 6 months ago #

    No problem :) Your welcome.

  6. enwebsoluciones
    Member
    Posted 2 months ago #

    Hello, I'm trying to add the featured image at the top of the PDF but without success.

    Could you share the code you used?
    Thank you, regards.

  7. idonic
    Member
    Posted 2 months ago #

    To place a featured post image on the pdf file i'm using
    get_the_post_thumbnail( $post->ID, medium)

    Does that solve your issue?

  8. enwebsoluciones
    Member
    Posted 2 months ago #

    but in where I put that line on the plugin code?
    thank you.

  9. idonic
    Member
    Posted 2 months ago #

    You should place that in the pdf template you create.

    By default, template location is wp-content/wp-mpdf-themes/default.php.

    To costumize your pdf's just create a copy of default.php (let's say default_2.php), and edit it according to your needs.

    You are also required to make a copy of the default.css file in order to edit the styles of your template. (you have to name them the same: default_2.php and default_2.css)

    On the default.php file you'll notice a page structure which then you can costumize according to your needs. And that is where you'll use that piece of code to call forth the thumbnail's featured image.

  10. enwebsoluciones
    Member
    Posted 2 months ago #

    Thank you! It Work now!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags