diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml index 2d464b5..443ba4f 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -10,14 +10,14 @@ jobs: contents: read packages: write steps: - - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - name: Set up JDK and Maven - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4 + uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4 with: distribution: adopt java-version: 17 cache: maven - - uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22 + - uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22 with: repositories: > [ @@ -57,7 +57,7 @@ jobs: - name: Print settings.xml run: cat /home/runner/.m2/settings.xml - name: Build with Maven - run: mvn --batch-mode -DwpExporterImpl=docker clean package -P polarion2404,tests-with-weasyprint-docker + run: mvn --batch-mode -DwpExporterImpl=docker clean package -P tests-with-weasyprint-docker - name: Extract artefact version id: artefact_version run: echo "version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT diff --git a/.gitignore b/.gitignore index 0205c77..8f55b56 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,6 @@ replay_pid* target/ *.iml dependency-reduced-pom.xml + +src/main/resources/webapp/*-admin/html/about.html +README.html \ No newline at end of file diff --git a/.scripts/convert-readme.sh b/.scripts/convert-readme.sh new file mode 100755 index 0000000..a3e1e20 --- /dev/null +++ b/.scripts/convert-readme.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +INPUT_FILE="${1:-README.md}" +OUTPUT_FILE="${2:-README.html}" + +# Convert the markdown file to a JSON payload +jq -R -s '{"mode": "gfm", "text": .}' < "$INPUT_FILE" > payload.json + +# Send the JSON payload to the GitHub API +curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/markdown \ + -d @payload.json > "$OUTPUT_FILE" + +# Remove the temporary JSON payload +rm payload.json + +# Remove the Build and Installation sections from readme +awk ' +/

Build<\/h2>/ {skip=1; next} +/

Polarion configuration<\/h2>/ {skip=0} +!skip' "$OUTPUT_FILE" > "$OUTPUT_FILE.tmp" && mv "$OUTPUT_FILE.tmp" "$OUTPUT_FILE" diff --git a/pom.xml b/pom.xml index c9a9b90..d0aa736 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ ch.sbb.polarion.extensions ch.sbb.polarion.extension.generic.parent-pom - 4.10.0 + 4.11.0 ch.sbb.polarion.extension.pdf-exporter diff --git a/src/main/resources/webapp/pdf-exporter-admin/html/.gitkeep b/src/main/resources/webapp/pdf-exporter-admin/html/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/webapp/pdf-exporter-admin/html/help/configuration.css b/src/main/resources/webapp/pdf-exporter-admin/html/help/configuration.css deleted file mode 100644 index 7ffb408..0000000 --- a/src/main/resources/webapp/pdf-exporter-admin/html/help/configuration.css +++ /dev/null @@ -1,33 +0,0 @@ -.cm-builtin { - color: #09326C; -} -.cm-attribute { - color: #216E4E; -} -.cm-string { - color: #974F0C; -} -.cm-property { - color: #216E4E; -} -.cm-keyword { - color: #AE2A19; -} -.cm-operator { - color: #172B4D; -} -.cm-tag { - color: #0C66E4; -} -.cm-bracket { - color: #172B4D; -} -.cm-def { - color: #216E4E; -} -.cm-variable { - color: #44546F; -} -.cm-variable-2 { - color: #44546F; -} diff --git a/src/main/resources/webapp/pdf-exporter-admin/html/help/configuration.html b/src/main/resources/webapp/pdf-exporter-admin/html/help/configuration.html deleted file mode 100644 index c59a9c5..0000000 --- a/src/main/resources/webapp/pdf-exporter-admin/html/help/configuration.html +++ /dev/null @@ -1,254 +0,0 @@ -

Polarion ALM extension to convert Documents to PDF files

- -

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 either to be installed as a system's command-line tool or to run from Docker container (as CLI or as Service, see below).

- -

Polarion configuration

- -

WeasyPrint Configuration

- -

WeasyPrint CLI

- -

To run WeasyPrint as a system's command-line tool specify following properties in file <POLARION_HOME>/etc/polarion.properties:

-
-    
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.connector=cli
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.executable=weasyprint
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.pdf.variant=pdf/a-2b
-    
-
- -

And then install WeasyPrint. On Linux system it can be done following way:

-
-    
-pip install weasyprint
-    
-
-

For more information on WeasyPrint Installation see these instructions

- -

WeasyPrint CLI in Docker

- -

This extension supports using WeasyPrint running in Docker container. This feature can be switched on with help of following properties in file <POLARION_HOME>/etc/polarion.properties:

-
-    
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.connector=cli
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.executable=docker run --interactive --rm docker.io/library/weasyprint:61.2
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.pdf.variant=pdf/a-2b
-    
-
- -

WeasyPrint as Service in Docker

- -

This extension supports using WeasyPrint running as a REST Service in Docker container. This feature can be switched on with help of following properties in file <POLARION_HOME>/etc/polarion.properties:

-
-    
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.connector=service
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.service=http://localhost:9080
-ch.sbb.polarion.extension.pdf-exporter.weasyprint.pdf.variant=pdf/a-2b
-    
-
- -

Enabling Internalization of CSS Links

- -

The converting HTML can contain some external CSS links referencing Polarion Server, like:

-
-    
-<link rel="stylesheet" href="/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 <link> elements with internal CSS <style> tags containing the CSS content embedded into the HTML document. - By default, CSS link internalization is disabled. To enable internalization of CSS links, it is necessary to activate the following property in file <POLARION_HOME>/etc/polarion.properties:

-
-    
-ch.sbb.polarion.extension.pdf-exporter.internalizeExternalCss=true
-    
-
- - -

PDF exporter extension to appear on a Document's properties pane

- -
    -
  1. Open a project where you wish PDF Exporter to be available
  2. -
  3. On the top of the project's navigation pane click ⚙ (Actions) ➙ 🔧 Administration. Project's administration page will be opened.
  4. -
  5. On the administration's navigation pane select Documents & Pages ➙ Document Properties Sidebar.
  6. -
  7. In opened Edit Project Configuration editor find sections-element: -
    -            
    -…
    -<sections>
    -  <section id="fields"/>
    -  …
    -</sections>
    -…
    -            
    -        
    -
  8. -
  9. And insert following new line inside this element: -
    -            
    -…
    -<extension id="pdf-exporter" label="PDF Exporter" />
    -…
    -            
    -        
    -
  10. -
  11. Save changes by clicking 💾 Save
  12. -
- -

PDF exporter view to open via button in toolbar

- -

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.

-
    -
  1. Open "Default Repository".
  2. -
  3. On the top of its navigation pane click ⚙ (Actions) ➙ 🔧 Administration. Global administration page will be opened.
  4. -
  5. On the administration's navigation pane select Configuration Properties.
  6. -
  7. In editor of opened page add following line: -
    -            
    -scriptInjection.dleEditorHead=<script src="/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="/polarion/pdf-exporter/js/starter.js"></script><script>PdfExporterStarter.injectToolbar({alternate: true});</script>
    -            
    -        
    -
  8. -
  9. Save changes by clicking 💾 Save
  10. -
- -

PDF exporter view to open in Live Reports

- -

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:

-
    -
  1. Open "Default Repository".
  2. -
  3. On the top of its navigation pane click ⚙ (Actions) ➙ 🔧 Administration. Global administration page will be opened.
  4. -
  5. On the administration's navigation pane select Configuration Properties.
  6. -
  7. In editor of opened page add following line: -
    -            
    -scriptInjection.mainHead=<script src="/polarion/pdf-exporter/js/starter.js"></script>
    -            
    -        
    -
  8. -
  9. Save changes by clicking 💾 Save
  10. -
-

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.

- -

Configuring Logs

- -

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 Loggerssection:

-
-    
-<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>
-    
-
- -

Enabling CORS

- -

Cross-Origin Resource Sharing could be enabled using standard configuration of Polarion REST API. In <POLARION_HOME>/etc/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
-    
-
- -

Debug option

- -

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_HOME>/etc/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.

- -

Extension Configuration

- -
    -
  1. On the top of the project's navigation pane click ⚙ (Actions) ➙ 🔧 Administration. Project's administration page will be opened.
  2. -
  3. On the administration's navigation pane select PDF Export. There are 5 sub-menus with different configuration options for PDF Exporter.
  4. -
  5. For 3 of these options (Cover page, Header and Footer and Localization) Quick Help section available with option short description. For the rest 2 - (Style package, Stylesheets) there's no Quick Help section, but their content is self-evident. -
  6. -
  7. To change configuration of PDF exporter extension just edit corresponding section and press Save button.
  8. -
- -

Usage

- -
    -
  1. Open a document in Polarion.
  2. -
  3. In the toolbar choose Show Sidebar ➙ Document Properties.
  4. -
  5. Choose desired options in the PDF Exporter block and click Export to PDF. - For the options details please refer plugin documentation. -
  6. -
- -

Known issues

- -

SVG rendering issue

- -

Details

- -

Weasyprint doesn't fully support all SVG features. One of the most frequently used feature by Polarion which isn't supported by Weasyprint is 'foreignObject' - element. This leads to some visual bugs in resulting pdf (missing font colors, rich text formatting etc.)

- -

Solution

- -

Usage of WeasyPrint as Service in Docker (see above) is suggested. It has built-in SVG to PNG images conversion using Chromium browser (which supports more SVG features, including foreignObjects).

- -

Upgrade

- -

Upgrade from version 4.x.x to 5.0.0

- -

- In version 5.0.0 not only label of configuration parameter "Fit images and tables to page width" was modified to be "Fit images and tables to page", - but also underlying parameter was renamed to reflect this change. As a result if you had "Fit images and tables to page width" ticked in your configuration prior to version 5.0.0, - after installation of this version you will have to go to configuration again and re-tick property "Fit images and tables to page", both on global repository level and on level of projects. -

-

- Another change is default CSS which was modified to reflect different possible paper sizes as well as additional styling for images to jump into next page if they can't be fully displayed on current one. - Thus please either reset your saved CSS into last version if you didn't have your own CSS definitions or merge your saved version with new default version. -

\ No newline at end of file diff --git a/src/main/resources/webapp/pdf-exporter-admin/pages/about.jsp b/src/main/resources/webapp/pdf-exporter-admin/pages/about.jsp index 7371b4b..20834f8 100644 --- a/src/main/resources/webapp/pdf-exporter-admin/pages/about.jsp +++ b/src/main/resources/webapp/pdf-exporter-admin/pages/about.jsp @@ -28,7 +28,7 @@ - + @@ -126,13 +126,15 @@ "/> +
<% - try (InputStream inputStream = ExtensionInfo.class.getResourceAsStream("/webapp/pdf-exporter-admin/html/help/configuration.html")) { + try (InputStream inputStream = ExtensionInfo.class.getResourceAsStream("/webapp/pdf-exporter-admin/html/about.html")) { assert inputStream != null; String configurationHelp = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); out.println(configurationHelp); } %> +