The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Create pdf for entry view
I successfully added a pdf button to print estimates created with Formidable. I used wp-mpdf plugin, which uses the mPDF PHP class. The plugin documentation is pretty narrow so I'll share the steps with you while it's still fresh in my mind...
1) create a new Single Entry view and place anything you want to show in content, as per usual. On Settings, add a filter with Entry ID equal to [get param="entry"].
2) install wp.mpdf plugin and activate it. Create a template according to plugin instructions: copy default.php and default.css to a new folder titled "wp-mpdf-themes" in wp-content. Change the file names (ex. my_template.php and my_template.css), go to the plugin settings and change Thema (sic) to my_template.
3) On my_template.php check for the $pdf-output variable. That's where most of the layout (except header and footer) is rendered. Add the custom display shortcode within it:
FrmProDisplaysController::get_shortcode(array('id' => x, 'filter' => 1))
where x is the ID or key of the View you would like to insert. For example:
$pdf_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>My Template</title> </head> <body xml:lang="en"> <bookmark content="'.htmlspecialchars(get_bloginfo('name'), ENT_QUOTES).'" level="0" /><tocentry content="'.htmlspecialchars(get_bloginfo('name'), ENT_QUOTES).'" level="0" /> <div id="header"></div> <div id="content" class="widecolumn">'; if(have_posts()) : while (have_posts()) : the_post(); $pdf_output .= '<div class="post"><div class="entry">' . FrmProDisplaysController::get_shortcode(array('id' => x, 'filter' => 1)) . '</div></div> <!-- post -->'; endwhile; else : $pdf_output .= '<h2 class="center">Not Found</h2> <p class="center">Sorry, but you are looking for something that isn't here.</p>'; endif; $pdf_output .= '</div> <!--content--></body></html>';
4) Add a link to view the PDF on any custom view that uses the form:
<a href="http://mysite.com/frm_display/my_single_entry_view/?entry=[id]&output=pdf" target="blank">View PDF</a>
Where http://mysite.com/frm_display/my_single_entry_view/
is the permalink of the view created in step 1.
If your CSS permits, use classes to transform the link to a button.
Extra Step) If, like me, you want your pdf filenames to be unique, add this filter to your my_template.php file:
function custom_pdf_filename($pdf_filename) { $pdf_filename = 'my_template-' . FrmProEntriesController::get_field_value_shortcode(array('field_id' => x, 'entry_id' => 'entry')) . '.pdf'; return $pdf_filename;} add_filter('mpdf_output_pdf_filename', 'custom_pdf_filename');
Where x is a field with a unique value (in my case, the estimate number).
May 22, 2015 at 11:43 pm
Great find. I will have to test that out when the time comes.
Discussion closed.