PDF by python script ignores Japanese text in Rhino 8

Hi. I have a Python script to export a Rhino layout to PDF.
In the script, I add some text to PDF page.
It works fine in Rhino7 both with alphabet and with Japanese font.
However, in Rhino8 Japanese text is ignored while English one comes out as is.

In Rhino7:


In Rhino8:

If I place a Japanese text object in the layout, it is exported properly.
That is to say, font is not the problem and issue seems to be in PDF creation in Python.

Here is my code.
You can test with Rhino 3dm which has A3 size layout named “Main Layout”

# -*- coding: utf-8 -*-

# RhinoPythonコードを使用してレイアウトのPDFファイルをエクスポートする
import Rhino
import rhinoscriptsyntax as rs
import System.Drawing
import scriptcontext as sc


# レイアウトをPDFとしてエクスポートする関数
def export_layout_as_pdf(layout_name, file_path, dpi=300):
    # レイアウトを取得
    layout = sc.doc.Views.Find(layout_name, False)
    if layout is None:
        print("指定されたレイアウトが見つかりません: " + layout_name)
        return

    # PDFファイルを作成
    pdf = Rhino.FileIO.FilePdf.Create()
    size = System.Drawing.Size(16.53 * dpi, 11.69 * dpi)  # A3サイズ

    # レイアウトの設定
    view_settings = Rhino.Display.ViewCaptureSettings(layout, size, dpi)
    view_settings.RasterMode = True
    view_settings.OutputColor = Rhino.Display.ViewCaptureSettings.ColorMode.DisplayColor
    # PDFにページを追加
    pdf.AddPage(view_settings)

    text_font = Rhino.DocObjects.Font("Meiryo")
    text_holizontal_alignment = Rhino.DocObjects.TextHorizontalAlignment(1)
    text_display_alignment = Rhino.DocObjects.TextVerticalAlignment(4)
    clr = rs.CreateColor(0,0,0)
    pdf.DrawText(
            1, "ENGLISH 日本語", 16.53*dpi/2, 11.69*dpi*(92/100), 36, text_font,
            clr, clr, 0, 0, text_holizontal_alignment,
            text_display_alignment
    )

    # PDFファイルを書き出し
    pdf.Write(file_path)
    print("PDFがエクスポートされました: " + file_path)


# 使用例
export_layout_as_pdf("Main Layout", "C:/Users/vicc_ishihara/Desktop/output.pdf")

Does it print the text correctly? Make sure the problem’s not with Rhino script reading in the layout (i.e. nothing to do with the pdf creation).

If you’re defining the text as a string literal, it could be as simple as using a u-string (u"ENGLISH 日本語")

I’m not familiar with Rhino.FileIO.FilePdf but I’d ensure the string or bytes data is being provided in the exact format, type and encoding Rhino.FileIO.FilePdf.Create().DrawText() expects.

It’s a bit weird as although Python 2 had idiosyncratic unicode support, (and easily confusable/indistinguishable bytes and ascii strings), the Iron Python 2 implementation uses System.String as a Python str, which under the hood is encoded in UTF-16, and can easily support any unicode code point.

Most unicode problems are solved, by figuring out what the library expects from the non-standard Python environment it’s in, and preferably by controlling the encoding yourself and just giving it bytes.

Hi James.
Thank you for your suggestion.

I tried with u"English 日本語" but the result was same: only the part with alphabet (English) was printed in PDF.

Also, as far as I search, Rhino.FileIO.FilePdf.Create().DrawText() expect string to be UTF-16.

I will try to deep-dive this idea:

Most unicode problems are solved, by figuring out what the library expects from the non-standard Python environment it’s in, and preferably by controlling the encoding yourself and just giving it bytes.

Additional system info:
Rhino 8 SR 7.
OS Windows 11 Pro.

Hi Takahiro -
I’ve added this thread to
RH-79834 Leader with Japanese text Not Printing with V8 RhinoPDF
-wim

1 Like

RH-79834 is fixed in Rhino 8 Service Release 11