Tell us what you are trying to do?
Create a custom plugin to enable a button shortcode (or function) that when used to a page (or page button) that will create a PDF with the data from some views with the use of the FPDF (hidden link) which will be downloaded by the user.
Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/views-api/#render_view
hidden link
Right now I have created the code for creating a simple PDF form but when I call the "render_view()" I get the error
<?php
/*
* Plugin Name: My Custom PDF Creator with FPDF
* Description: A plugin created to build a PDF document.
* Version: 1.0
* Author: Sotiris Krontiris
* Author URI: <em><u>hidden link</u></em>
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
include( 'my-pdf-creator-helper-functions.php');
$pdf = new PDF_HTML();
if( isset($_POST['generate_posts_pdf'])){
output_pdf();
}
add_action( 'admin_menu', 'as_fpdf_create_admin_menu' );
function as_fpdf_create_admin_menu() {
$hook = add_submenu_page(
'tools.php',
'My Custom PDF Generator',
'My Custom PDF Generator',
'manage_options',
'as-fdpf-tutorial',
'as_fpdf_create_admin_page'
);
}
function output_pdf() {
/*
$posts = get_posts( 'posts_per_page=5' );
if( ! empty( $posts ) ) {
global $pdf;
$title_line_height = 10;
$content_line_height = 8;
$pdf->AddPage();
$pdf->SetFont( 'Arial', '', 42 );
$pdf->Write(20, 'VESSELJOIN.COM');
foreach( $posts as $post ) {
$pdf->AddPage();
$pdf->SetFont( 'Arial', '', 22 );
$pdf->Write($title_line_height, $post->post_title);
// Add a line break
$pdf->Ln(15);
// Image
$page_width = $pdf->GetPageWidth() - 20;
$max_image_width = $page_width;
$image = get_the_post_thumbnail_url( $post->ID );
if( ! empty( $image ) ) {
$pdf->Image( $image, null, null, 100 );
}
// Post Content
$pdf->Ln(10);
$pdf->SetFont( 'Arial', '', 12 );
$pdf->WriteHTML($post->post_content);
}
}
*/
global $pdf;
$title_line_height = 10;
$content_line_height = 8;
$pdf->AddPage();
$pdf->SetFont( 'Arial', '', 42 );
$pdf->Write(20, '.COM');
// Add a line break
$pdf->Ln(15);
// Image
$page_width = $pdf->GetPageWidth() - 20;
$max_image_width = $page_width;
//$image = get_the_post_thumbnail_url( $post->ID );
//if( ! empty( $image ) ) {
// $pdf->Image( $image, null, null, 100 );
//}
//Display Personal Details
$args = array(
'name' => 'print-personal-data'
);
$pdf->Ln(10);
$pdf->SetFont( 'Arial', '', 12 );
//$pdf->WriteHTML(render_view( $args ));
//$pdf->Write(render_view( array( 'id' => 57530 ) ));
$view_data = render_view( array( 'id' => 57530 ) );
$viewdata_returned = sprintf($view_data);
$pdf->WriteHTML( $viewdata_returned );
$pdf->Output('D','cv-form.pdf');
exit;
}
function as_fpdf_create_admin_page() {
?>
<div class="wrap">
<h1>My Custom - WordPress PDF Generator</h1>
<p>Click below to generate a pdf from the content inside all the WordPress Posts. </p>
<p>Each post will be on its own pdf page containing the post title and post content.</p>
<form method="post" id="as-fdpf-form">
<button class="button button-primary" type="submit" name="generate_posts_pdf" value="generate">Generate PDF from WordPress Posts</button>
</form>
</div>
<?php
}
########Error!
[14-Jun-2020 12:06:16 UTC] PHP Fatal error: Uncaught Error: Call to undefined function render_view() in /var/www/wp-content/plugins/my-pdf-creator/my-pdf-creator-tutorial.php:102
Stack trace:
#0 /var/www/wp-content/plugins/my-pdf-creator/my-pdf-creator-tutorial.php(18): output_pdf()
#1 /var/www/wp-settings.php(371): include_once('/var/www/wp-con...')
#2 /var/www/wp-config.php(126): require_once('/var/www/wp-set...')
#3 /var/www/wp-load.php(37): require_once('/var/www/wp-con...')
#4 /var/www/wp-admin/admin.php(34): require_once('/var/www/wp-loa...')
#5 /var/www/wp-admin/tools.php(40): require_once('/var/www/wp-adm...')
#6 {main}
thrown in /var/www/wp-content/plugins/my-pdf-creator/my-pdf-creator-tutorial.php on line 102
The credentials of the site are in the below link:
https://toolset.com/forums/topic/filtering-view-with-two-complex-relationships/#post-1637351