0

I currently have a members area for subscribers. I have already setup the ability for users to 'favourite' posts and add them to custom folders of their choice. Once they have added some posts to a specific folder, I want them to be able to click download where it will collate that folders posts into a pdf. Doesn't have to be perfect, it just has to be functional for now.

I found a plugin Kalin's PDF creation station, which has an additional backend feature (Tools) which does this perfectly, even offering reordering of the posts before publishing. But I want to know if I can offer this option to a front end subscriber.

Does anyone know if this can be done?

Open to alternative solutions if anyone has any as well.

Below is a screenshot to help. The blurred out titles are 3 seperate posts titles. When they click download, I want those 3 to be compiled into a pdf? Any suggestions?

enter image description here

1
  • hi Graeme ... You should add this as your own answer :) and then wait 24 hours and accept it as the answer
    – Damien
    Commented Oct 17, 2012 at 11:03

2 Answers 2

0

This can be a very complicated area to get involved in .. because

  1. Your users can press Ctrl P in their browser and many have Send To PDF already. And this is better than many PDF plugins as the user is 'printing to PDF' the screen they are looking at

  2. PDF plugins can require a lot of customisation to include or exclude sidebars, banners or other images. But there are customer / frontend plugins like HTML2PDF this is good for single article 'downloads'.

  3. You can also do it yourself as PHP has a number of libraries for HTML2PDF ... one of the best libraries to use is wkhtmltopdf which runs on your server

To allow the customer to choose a number of articles and then 'click to download' to PDF you'll need to develop your own solution using wkhtmltopdf and/or other PHP libraries

2
  • I was afraid of that. Which is ok, but seeing that Kalin's back end tool was already created with the exact functionality i'm after, I hope I could pull the functionality to be on the user end. I guess a further question would be is this possible, regardless of the plugin? Can a front end subscriber access the code/functionality of a backend tool, without have to go into wp-admin. A 'run in the background' process perhaps.
    – zilj
    Commented Oct 15, 2012 at 16:29
  • Fix added to original post :)
    – zilj
    Commented Oct 17, 2012 at 9:37
0

I've managed to answer my own question.

If anyone ever has a simular request, I have now implemented a pretty basic fix.

I decided to download the simplest post2pdf plugin I could find. I settled on WP Post to PDF by Neerav Dobaria, based on the TCPDF script. The code is simplistic and tidy so it allowed me to customise easily.

I decided to pass the post ids as a url parameter with a list of the post ids I wanted (?format=pdf&pids=10,15,21,30), then in the plugin's core php file (/wp-post-to-pdf/wp-post-to-pdf.php) I listend for the parameter and used a simple conditional to get the ids into the core:


    // wp-post-to-pdf/wp-post-to-pdf.php

    [line 124]
    if ($_GET['pids']) {
        $pid_list = $_GET['pids'];
    } else {
        return false; 
    }

    ...

    [line 144]
    // Add the pids as a secondary argument
    if ($includeCache and !in_array($post->ID, $excludeThisCache)){
        $this->generate_pdf_file($pid_list, **$pid_list**);
    } elseif (!$includeCache and in_array($post->ID, $excludeThisCache)){
        $this->generate_pdf_file($pid_list, **$pid_list**);
    } else {
        if (!file_exists($filePath)) {
            $this->generate_pdf_file($pid_list, **$pid_list**);
        }
    }

    ...

    [line 256]
    // Separate the string into an array
    $pid_list = explode(',', $pid_list);

    ...

    [line 321]
    // Add a for each to create a new page for each post id in the list. 
    foreach($pid_list as $pid){
        $pdf->AddPage();
        // Created a new variable for the pids.
        $post_data = get_post($pid); 

        ...

    }

For all instances where $post->parameter exists within this new foreach, you simply need to change it to be the new array variable $post_data->parameter. Then change the plugin's setting accordingly.

Easy! ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.