Indesign 导出页面

问题描述

我正在尝试导出文档页面。我在导出页面甚至导出文档页面的项目时都遇到问题

导出文档页面时:

app = win32com.client.dispatch("InDesign.Application.CS6")
doc = app.Documents(1)
app.jpegExportPreferences.exportResolution = 150
page = doc.Pages(1)
page.Export(1699761735,f'{folder_selected}/test.png')
ERROR

Traceback (most recent call last):
  File "c:\Users\Sofia\Desktop\C.py",line 85,in <module>
    page.Export(1699761735,f'{folder_selected}/test.png')
  File "C:\Users\Sofia\AppData\Local\Programs\Python\python39\lib\site-packages\win32com\client\dynamic.py",line 511,in __getattr__
    raise AttributeError("%s.%s" % (self._username_,attr))
AttributeError: <unkNown>.Export

导出页面项目时:

app = win32com.client.dispatch("InDesign.Application.CS6")
doc = app.Documents(1)
app.jpegExportPreferences.exportResolution = 150
page = doc.Pages(1)
items = page.PageItems(1)
items.Export(1699761735,f'{folder_selected}/test.png')

它工作正常,但它导出单个项目,我可以更改项目但我希望导出整个页面

实际页面

The Image which should be exported alongside the Page

导出 Item 后的结果:

AFTER EXPORTING

如果我导出为 PDF,它工作正常。但我想要 JPG 或 PNG 格式。请问有什么解决办法吗?

解决方法

你的意思是这样吗?

import win32com.client
from pathlib import Path

app = win32com.client.Dispatch('InDesign.Application.CS6')

indd_file = Path(r'd:\test.indd')
doc = app.Open(str(indd_file))

app.pngExportPreferences.exportResolution = 150
doc.Export(1699761735,indd_file.parent / (indd_file.stem + ".png"))