-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PDF-Exporter webhook for setting table td height
- Loading branch information
Showing
5 changed files
with
67 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,7 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
replay_pid* | ||
.idea/* | ||
|
||
# code style config | ||
!.idea/codeStyles | ||
.idea/codeStyles/* | ||
!.idea/codeStyles/Project.xml | ||
!.idea/codeStyles/codeStyleConfig.xml | ||
|
||
.vscode/* | ||
|
||
target/ | ||
*.iml | ||
dependency-reduced-pom.xml | ||
|
||
src/main/resources/webapp/*-admin/html/about.html | ||
README.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
# PDF-exporter webhook samples | ||
# PDF-Exporter Webhook Samples | ||
|
||
This project includes samples of webhooks that can incorporate additional logic for processing HTML prior to PDF generation. | ||
Webhook can be implemented as a REST endpoint by any programming language (Java, JS, Python etc.) and be hosted anywhere (within Polarion as an extension, or absolutely external). | ||
This project contains examples of webhooks that can include additional logic to process HTML prior to PDF generation. | ||
Webhooks can be implemented as a REST endpoint by any programming language (Java, JS, Python, etc.) and hosted anywhere (inside Polarion as an extension or completely external). | ||
|
||
## TableCellAutoHeightSetter | ||
|
||
The TableCellAutHeightSetter webhook processes HTML content by replacing table cell height values specified in pixels (e.g., height: 100px) with height: auto. The processed HTML is then returned as a response to the client. | ||
The TableCellAutHeightSetter webhook processes HTML content by replacing table cell height values specified in pixels (e.g. height: 100px) with height: auto. The processed HTML is then returned as a response to the client. | ||
|
||
## Usage | ||
This webhook endpoint can be started using the following command: | ||
This webhook endpoint can be launched with the following command: | ||
|
||
```bash | ||
python app/TableCellAutoHeightSetter.py --port=9333 | ||
python table-cell-auto-height-setter/table_cell_auto_height_setter.py --port=9333 | ||
``` | ||
|
||
## Configuration Webhook URL in PDF-exporter: | ||
|
||
1. Navigate to: Administration ➙ PDF Export ➙ Webhooks | ||
|
||
2. Add the webhook URL, such as http://host.docker.internal:9333/process. | ||
|
||
|
||
|
||
|
||
## Configuration of the webhook URL in the PDF Exporter: | ||
|
||
1. Navigate to: `Administration` ➙ `PDF Export` ➙ `Webhooks` | ||
2. Add the webhook URL, for example http://localhost:9333/td-height/auto. |
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
table-cell-auto-height-setter/table_cell_auto_height_setter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import argparse | ||
import logging | ||
import re | ||
from flask import Flask, Response, request, json | ||
from gevent.pywsgi import WSGIServer | ||
|
||
app = Flask(__name__) | ||
|
||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s [%(levelname)s] - %(message)s') | ||
|
||
|
||
@app.route("/td-height/<height>", methods=["POST"]) | ||
def process_html(height): | ||
export_params, html = validate_request() | ||
|
||
logging.info(f"Changing HTML table cell height to '{height}'") | ||
|
||
if export_params.get('fitToPage'): | ||
html = change_height(html, height) | ||
logging.info("Changing HTML table cell height finished.") | ||
else: | ||
logging.info("'fitToPage' is not set. Changing HTML table cell height skipped.") | ||
|
||
return Response(html, mimetype="text/html", status=200) | ||
|
||
|
||
def change_height(html, height): | ||
pattern = r'(<t[dh].+?height:.*?)(\d+(\.\d+)?px)' | ||
return re.sub(pattern, lambda m: m.group(1) + height, html) | ||
|
||
|
||
def validate_request(): | ||
export_params_json = request.form.get('exportParams') | ||
if export_params_json is None: | ||
return "Missing exportParams", 400 | ||
else: | ||
export_params_json = json.loads(export_params_json) | ||
|
||
html = request.form.get('html') | ||
if html is None: | ||
return "Missing html", 400 | ||
return export_params_json, html | ||
|
||
|
||
def start_server(port): | ||
http_server = WSGIServer(("", port), app) | ||
http_server.serve_forever() | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description="Webhook: table cell auto height setter") | ||
parser.add_argument("--port", default=9333, type=int, required=False, help="Service port") | ||
args = parser.parse_args() | ||
|
||
logging.info(f"Service listening on port: {args.port}") | ||
|
||
start_server(args.port) |