Announcing new plugin - Dompdf for Moodle

Re: Announcing new plugin - Dompdf for Moodle

by Lukas Celinak -
Number of replies: 12
Picture of Plugin developers
Hi, i tested plugin ,but i had exproted broken PDF file when im try to use functionf for images rewrite.
In reply to Lukas Celinak

Re: Announcing new plugin - Dompdf for Moodle

by Darko Miletić -
Show us the code in question
In reply to Darko Miletić

Re: Announcing new plugin - Dompdf for Moodle

by Lukas Celinak -
Picture of Plugin developers

view,php:
$download = optional_param('download', false, PARAM_BOOL);

if ($download) {
    $printid = required_param('printid', PARAM_INT);
    $slotid = required_param('slotid', PARAM_INT);
    $document = timetable_generate_document($printid, $slotid);
    //echo $document;
    $pdf = \local_dompdf\api\pdf::createnew();
    $pdf->loadHtml($document);
    $pdf->render();
    send_file(
            $pdf->output(), 'document.pdf', null, 0, true, true, 'application/pdf'
    );
}

and generating of content in function:
$template->body = \local_dompdf\api\pdf::file_rewrite_image_urls($template->docbody, $template->id, 'body', $context->id, 'mod_timetable');

$options = [
'noclean' => true, 'para' => false, 'filter' => true,
'context' => $context, 'overflowdiv' => true
];

$template->body = format_text($template->body, $template->docbodyformat, $options, null);
In reply to Lukas Celinak

Re: Announcing new plugin - Dompdf for Moodle

by Darko Miletić -
Nothing looks wrong but I do not have access to complete module you are using so I can not really tell.
I just added an example to the plugin that exports forum posts. Any forum post that you have you can export with this and if it does contain images they will be exported as well.
See https://github.com/kiklop74/moodle-local_dompdf/blob/master/examples/testimage.php

Make sure that context you use is the right one, make sure that filearea is the right one. See how I create it in my example
In reply to Darko Miletić

Re: Announcing new plugin - Dompdf for Moodle

by Lukas Celinak -
Picture of Plugin developers
Hi, i found the source of error, it is a debug messaging:
Warning: Use of undefined constant LIBXML_HTML_NOIMPLIED - assumed 'LIBXML_HTML_NOIMPLIED' (this will throw an Error in a future version of PHP) in /var/www/htmlcel/local/dompdf/classes/api/xmlutil.php on line 84

Warning: Use of undefined constant LIBXML_HTML_NODEFDTD - assumed 'LIBXML_HTML_NODEFDTD' (this will throw an Error in a future version of PHP) in /var/www/htmlcel/local/dompdf/classes/api/xmlutil.php on line 84

Warning: A non-numeric value encountered in /var/www/htmlcel/local/dompdf/classes/api/xmlutil.php on line 84
In reply to Lukas Celinak

Re: Announcing new plugin - Dompdf for Moodle

by Darko Miletić -
What PHP version are you using?



El lun., 17 jun. 2019 06:35, Lukas Celinak (via Moodle.org) <
In reply to Darko Miletić

Re: Announcing new plugin - Dompdf for Moodle

by Lukas Celinak -
Picture of Plugin developers
Im usign PHP 7.2
but ithing problem is in DOM or libxml. We are on centos 6.10 ande s libxml version is 2.7.6.
In reply to Lukas Celinak

Re: Announcing new plugin - Dompdf for Moodle

by Darko Miletić -
Just fetch the latest code from github. I removed those constants.
In reply to Darko Miletić

Re: Announcing new plugin - Dompdf for Moodle

by Lukas Celinak -
Picture of Plugin developers
I fetched it, but i think, i need uprage libxml anyway, because:

Generating document with images trough MOODLE FILE API:
Using:
file_rewrite_pluginfile_urls($template->docbody, 'pluginfile.php', $context->id, 'mod_timetable', 'body', $template->id);

it is working in bowser, document is full loaded with images

local_dompf is generating pdf with broken image: "Image not found or type unknown"

Using:
\local_dompdf\api\pdf::file_rewrite_image_urls($template->body, $template->id, 'body', $context->id, 'mod_timetable');

it is working in browser, generated link is in some kind of hash, document is full loaded with images

local_dompf is generating broken pdf
In reply to Lukas Celinak

Re: Announcing new plugin - Dompdf for Moodle

by Darko Miletić -

Can you try the testimage script in examples directory to see how it behaves in general. 

I am using the same code on some of my projects and so far had no issues whatsoever. Please open the issue on github and let's continue there.

In reply to Darko Miletić

Re: Announcing new plugin - Dompdf for Moodle

by Lukas Celinak -
Picture of Plugin developers
Hi,
thank you, and im sorry, i had started header before pdf generating, there was a problem. Everything works fine now.

Good job.
In reply to Lukas Celinak

Re: Announcing new plugin - Dompdf for Moodle

by Darko Miletić -
It seems that you use old version of libxml



https://php.net/manual/en/libxml.constants.php#constant.libxml-html-noimplied



El lun., 17 jun. 2019 06:35, Lukas Celinak (via Moodle.org) <
In reply to Lukas Celinak

Re: Announcing new plugin - Dompdf for Moodle

by Darko Miletić -
Anyways I removed those things and that should cover distributions that use older libxml2.