Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Apply Export Tag to Paragraph Style

Explorer ,
Aug 10, 2016 Aug 10, 2016

Hi,

I'm learning basic scripting and today I need to apply an export tag to a paragraph style for PDF export (see screenshot) across dozens of documents. I thought this would be the perfect opportunity to use a script to automatize this time intensive process.

Does anybody have any tips on how to do that?Screen Shot 2016-08-10 at 1.22.55 PM.png

TOPICS
Scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 10, 2016 Aug 10, 2016

Look in to InDesign's DOM (Document Object Model), and specifically at Paragraph Style properties: ParagraphStyle

In there you can find a property "styleExportTagMaps" – a plural, probably because you can add multiple tags to a single style (?). Browsing to that, you get StyleExportTagMap , which, in turn, has a simple string property called "exportTag".

So if style points to a valid Paragraph Style, you can do this to add either a tagName or a className to it (only one of these; you must set the

...
Translate
Community Expert ,
Aug 10, 2016 Aug 10, 2016

Look in to InDesign's DOM (Document Object Model), and specifically at Paragraph Style properties: ParagraphStyle

In there you can find a property "styleExportTagMaps" – a plural, probably because you can add multiple tags to a single style (?). Browsing to that, you get StyleExportTagMap , which, in turn, has a simple string property called "exportTag".

So if style points to a valid Paragraph Style, you can do this to add either a tagName or a className to it (only one of these; you must set the other to an empty string):

style.styleExportTagMaps.add({exportType:"PDF", exportAttributes:'', exportTag:tagName, exportClass:className});

I've only used this with an exportType of "EPUB", but if I'm remembering correctly "PDF" is 'the' other option.

I haven't used those exportAttributes before. If you want to find out what it can contain, set a number of options in the user interface for a random style and then read out the styleExportTagMap of that style to see what values it holds.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 11, 2016 Aug 11, 2016

Thanks Jongware,

You pointed me in the right direction; here's what I came up with:

  var myDoc = app.activeDocument;

                      

            // Body Text

            var body = myDoc.paragraphStyles.itemByName("Body Text");

                body.styleExportTagMaps.add({exportType: "EPUB", exportTag: "p", exportClass: "", exportAttributes: ""});

                body.styleExportTagMaps.add({exportType: "PDF", exportTag: "P", exportClass: "", exportAttributes: ""});   

           

            // H1

            var h1 = myDoc.paragraphStyles.itemByName("H1");

                h1.styleExportTagMaps.add({exportType: "EPUB", exportTag: "h1", exportClass: "", exportAttributes: ""});

                h1.styleExportTagMaps.add({exportType: "PDF", exportTag: "H1", exportClass: "", exportAttributes: ""});  

           

            // H2

            var h2 = myDoc.paragraphStyles.itemByName("H2");

                h2.styleExportTagMaps.add({exportType: "EPUB", exportTag: "h2", exportClass: "", exportAttributes: ""});

                h2.styleExportTagMaps.add({exportType: "PDF", exportTag: "H2", exportClass: "", exportAttributes: ""});  

           

            // H3

            var h3 = myDoc.paragraphStyles.itemByName("H3");

                h3.styleExportTagMaps.add({exportType: "EPUB", exportTag: "h3", exportClass: "", exportAttributes: ""});

                h3.styleExportTagMaps.add({exportType: "PDF", exportTag: "H3", exportClass: "", exportAttributes: ""});      

            // Tables - Body Text

            var tablesBody = myDoc.paragraphStyles.itemByName("Tables - Body Text");

                tablesBody.styleExportTagMaps.add({exportType: "EPUB", exportTag: "p", exportClass: "", exportAttributes: ""});

                tablesBody.styleExportTagMaps.add({exportType: "PDF", exportTag: "P", exportClass: "", exportAttributes: ""}); 

                                        

            // Student Version     

                // Student MS - Body Text

                var StudentBody = myDoc.paragraphStyleGroups.item("Student Version").paragraphStyles.item("Student MS - Body Text");

                    StudentBody.styleExportTagMaps.add({exportType: "EPUB", exportTag: "p", exportClass: "", exportAttributes: ""});

                    StudentBody.styleExportTagMaps.add({exportType: "PDF", exportTag: "P", exportClass: "", exportAttributes: ""});     

                            

                // Student Cover - H1

                var StudentCoverH1 = myDoc.paragraphStyleGroups.item("Student Version").paragraphStyles.item("Student Cover - H1");

                    StudentCoverH1.styleExportTagMaps.add({exportType: "EPUB", exportTag: "h1", exportClass: "", exportAttributes: ""});

                    StudentCoverH1.styleExportTagMaps.add({exportType: "PDF", exportTag: "H1", exportClass: "", exportAttributes: ""});                   

                                               

                // Student Cover - H2

                var StudentCoverH2 = myDoc.paragraphStyleGroups.item("Student Version").paragraphStyles.item("Student Cover - H2");

                    StudentCoverH2.styleExportTagMaps.add({exportType: "EPUB", exportTag: "h2", exportClass: "", exportAttributes: ""});

                    StudentCoverH2.styleExportTagMaps.add({exportType: "PDF", exportTag: "H2", exportClass: "", exportAttributes: ""});                   

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 05, 2025 Aug 05, 2025

I have exactly the same problem. I can apply 'P', 'H1', 'H2', etc., but InDesign doesn't seem to recognize 'Artefact' as a valid exportTag for exportType 'PDF'!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 05, 2025 Aug 05, 2025

Artifact

🙂

Edited, maybe not 😞

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 05, 2025 Aug 05, 2025

Aha — that does seem to work! It doesn't throw an error, and scripting reveals that its value has indeed been set to 'Artifact':

var mySelection = app.selection[0];
var myParagraphStyle = mySelection.appliedParagraphStyle;
alert(myParagraphStyle.styleExportTagMaps[0].exportTag);

 

Jeremybowmangraphics_0-1754388996741.png

…yet it doesn't show up in user interface:

 

Jeremybowmangraphics_1-1754389036672.png

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 05, 2025 Aug 05, 2025

Object export has it as Artefact.

Screenshot 2025-08-05 at 11.19.34.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 05, 2025 Aug 05, 2025

As far as I can tell, if a script creates a document, giving several paragraph styles the export tag 'Artifact', at first they all appear in Paragraph Style Options --> Export Tagging as '[Automatic]'. But as soon one of them is manually set to 'Artefact', the rest follow suit.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 05, 2025 Aug 05, 2025
LATEST

It is odd.  I set the artifact tag on style 2. It reports to my script that it has been set, but it does not export to pdf.

Screenshot 2025-08-05 at 16.00.59.pngScreenshot 2025-08-05 at 16.00.18.png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines