This Polarion extension provides possibility to convert Polarion Documents to PDF files. This is an alternative to native Polarion's solution. The extension uses WeasyPrint as a PDF engine and requires it to run in Docker as Service.
This extension can be produced using maven:
mvn clean package
To install the extension to Polarion ch.sbb.polarion.extension.pdf-exporter-<version>.jar
should be copied to <polarion_home>/polarion/extensions/ch.sbb.polarion.extension.pdf-exporter/eclipse/plugins
It can be done manually or automated using maven build:
mvn clean install -P install-to-local-polarion
For automated installation with maven env variable POLARION_HOME
should be defined and point to folder where Polarion is installed.
Changes only take effect after restart of Polarion.
This extension supports the use of WeasyPrint as a REST service within a Docker container, as implemented here.
To change WeasyPrint Service URL, adjust the following property in the polarion.properties
file:
ch.sbb.polarion.extension.pdf-exporter.weasyprint.service=http://localhost:9080
sections
-element:
β¦
<sections>
<section id="fields"/>
β¦
</sections>
β¦
β¦
<extension id="pdf-exporter" label="PDF Exporter" />
β¦
Alternatively you can configure PDF Exporter such a way that additional toolbar will appear in document's editor with a button to open a popup with PDF Exporter view.
scriptInjection.dleEditorHead=<script src="https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.pdf-exporter/raw/main/polarion/pdf-exporter/js/starter.js"></script><script>PdfExporterStarter.injectToolbar();</script>
There's an alternate approach adding PDF Exporter button into native Polarion's toolbar, which has a drawback at the moment - button disappears in some cases (for example when document is saved), so using this approach is not advisable:
scriptInjection.dleEditorHead=<script src="https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.pdf-exporter/raw/main/polarion/pdf-exporter/js/starter.js"></script><script>PdfExporterStarter.injectToolbar({alternate: true});</script>
Live Reports also can be converted to PDF with help of this extension.
First of all you need to inject appropriate JavaScript code into Polarion:
scriptInjection.mainHead=<script src="https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.pdf-exporter/raw/main/polarion/pdf-exporter/js/starter.js"></script>
Then open a project, its Live Report you wish to export, and click "Expand Tools" on top of the page. As a result report's toolbar will appear. Click "Edit" button in a toolbar, as a result the report will be switched into an edit mode. Add an empty region on top of the report, place cursor there, choose "Generic" tag on "Widgets" sidebar on right hand side of the page, find "Export to PDF Button" widget there and click it to add to the report. Then save a report clicking πΎ in a toolbar and then return to a view mode clicking "Back" button. When you click "Export to PDF" button just added to the report, PDF Exporter view will be opened in a popup and you will be able to proceed with exporting the report to PDF. Be aware that in report's context limited set of properties are available for configuration in PDF popup, the rest of them are relevant only in Live Document context.
For better problem analyses extended logging can be configured in Polarion. By default, Polarion log level is set to INFO. It can be changed to debug in log4j2.xml
file.
Find /opt/polarion/polarion/plugins/com.polarion.core.util_<version>/log4j2.xml
file and add the following line into Loggers
section:
<Logger name="ch.sbb.polarion.extension" level="debug"/>
It is also possible to write all messages of SBB extensions info separate log file which can be useful to report a problem. In this case new Appender
should be added:
<RollingFile name="SBB" fileName="${sys:logDir}/log4j-sbb${fileNameSuffix}" filePattern="${sys:logDir}/log4j-sbb${filePatternSuffix}">
<PatternLayout pattern="${layoutPattern}"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1"/>
</Policies>
</RollingFile>
and the following Logger
:
<Logger name="ch.sbb.polarion.extension" level="debug">
<AppenderRef ref="SBB"/>
</Logger>
Cross-Origin Resource Sharing could be enabled using standard configuration of Polarion REST API. In polarion.properties
the following lines should be added:
com.siemens.polarion.rest.enabled=true
com.siemens.polarion.rest.cors.allowedOrigins=http://localhost:8888,https://anotherdomain.com
This extension makes intensive HTML processing to extend similar standard Polarion functionality. There is a possibility to log
original and resulting HTML to see potential problems in this processing. This logging can be switched on (true
value)
and off (false
value) with help of following property in file polarion.properties
:
ch.sbb.polarion.extension.pdf-exporter.debug=true
If HTML logging is switched on, then in standard polarion log file there will be following lines:
2023-09-20 08:42:13,911 [ForkJoinPool.commonPool-worker-2] INFO ch.sbb.polarion.extension.pdf.exporter.util.HtmlLogger - Original HTML fragment provided by Polarion was stored in file /tmp/pdf-exporter10000032892830031969/original-4734772539141140796.html
2023-09-20 08:42:13,914 [ForkJoinPool.commonPool-worker-2] INFO ch.sbb.polarion.extension.pdf.exporter.util.HtmlLogger - Final HTML page obtained as a result of PDF exporter processing was stored in file /tmp/pdf-exporter10000032892830031969/processed-5773281490308773124.html
Here you can find out in which files HTML was stored.
The converting HTML can contain some external CSS links referencing Polarion Server, like:
<link rel="stylesheet" href="https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.pdf-exporter/blob/main/polarion/diff-tool-app/ui/app/_next/static/css/3c374f9daffd361a.css" data-precedence="next">
In case the Polarion Server is not reachable from the WeasyPrint Service, such links cannot be successfully resolved during the WeasyPrint PDF transformation. The solution is to replace external CSS elements with internal CSS