[reportlab-users] Error using encoding="utf-8" to output RML to PDF

Robert Sullivan robert.sullivan at octoenergy.com
Fri Jun 9 11:06:39 EDT 2017


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.

Many thanks,

Robert

On 8 June 2017 at 12:20, Robin Becker <robin at reportlab.com> wrote:

> Hi Robert,
>
> can you email me (attached as a zip) the smallest possible example where
> this happens? Also what version of python/platform are you using?
>
> I have tested by just inserting the ÷ into a simple test rml
>
>
> <!DOCTYPE document SYSTEM "../rml.dtd">
> <document filename="tdivide.pdf" invariant="1">
>
> <stylesheet>
> <paraStyle
>         name="intro"
>         fontName="Helvetica"
>         fontSize="12"
>         leading="12"
>         />
> </stylesheet>
>
> <pageDrawing>
> <drawCentredString x="4.1in" y="5.8in">
> Hello World. First Page Drawing ÷
> </drawCentredString>
> </pageDrawing>
>
> </document>
>
>
> that works for me with python 2.7 3.3...
>
> I suspect you have been more formal and have put in some encodings at the
> top somehow. The encoding eclared appears to be utf8 and the text of the
> rml appears to be something other than utf8.
>
>
> On 08/06/2017 11:37, Robert Sullivan wrote:
>
>> Hello,
>>
>> I'd like to use some entities such as ÷, × and ≈ in my
>> RML template that outputs to a PDF but I get an error:
>>
>> rml2pdf.go(rml, outputFileName=buffer)
>>    File "rlextra-3.3.29/src/rlextra/rml2pdf/rml2pdf.py", line 6018, in go
>> pyRXPU.error: Declared encoding UTF-8 is incompatible with UTF-16 which
>> was
>> used to read it
>>
>> I've read in this previous message
>> https://pairlist2.pair.net/pipermail/reportlab-users/2017-
>> March/011607.html
>> that PDF may not allow UTF-8 so I'm a bit stuck as to what to do.
>>
>> Many thanks,
>>
>> Robert
>>
> ......
>
> --
> Robin Becker
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20170609/c7d0643c/attachment.html>


More information about the reportlab-users mailing list