Pod Page to PDF?
Hello,
I'm going to have a Newsletter pod and would like to be able to convert a displayed newsletter record to a PDF, has anyone done this before? I've yet to try any of the Wordpress plugins to be able to covert a post or page to PDF but I'm hoping that one of them will allow me to use a template tag and spit out a convert button. Question is, will it be able to use the pods record generated content?
Ideas?
I'll post my results back here.
- Jonah
4 Answers
Pods is great because its super easy to integrate into many of the PHP scripts/ classes out there. Pods doesn't build PDF's nativity, but i wouldn't see a problem with using one of the many available PDF classes available. Maybe someone can chime in with some experience with a certain one.
I think an easier way than building your own PDF using a PHP library is to use an external web service like http://pdfmyurl.com/ to create a PDF from an existing web page. To use it, simply do something like:
http://pdfmyurl.com/?url=http://www.yoursite.com/path/to/html/print/page/
and it returns a PDF version of that entire page. If you want to go fancier, you can use PHP's cURL functions to fetch the data from the URL and save it to a location on your server or do something else with it.
Thanks, I'll try one of the two options.
- Jonah
The problem with clarinetlord's solution is that you will have all headers and footers, and also the embedded logo for pdfmyurl at your downloaded pdf.
I think the best solution is to use dompdf ( http://code.google.com/p/dompdf/ ). You can use this with a string filled with plain html code
Use the last version of dompdf in your plugin and then you can write a function like this one:
define('PLUGIN_PATH', rtrim(plugin_dir_path(__FILE__),'/'));
require_once(PLUGIN_PATH . "/dompdf/dompdf_config.inc.php");
function pluginname_pod_to_pdf($slug){
$dompdf = new DOMPDF();
global $pods;
$my_pod = pluginname_get_pod_by_slug($slug);
$html = '<html><head></head><body>fill_this_with_data_from_your_pod</body></html> ';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($slug.'.pdf');
}
You can use css style too.
edited Nov 22 '10 at 5:42


