Posted: 5 Jan 2017 10:27 EST Last activity: 12 Jan 2017 12:19 EST
Calling external js while creating PDF
We are using CKEditor ( as Rich Text editor) in Pega to allow users to write Math Functions. These Math functions (equations) are rendering proeprly on UI but when we are trying to create PDF or show the Editor in Read Only format, it is showing the source code of the equation.
Is there any way to load CkEditorMath.js file in the background so that PDF can print the Rendered equation not the source code?
Also see this: This gives some outlines of how to convert a client-side HTML5 Canvas (which I believe you are probably using here) to an image - by getting the clientside JS to POST the resultant data to the backend, which then converts to an image format.
This would probably require a fair bit of customization though.
Posted: 4 years ago
Updated: 4 years ago
Posted: 10 Jan 2017 10:26 EST Updated: 10 Jan 2017 10:25 EST
Or: if you can build another PRPC Activity which takes a single Parameter (the B64 data); and returns a ByteArray of the image; you could (perhaps) use that in conjunction with the Canvas code.
Basically: you would run your HTML on the browser; it would render the Canvas; it would then have to send the base64 encoded data back-to-the server; the server would need to store (or 'cache' I guess) the image data in a way that HTMLTOPDF could then retrieve it)....Again; it should work, but this has quite a number of 'moving parts' (especially if you have *multiple* Canvas objects in your HTML; and additionally it *has* to use a Browser at some point to generate the B64 data in the first place; so this would NOT work for any background/batch jobs; unless you use Pega Robotics of course....[which could allow you to fire up a browser automatically]).
[EDIT: even though the mechanism above [replacing all the canvas objects with img objects] would not directly help HTMLTOPDF - you could still then send the entire (re-rendered version) DOM back to a back-end service which WOULD be able to render it ; as the IMG tags would be 'self-contained' with all the B64 Data of all the images - probably quite a 'heavy' HTML file though) ].
I have managed to create a very simple Proof of Concept here: I can now send UP an HTML page FROM the browser; which allows HTMLTOPDF to convert images originally generated as clientside 'canvas' objects.
1. This isn't particularly 'PRPC-ish'; I'm sure somebody else can chip in here and re-write the bits using more standard PRPC bits (I've got a hard-coded 'form' object for instance).
3. The way I'm doing this is a bit odd: I'm 'stashing' the (newly altered) DOM in a textarea/html form, and then sending up the entire HTML DOM back to PRPC for conversion - but this also includes the textarea/form itself ! (this is just a 'feature'/'bug' currently; I'm sure this can be figured out by somebody else).
Here's the working solution; firstly I create a simple wrapper Activity that combines calls to '@baseclass.HTMLTOPDF' and 'Code-Pega-PDF.View'; so that it both converts to PDF and then streams the result back in one go:
It's just called 'ConvertToPDF'; I'm using 'Pass current parameter page' for both calls here - and also I'm 'mirroring' a subset of Parameters from both HTMLTOPDF (Markup, and PDFDocument) and View (PDFName and [already used by HTMLTOPDF] PDFDocument):
IMPORTANT: I also needed to tick the 'Allow direct invocation from the client or a service' on the Security Tab to get this to work. (Which should be taken into account for security reasons for any Production Apps; note this option still requires login credentials to run through).
This means I can call the Activity now using a URL like this:
In the case above - the 'HTML' is actually just the text 'hello' - and this sucessfully returns a converted PDF containing that text.
Here's the HTML Rule Contents in full: (actually most of the code is used to draw pretty pictures for testing with).
The ugly form stuff is basically the parameters for calling our Activity; you can see part of the text area has now contains the HTML we will send up to PRPC (once the 'ConvertToPDF' button is pressed).
Pressing the button results in a PDF, that looks like this:
I'll attach the text of the RULE HTM as a text file also; as well as an example PDF that was created.
I don't know whether this flag works with the version of the CKEditor shipped with PRPC - and I don't know (without further research) about you would go about altering the shipped version of the CKEditor with PRPC.
Somebody else may be able to fill in the blanks here though !