This Tinyscript-based tool allows to decompres a STIX XML file and to output it as a PDF using pdfkit.
This can be installed using:
$ pip install bs4 pdfkit tinyscript
$ tsm install stix-reports-to-pdf
This Tinyscript-based tool allows to decompres a STIX XML file and to output it as a PDF using pdfkit.
This can be installed using:
$ pip install bs4 pdfkit tinyscript
$ tsm install stix-reports-to-pdf
| #!/usr/bin/python3 | |
| # -*- coding: UTF-8 -*- | |
| import pdfkit | |
| import zipfile | |
| from bs4 import BeautifulSoup | |
| from tinyscript import * | |
| try: | |
| from HTMLParser import HTMLParser | |
| except ImportError: | |
| from html.parser import HTMLParser | |
| __author__ = "Alexandre D'Hondt" | |
| __version__ = "1.2" | |
| __copyright__ = "A. D'Hondt" | |
| __license__ = "agpl-3.0" | |
| __examples__ = ["stix_report_entities.xml", "stix_report_entities.xml.zip"] | |
| __doc__ = "This tool allows to decompres a STIX XML file and to output it as a PDF using pdfkit." | |
| html = HTMLParser() | |
| XML = "stix_report_entities.xml" | |
| def generate_report(stix): | |
| with open(stix) as f: | |
| soup = BeautifulSoup(f.read(), 'xml') | |
| for report in soup.find("stix:Reports").find_all("stix:Report"): | |
| fn = "{}.pdf".format(ts.slugify(report.find("report:Title").text)) | |
| content = html.unescape(report.find("report:Description").text) | |
| pdfkit.from_string(content, fn, { | |
| 'page-size': "A4", | |
| 'margin-top': "0.5in", | |
| 'margin-right': "0.5in", | |
| 'margin-bottom': "0.75in", | |
| 'margin-left': "0.5in", | |
| 'footer-center': "[page]/[toPage]", | |
| }) | |
| if __name__ == '__main__': | |
| parser.add_argument("stix", default=XML, type=ts.file_exists, | |
| help="STIX file (XML or ZIP format)") | |
| initialize() | |
| try: | |
| with zipfile.ZipFile(args.stix, 'r') as z: | |
| z.extract(XML) | |
| args.stix = XML | |
| except: | |
| pass | |
| generate_report(args.stix) |