humhub / wiki

Create and edit pages with this powerful tool. Build a collaborative knowledge base, view and share information with your colleagues.
28 stars 35 forks source link

PDF Export #89

Closed buddh4 closed 3 years ago

buddh4 commented 5 years ago

Export wiki to pdf

Oremountainflorian commented 4 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..

JK742020 commented 3 years ago

I'm interested in the feature too! For single Wiki-Pages and the whole wiki as well. HTML would be great too.

yurabakhtin commented 3 years ago

@luke- I tried to use https://github.com/dompdf/dompdf to render HTML to PDF, but it looks like cannot load CSS and images:

html2pdf

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:

pdf_by_printer
luke- commented 3 years ago

@yurabakhtin You're right, let's close the feature. The print version looks pretty good!

marc-farre commented 3 years ago

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.

Oremountainflorian commented 3 years ago

@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?

grafik

grafik

Thanks in advance!

luke- commented 3 years ago

@Oremountainflorian I think 1,2,5,6 are automatically added by the browser.

marc-farre commented 2 years ago

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
    ]
);