Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide alternative option for PDF rendering #4732

Closed
4 of 6 tasks
ssddanbrown opened this issue Dec 18, 2023 · 5 comments
Closed
4 of 6 tasks

Provide alternative option for PDF rendering #4732

ssddanbrown opened this issue Dec 18, 2023 · 5 comments

Comments

@ssddanbrown
Copy link
Member

ssddanbrown commented Dec 18, 2023

At this point WKHTMLtoPDF is deprecated, with the source repos archived and it drifting out of OS repos (Alpine as an example).

Would be good to allow an alternative to fill the non-dompdf gap, and then deprecate and remove WKHTMLtoPDF specific support in the future.

Instead of supporting specific export options, we could maybe support a generic interface to allow adapting to different options where desired. Something like a configurable command path with a placeholder parameter to take a location of where BookStack writes out HTML to for conversion.

Research

  • Chromium - Can't see way to completely disable networking & JS.
  • Firefox - Can't find direct way for PDF capture. Does have a --no-remote option which may disable networking?

For browsers, there's a WebDriver standard in progress which may open up possibilities in this area via a standard API.

  • TCPDF - LGPL
    • New version being built here, existing stable version support-only. New version slow to develop (look like it's been 6 years in the making).
    • Need to test output against BookStack HTML.
    • Need to assess options (disable network).
  • WeasyPrint - BSD
    • Need to test output against BookStack HTML.
      • Looks pretty good.
    • Need to assess options (disable network).
  • Pandoc - GPL (More of an abstraction layer to other libs)
    • Need to test output against BookStack HTML.
    • Need to assess options (disable network).
    • Tested using pagejs-cli below, works fine, can pass options to underlying lib used, so output and security depends on underlying lib.
  • PagedJS-CLI
    • Does a fair job at output, but fails some common CSS properties used in example page. Really feels like it's intended for print use more that matching web output.
    • Has good controls to prevent fetching.

There's also commercial offerings, which may or may not be better (PDFreactor, PrinceXML).
Still makes sense to me to create a generic command line rather than supporting specific libraries in this case, as it's a moving area, and by allowing a user to call their own wrapper script it can be built upon like for customizing generation options, and allow flexibility in solution used without over complicating our support. There could be other options to think about too (for example, running chrome in a network-limited container).

Implementation

  • Add new EXPORT_PDF_COMMAND env option.
    • Supports placeholders:
      • {input_html_path} - Path to input HTML file to convert.
      • {output_pdf_path} - Path that the output PDF file should be written to.

Notes: Should update existing LDAP_USER_FILTER env option to support this format.

@chris-devel0per
Copy link

Yes I think that is would be a nice feature!

@roceil
Copy link

roceil commented Feb 22, 2024

Could you please clarify if you mean that in the current version, wkhtmltopdf is no longer available? I am in the process of preparing to install wkhtmltopdf in Docker for exporting PDFs in Chinese.

@ssddanbrown
Copy link
Member Author

Could you please clarify if you mean that in the current version, wkhtmltopdf is no longer available?

@roceil The ability to use WKHTMLtoPDF is still currently available in BookStack, but may likely be removed in the future.

@ssddanbrown ssddanbrown added this to the Next Feature Release milestone Apr 7, 2024
@ssddanbrown ssddanbrown self-assigned this Apr 7, 2024
@Froggy422811
Copy link

There is a nice GIST to replace WKHTMLtoPDF within a docker container. This is working very good for us:
https://gist.github.com/kmpm/c254558fcb0608346f49946a53cd8c09

If the new function made it possible to specify an "export template" at book, chapter or page level, that would be a great thing.

ssddanbrown added a commit that referenced this issue Apr 22, 2024
- Updated DOMPDF to direcly use library instead of depending on barry
wrapper.
- Merged existing export options file into single exports file.
- Defined option for new command option.

Related to #4732
@ssddanbrown
Copy link
Member Author

With the merge of #4969 there's now a generic command-based PDF option, which will be part of the next feature release. In the future we can put together specific engine/generator guidance (and help build generation implementations maybe).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants