-1

I am trying to export the page of the document. I am facing issues both in exporting the page or even exporting an item of the PAGE of the document

While exporting a Page of the Document:

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

While Exporting an Item of the Page:

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

It works fine, But it exports a single item, I can change the item but I want the whole page to export.

The Actual Page:

The Image which should be exported alongside the Page The results after exporting an Item:

AFTER EXPORTING

It works fine if I export as PDF. But I want it in JPG or PNG format. Any solutions Please?

Sofi
  • 498
  • 4
  • 12
  • Not sure, but I think you need to use `pageString`. [This](https://community.adobe.com/t5/indesign/is-exporting-to-jpeg-possible-with-javascript/td-p/10963814) may have the info you're looking for. – cybernetic.nomad Mar 25 '21 at 16:20

1 Answers1

0

Do you mean something like this?

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"))
Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23
  • If you want to export some pages from a multipage document you can add a couple of lines before the last line: `app.pngExportPreferences.pngExportRange = 1785742674 ` (this magic number means PNGExportRangeEnum.EXPORT_RANGE) and `app.pngExportPreferences.pageString = page_num` where `page_num` is a range of pages '1' or '3, 10-15' etc – Yuri Khristich Mar 29 '21 at 20:06