[reportlab-users] Error using encoding="utf-8" to output RML to PDF
Robin Becker
robin at reportlab.com
Fri Jun 9 12:12:12 EDT 2017
In fact I'm being stupid, if the django is producing mixed stuff somehow then
the templating software should blow up as bytes (utf8) are added to unicode or
vice versa.
If on the other hand you declare utf16 in the rml header, but django is
producing utf8 then you'll likely get this error.
I tried just changing the encoding to utf-16 in the header of one of my test
files (ie it is a bytes file) and I get exactly this error
C:\tmp>rml2pdf bad.rml
Traceback (most recent call last):
File "c:\code\rlextra\rml2pdf\rml2pdf.py", line 6511, in <module>
main()
File "c:\code\rlextra\rml2pdf\rml2pdf.py", line 6503, in main
dynamicRml=1
File "c:\code\rlextra\rml2pdf\rml2pdf.py", line 6147, in go
parsed = parsexml(xmlInputText,eoCB=_eoDTD)
pyRXPU.error: Declared encoding UTF-16 is incompatible with UTF-8 which was used
to read it
Internal error, ParserPush failed!
clearly a bytes file cannot be utf16.
This seems to indicate you are actually producing utf8 under some circumstances.
On 09/06/2017 16:06, Robert Sullivan wrote:
> Hi Robin,
>
> In preparing the smallest possible example I discovered I don't get the
> error when using Helvetica just with Gotham. So the entities are working
> fine.
>
> Here is the docinit snippet and we are using utf-16 encoding.
>
> <docinit>
> {% if font == "Gotham" %}
> <registerTTFont faceName="{{ font }}" fileName="{{ asset_root
> }}/{{ font }}-Book.ttf" />
> <registerTTFont faceName="{{ font }}-Bold" fileName="{{
> asset_root }}/{{ font }}-Bold.ttf" />
> <registerTTFont faceName="{{ font }}-Italic" fileName="{{
> asset_root }}/{{ font }}-BookItalic.ttf" />
> <registerTTFont faceName="{{ font }}-Black" fileName="{{
> asset_root }}/{{ font }}-Black.ttf" />
> <registerFontFamily
> normal="Gotham"
> bold="Gotham-Bold"
> italic="Gotham-Italic"
> boldItalic="Gotham-Black" />
> {% endif %}
> </docinit>
>
> Also using Python3.6 and Django 1.10.5, fyi, so the font is declared in the
> context variable that gets passed to this template.
>
> I'll look more into the Gotham font but any pointers would be appreciated.
>
......
>
--
Robin Becker
More information about the reportlab-users
mailing list