Michał
Michał

Reputation: 13

HCL Domino - Xpage content parsed to PDF

I have an XPage designed to serve as a training sheet for users. I need to style it to resemble an A4 format paper sheet. The page contains up to 15 editable fields, but ultimately, the end user should be able to click a button (or trigger an action after saving the document) that sends the page as a PDF attachment in an email.

I'm wondering if it is possible to programmatically generate a PDF from an existing XPage. I know I can style the print view of the page and use window.print() for the user, but that doesn't meet my goal. The objective is to have the same content in the email as on the website.

As a workaround, I considered using an HTML-prepared page that reflects the view of the XPage form and sending it as the email body. However, I prefer to avoid splitting it into two separate instances. Since this page may be updated several times a year, maintaining changes on two pages would be inefficient and not optimal.

Upvotes: 1

Views: 80

Answers (2)

D.Bugger
D.Bugger

Reputation: 2359

I know I can style the print view of the page and use window.print() for the user, but that doesn't meet my goal.

We went pretty much that way, but not on the same client computer. Our goal was to put the contents of the screen on paper, in more or less the exact same format (some buttons were left out, no point in printing those).

How we did it? On the server. What we use:

  1. any browser
  2. an Ubuntu Linux server
  3. XPages on Domino V12.0.x
  4. Headless Chrome
  5. node.js

When the user clicks the Print-button, a message is sent to the server with all the details of the page to be printed (URL etc). An agent activates some node.js code, which starts Chrome with the right URL and then makes sure that that same page is retrieved by Chrome and printed.

We came to the conclusion that we would never be able to reproduce exactly the same page on paper using any other PDF library. We would end up with coding everything twice, and when custom forms are used, or custom views, that would make it impossible to properly generate output. It took us quite a lot of testing, because a headless Chrome is difficult to tame...

Good luck!

Upvotes: 0

stwissel
stwissel

Reputation: 20384

You could use an XAgent to output the result of a PDF generator in a Java bean. Potential libraries are Apache FOP or Apache PDFBox. They represent very different approaches, so there’s a good chance one fits your style.

You can follow my blog series about Domino and PDF to get more insights.

Hope that helps

Upvotes: 1

Related Questions