【问题标题】:how can I extract text from indd files or indesign files using python programs?如何使用 python 程序从 indd 文件或 indesign 文件中提取文本?
【发布时间】:2021-03-17 14:06:30
【问题描述】:

我需要创建一个 api,用户将在其中提供 indesign 文件,我需要从中提取文本。

【问题讨论】:

  • 嗯?阅读How to Ask 并创建一个minimal reproducible example
  • @AlonEitan 我有 indesign 文件 (.indd),我需要从中提取所有文本,有什么办法可以做到这一点,这就是我要问的全部
  • 您是否有 InDesign 服务器设置,可以更轻松地进行 indesign 操作

标签: adobe-indesign idml


【解决方案1】:

基本上可以这样:

from win32com.client import Dispatch

app = Dispatch('InDesign.Application.CS6')
doc = app.Open(r"d:\text.indd")
contents = ""
for story in doc.stories: contents += story.contents + "\n"
f = open(r"d:\text.txt", "w", encoding="utf8")
f.write(contents)
f.close()
doc.Close()

但是,特殊符号可能会出现故障。我相信使用本机 Javascript Extendscript 来完成这项任务是有意义的。像这样的:

var doc = app.open(File("d:/text.indd"));
var stories = doc.stories.everyItem().getElements();
var contents = "";
for (var i=0; i<stories.length; i++) contents += stories[i].contents + "\n";
var file = File("d:/text.txt");
file.open("w");
file.write(contents);
file.close();
doc.close();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-07
    • 2021-02-11
    • 2022-10-14
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多