Skip to main content
Inspiring
October 30, 2023
Question

How to correctly create an HTML object in an InDesign layout with UXP?

  • October 30, 2023
  • 1 reply
  • 181 views

Basic example:

 

// currentPage = the current page InDesign

let htmlContent = '<p>Hello</p>';

let newRectangle = currentPage.rectangles.add();
let htmlItem = newRectangle.htmlItems.add( { htmlContent } );
 

This code works partially.
A block is created in the InDesign layout and the HTML code is correctly assigned.

 

But it doesn't work in the HTML preview or in a digital publication.

 

If the HTML block is created manually in the InDesign interface, there is an additional step which "validates" the specificity of the HTML block.

 

I've tried browsing javascript objects created manually or in JS UXP, and I can't detect any difference.
But there is a difference that prevents it from working properly.

 

Does anyone have any information on this subject?

 

Many thanks for your help!

This topic has been closed for replies.

1 reply

Inspiring
October 30, 2023

I found a (not very clean) workaround.


I manually created an Html block in a hidden layer.
I use this Html block as the master element and duplicate and customize it with UXP JS as many times as necessary.
Ideally, I'd like to be able to create an Html block with JS UXP from scratch.

 

Thanks for your insights!