Closed buddh4 closed 3 years ago
I would really appreciate the implementation of this feature!!! So far, we always copy content to LibreOffice and export it to pdf, but unfortunately the format and style breaks and it doesn't look as pretty as in the wiki..
I'm interested in the feature too! For single Wiki-Pages and the whole wiki as well. HTML would be great too.
@luke- I tried to use https://github.com/dompdf/dompdf to render HTML to PDF, but it looks like cannot load CSS and images:
Also there is no wiki page content at all, because the markdown/richtext content is rendered on client side by JS, however I enabled JS on dompdf
, my code is:
$dompdf = new Dompdf(new Options([
'defaultMediaType' => 'print',
'isJavascriptEnabled' => true,
'isPhpEnabled' => true,
'isRemoteEnabled' => true,
'isHtml5ParserEnabled' => true,
]));
$dompdf->loadHtml($render);
$dompdf->render();
$dompdf->stream();
I can try to render by some JS library like https://github.com/MrRio/jsPDF, but now I am thinking... do we really need such feature from humhub side? when almost all modern browsers can save a printing page into PDF file:
@yurabakhtin You're right, let's close the feature. The print version looks pretty good!
Just for information, I use MPDF library to generate PDF. It work really well. If you want I can share my code. MPDF supports CSS and images.
@yurabakhtin I'm really impressed, looks great, thanks for coding!
An idea as further improvement: Would it be possible to create kind of a menu to select what additional information to print and what not. I think of:
(1) Date (upper left in heading line) (2) Space, in which wiki is located (upper middle in heading line) (3) Name of wiki page (on the right in heading line) (4) Category (on the right in heading line) (5) Link (bottom line), doesn't look as long it's not improved as proposed recently by @luke- ? → https://github.com/humhub/wiki/issues/136#issuecomment-862353197 (6) Page/ Number of Pages (on the right in bottom line)
(1), (2) and (6) could be set by default, (3), (4) and (5) are rather special?
Thanks in advance!
@Oremountainflorian I think 1,2,5,6 are automatically added by the browser.
For information, I share my code here to create PDF with images and with CSS (using Dompdf which is much lighter MPDF, thanks @yurabakhtin for letting me know this library), if it can help someone:
Edit on December 7, 2022: images are included in the PDF only if the related content is visible for guest...
$dompdf = new Dompdf(new Options([
'defaultMediaType' => 'print',
'isRemoteEnabled' => true,
'isHtml5ParserEnabled' => true,
]));
$dompdf->loadHtml(
Html::style('img {max-width: 100%;}') .
RichText::convert($model->markdownText, RichText::FORMAT_HTML) // or RichTextToEmailHtmlConverter::process($model->markdownText)
);
$dompdf->setPaper('A4');
$dompdf->render();
return Yii::$app->response->sendContentAsFile(
$dompdf->output(),
BaseInflector::slug('File name') . '.pdf',
[
'mimeType' => 'application/pdf',
'inline' => false
]
);
Export wiki to pdf