Good Day Everyone,

I have used HTMLRenderer.PdfSharp library to create an OutSystems extension to generate PDF files from HTML. SavePDF is the extension server action.

It takes HTML string, file name and folder path as parameters to generate the PDF file.

Currently I am passing the HTML string as below:

I would like to know whether there is a better way to archive this as it will be harder to modify and maintain. (Probably put those HTML in a separate html file)

I thought about creating a separate Web Screen and load it to get it's HTML but found two problems:

1. Firing an unnecessary web request.

2. Web Screen will hold all the unnecessary html elements and CSS classes that OutSystems auto generates.

(I want to pass very simple html layout into my PDF function. Complex html and css will cause problems)

Let me know if any of you have a solution to this.


Sanoj :D

Hi Sanoj,

I'm not sure I understand the goal of what you're trying to do. If you have fixed HTML (as it seems from your example above), why do you need to generate the PDF dynamically? You can just include the PDF?

Apart from that, as for including files in an eSpace, you can add them as a Resource. To do that, switch to the Data tab, and locate the Resources folder (it's the bottom one). Right click and select "Import Resource" or press Ctrl-N when it's selected to add the resource (in your case the HTML). After adding it, click the Resource to display its Properties. One of the properties says "Deploy Action". Set it to "Deploy to Target Directory" (default is "Do Nothing"), and specify the target directory. This is a path relative to the module's deploy directory.

To get the content of the Resource, use Resources.ResourceName.Content in an expression.

As for your remark that "Web Screen will hold all the unnecessary html elements and CSS classes that OutSystems auto generates", that's only partially true: you control the CSS that is added, by selecting the Theme for the Web Flow of a Web Screen, and optionally specifying the CSS for the Web Screen. But it's true that the HTML elements are added as the Platform sees fit (including session information), though you have of course partial control over it by the Widgets you use on the Screen (Containers will result in a div, etc.).

Hi Kilian,

Thanks for your reply.

I actually wanted to pass dynamic variables into the HTML string. Sorry for not including it in the screen shot.

So my HTML string will have dynamic values like below:

So I won't be able to store it manually. (but thanks for instructions on adding resources. Some thing new I've learnt :D)

Basically, I am trying to achieve following (This is how I used to do this in PHP MVC):

1. Create the PDF template View (This file only has HTML and parameters like {{UserName}}. Parameters will be populated by the template engine.)

2. Pass dynamic parameters from the Controller. (This PHP class function will send parameters to the View)

3. Get HTML string as the output instead of sending to the browser. (We have the option to get the rendered HTML as a string)

4. Pass the HTML string into the PDF function as a parameter.

Do you think that we achieve a similar workaround  with OutSystems platform?



Hi Chamika,

You can easily substitute template variables by using the built-in Replace function. You need a Text Variable for it, so in order to convert the Resource to Text you'll need the BinaryDataToText Action from the BinaryData Extension.