Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 4159

PDF by python script ignores Japanese text in Rhino 8

$
0
0

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")

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4159

Trending Articles