简体   繁体   English

按钮下载PDF文件

[英]Button to download PDF file

On the current page I already have button , which enrols me in a course, now I want to add such button to download the summary of the course in pdf . 在当前页面我已经有button ,这enrols我一门课程,现在我要添加这种buttondownload过程的总结, pdf The current button looks like this: 当前按钮如下所示:

.= html_writer::div(html_writer::tag("button", get_string('enrol', 'local_customenrol'), array('class' => 'ebutton')), 'enrol');

I added the Download in PDF button like this: 我添加了“ Download in PDF按钮,如下所示:

.= html_writer::div(html_writer::tag("button", get_string('printpdf', 'local_customenrol'), array('class' => 'printpdf')), 'printpdf');

The enrol button works with javascript in local_customenrol.js , the printing of the page summary is made in printpdf.php , I just can not make it to trigger the download . 登记按钮与local_customenrol.js javascript一起local_customenrol.js ,页面摘要的打印在printpdf.php ,但我无法触发download I preffer to make it in php , if possible, or should I use javascript ? 我愿意在php制作它,或者应该使用javascript

I've found that to print links to course summary files you have to do something like this: 我发现要打印课程摘要文件的链接,您必须执行以下操作:

$course = get_course($courseid);
$url = '';
foreach ($course->get_course_overviewfiles() as $file) {
    $url = file_encode_url($CFG->wwwroot.'/pluginfile.php',
                           '/'.$file->get_contextid().'/'.
                           $file->get_component().'/'.
                           $file->get_filearea().
                           $file->get_filepath().
                           $file->get_filename(), !$isimage); 
    echo html_writer::link($url, 'Download course file', array('class' => 'btn btn-secondary span3'));
}

With this you will print a link for each file attached to an existing course and will not need to render the PDF using php. 这样,您将为连接到现有课程的每个文件打印一个链接,并且无需使用php呈现PDF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM