Specifying Encoding While Placing Files In InDesign Using Extendscript

2.1k views Asked by At

I have a script that places a Markdown file into a text frame in InDesign. Unfortunately, InDesign doesn't seem to be picking up on the UTF-8 encoding, as quotation marks and other things are ending up as “.

I tried setting file.encoding to "UTF-8" based on this question, all to no avail. Here's the relevant code as it stands:

var file = File.openDialog ("Select content markdown" , "Markdown:*.md", false );
file.encoding = "UTF-8";
myFirstTextframe.place(file);

How can I resolve this problem?

1

There are 1 answers

0
Nathan Arthur On

I'm not 100% sure (perhaps InDesign is just remembering what I selected in the Import Options window), but it seems like adding this solved my problem:

with(app.textImportPreferences){
    characterSet = TextImportCharacterSet.UTF8;
    useTypographersQuotes = true;
}