WebView Printing Capability for PDF Export

Description of the limitation and why it is relevant to address

As a developer using the VIKTOR platform, I need the ability to export or print a WebView as a PDF file directly within the platform. This functionality is crucial as it allows for seamless conversion of HTML/CSS-based content into a standardized document format, enhancing the reporting and documentation process.

Historically, our team leveraged the browser’s native print function to achieve this, a process that was straightforward in our pre-VIKTOR setup. Integrating a similar feature within VIKTOR’s WebView would significantly streamline our workflow, enabling us to efficiently produce and share professional-quality documents.

Submitter proposed design (optional)

We propose the introduction of a “Print to PDF” or “Export as PDF” feature within the WebView component of VIKTOR. This addition would allow users to convert the displayed WebView content into a PDF file directly from the VIKTOR interface, mimicking the functionality we had prior to transitioning to VIKTOR.

An example from the PDF View:
image

Current workarounds

  • Currently, there is no direct method to print WebView content within VIKTOR, which limits our ability to export high-fidelity PDF documents from the platform. (This was throughly tested on our end last year)
  • Our current workaround involves opening WebView content in a separate browser window to use the native print function. However, this method is not ideal as it detracts from the integrated user experience offered by VIKTOR.
  • We have explored in our previous discussions using Python-based HTML-to-PDF conversion libraries like xhtml2pdf. Nevertheless, these tools often struggle with complex HTML/CSS, leading to suboptimal results. (This also was throughly tested for our existing .html files)

I found it is possible to convert an html to a pdf using a headless browser such as selenium. I convert the .html into pdf bytes and then use that to create a File.from_data()