PDF file produced by scripts/pdf-report.gmp can not be opened successly

So, there was probably a parsing issue going on.

Firstly I temporarily saved the XML response and removed all nodes from <report> but the text node. Parsing of this modified XML worked fine with the pdf-report.gmp code.

But instead of removing nodes I applied the solution suggested from @gormami posted in:

To achieve this, the codeline of pdf-report.gmp

had to be rewritten as follows:

import re
from lxml import etree

# get the content of the report element
report = report_response[0]
report = etree.tostring(report).decode('ascii')
report = re.sub('</report_format>', '</report_format><value>', report)
report = re.sub('</report>', '</value></report>', report)
report = etree.fromstring(report)
content = report.xpath('value')[0].text

In my case, this results in a correct PDF report. Of course, this is just a workaround. But obviously there are some parser which cannot handle the XML structure of <report>. So maybe an adjustment should be considered.

4 Likes