If you don't have an account with Aspose Cloud, Click here to Sign Up.

current_action(); $allowed_actions = array("aspose_export_pdf"); if(!in_array($action, $allowed_actions)) return; // security check check_admin_referer('bulk-posts'); // make sure ids are submitted. depending on the resource type, this may be 'media' or 'ids' if(isset($_REQUEST['post'])) { $post_ids = array_map('intval', $_REQUEST['post']); } if(empty($post_ids)) return; // this is based on wp-admin/edit.php $sendback = remove_query_arg( array('exported', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); if ( ! $sendback ) $sendback = admin_url( "edit.php?post_type=$post_type" ); $pagenum = $wp_list_table->get_pagenum(); $sendback = add_query_arg( 'paged', $pagenum, $sendback ); switch($action) { case 'aspose_export_pdf': $exported = count($post_ids); $post_contents = aspose_pdf_exporter_array_builder($post_ids); if ( is_array($post_contents) && count($post_contents) > 0 ) { $file_name = aspose_pdf_exporter_array_to_html($post_contents); include_once('asposePdfConverter.php'); } else { wp_die( __('Error exporting post.') ); } global $html_filename; $file_name = str_replace('.html','.pdf',$html_filename); $upload_dir = wp_upload_dir(); $upload_path = $upload_dir['path'] . '/'; $file_name = $upload_path . $file_name; $file_details = pathinfo($file_name); if($file_details['extension'] == 'pdf') { header ("Content-type: octet/stream"); header ("Content-disposition: attachment; filename=".basename($file_name).";"); header("Content-Length: ".filesize($file_name)); readfile($file_name); exit; } else { echo "Invalid File!"; } break; default: return; } $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), $sendback ); wp_redirect($sendback); exit(); } function aspose_pdf_exporter_array_builder($post_ids) { foreach($post_ids as $post_id) { $post_data = get_post($post_id); $post_title = $post_data->post_title; $post_content = apply_filters('the_content',$post_data->post_content) ; $post_contents[$post_title] = $post_content; } if(is_array($post_contents)) { return $post_contents; } else { return false; } } function aspose_pdf_exporter_array_to_html($post_contents){ global $html_filename; $upload_dir = wp_upload_dir(); $upload_path = $upload_dir['path'] . '/'; $html_filename = 'output_'.time().'.html'; $output_string = << EOD; foreach($post_contents as $post_title=>$post_content) { $output_string .= << {$post_title}

{$post_content}


EOD; } $output_string .= << EOD; @unlink($upload_path . $html_filename); file_put_contents($upload_path . $html_filename,$output_string); return $upload_path . $html_filename; }