- OpenOfficeのドキュメント内のテキストを表示 - らんだむな記憶
- OpenOfficeのpythonマクロ(1) - らんだむな記憶
- OpenOfficeのpythonマクロ(2) - らんだむな記憶
で頑張った結果、*1
# -*- coding: utf-8 -*- FONT_NAME = u"小塚明朝 Pr6N R" # https://wiki.openoffice.org/wiki/JA/Documentation/BASIC_Guide/Structure_of_Text_Documents def change_text_font(text, font_name): enumeration = text.createEnumeration() while enumeration.hasMoreElements(): text_element = enumeration.nextElement() if not text_element.supportsService("com.sun.star.text.Paragraph"): continue enumeration2 = text_element.createEnumeration() while enumeration2.hasMoreElements(): text_portion = enumeration2.nextElement() # 英数部分の置換 text_portion.CharFontName = font_name # 和文部分の置換 text_portion.CharFontNameAsian = font_name def change_document_font(dummy=None): doc = XSCRIPTCONTEXT.getDocument() text = doc.getText() change_text_font(text, FONT_NAME) enumeration = doc.getTextFrames().createEnumeration() while enumeration.hasMoreElements(): text = enumeration.nextElement() change_text_font(text, FONT_NAME) # マクロの公開 g_exportedScripts = ( change_document_font, )
のようなスクリプトを書いて、change_font.py
みたいな名称で保存しておいて %appdata%\OpenOffice\4\user\Scripts\python
の下に python スクリプトを置くと、OpenOffice アプリの[ツール]→[マクロ]→[マクロの管理]→[Python]の下にマクロとして現れるのでコレを叩いて個別の .odt ごとにフォントを置換すると楽だよねってことになったらしい。(去年は何も記録を残していない・・・)
この時、Java の 32bit のランタイムが必要っぽくて(OO が 32bit 版しかないから・・・)、jre-8u231-windows-i586.exe とか叩いておきましょうと。
で PDFCreator みたいなので pdf 化すると。この時年賀状 - らんだむな記憶の要領で:
- PDFCreatorのプリンタドライバを入れて、[印刷]→[プロパティ]→[用紙/品質]→[詳細設定]→[用紙サイズ]から「PostScript カスタムページサイズ」を選択して100mmx148mmで出力
そしてこれを
とすれば良いはず・・・。
サイズ確認については以下とかでざっと見たらいい:*2
import os, glob import PyPDF2 pt_per_mm = 2.83 for f in glob.glob("*.pdf"): pdf = PyPDF2.PdfFileReader(f) media_box = [round(size/pt_per_mm) for size in pdf.pages[0].mediaBox] print(f"{os.path.basename(f)}: {media_box}") assert(media_box == [0, 0, 100, 148])
*1:Python - Apache OpenOffice Wikiを活用することになったようだ
*2:というのをJupyterLab経由で行おうとしたらハマったので次の記事へ続く・・・