humanmade/voce-post-pdfs

Name: voce-post-pdfs

Owner: Human Made

Description: null

Forked from: voceconnect/voce-post-pdfs

Created: 2017-12-22 00:22:54.0

Updated: 2017-12-22 00:22:56.0

Pushed: 2017-12-22 01:08:11.0

Homepage: null

Size: 6287

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Voce Post PDFs

Contributors: johnciacia, kevinlangleyjr, brockangelo
Tags: printing, pdf
Requires at least: 3.2
Tested up to: 3.8.3
Stable tag: 1.2.3
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

A WordPress plugin/module that generates a pdf from a post.

Description

This plugin generates a PDF file from a post's content using the PHP dompdf library. Simply link to the post + '/pdf/' and a PDF will be generated. You have the ability to customize the upload path, the PDF template that is used, and the filename format through filters.

Installation
As standard plugin:

See Installing Plugins.

As theme or plugin dependency:

After dropping the plugin into the containing theme or plugin, add the following:

! class_exists( 'Voce_Post_PDFS' ) ) {
require_once( $path_to_vpp . '/voce-post-pdfs.php' );

Usage

Add a Download PDF link to /pdf/:

_link = esc_url( trailingslashit( get_permalink() ) . 'pdf/' );
Customize with filters

To modify the logo used in the PDF header:

action( 'voce_post_pdfs_logo', function(){ 
_action('newsroom_custom_header_logo');

Use your own template for the PDF, relative to the theme directory:

filter('voce_post_pdf_print_template', function($template){
turn 'print.php';

Modify query args:

filter('voce_post_pdfs_save_query_args', function($args){
( isset( $_GET['lang'] ) )
 $args['lang'] = $_GET['lang'];
turn $args;

Modify the default filename format (defaults to post-title.pdf):

filter('voce_post_pdfs_save_filename', function($filename) {
ang = ( isset( $_GET['lang'] )  ? '-' . sanitize_key( $_GET['lang'] ) : '');
ilename = basename($filename, '.pdf');
turn $filename . $lang . '.pdf';

Modify the upload location on the server:

filter('voce_post_pdfs_upload_basepath', function($basepath, $post){
ploads = wp_upload_dir();
asepath = $uploads['basedir'] . '/' . date('Y', strtotime($post->post_date) ) . '/' . date('m', strtotime($post->post_date) ) . '/pdf/';                
turn $basepath;
0, 2);

Modify the url to the pdf:

filter('voce_post_pdfs_upload_baseurl', function($baseurl, $post){
ploads = wp_upload_dir();
aseurl = $uploads['baseurl'] . '/' . date('Y', strtotime($post->post_date) ) . '/' . date('m', strtotime($post->post_date) ) . '/pdf/';                
turn $baseurl;
0, 2);

Changelog

1.2.3

1.2.1
Reorganizing the path declarations and pdf existance check in save_post to improve performace.

1.2
Adding a parameter to save_pdf to not overwrite the PDF, if the PDF already exists. get_upload_basepath and get_upload_baseurl are now public, so other plugins can retrieve a PDF's location.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.