Skip to main content
Participating Frequently
October 8, 2023
Answered

Create InDesign document with specific preferences UXP

  • October 8, 2023
  • 1 reply
  • 505 views

Hi form, this is my first atempt to create a document using UXP plugin.

From the code below the document is creating 6 Pager document with size 100x210mm and with 3mm bleeds as described in the "documentPreferences"

However I'm not able to set "marginPreferences" as 5mm. 

The ocde runs well without errors but margins 15mm (which I guess taken from default parameters - I see 15mm margins in the file > new Window)


Could you mabe give me some suggestions?

const { entrypoints } = require("uxp");
const { app } = require("indesign");

//const indesign = require("indesign");

entrypoints.setup({

  panels: {
    showPanel: {
      show({node} = {}) {
        document.getElementById("btnCreateTrifold").addEventListener("click", () => {
          const doc = app.documents.add({
            
            marginPreferences: {
              top: "5mm", 
              left: "5mm", 
              bottom: "5mm", 
              right: "5mm"
            },
            
            
            documentPreferences: {
              pageWidth:  "100mm",
              pageHeight: "210mm",
              
              pagesPerDocument: 6,

              documentBleedBottomOffset: "3mm",
              documentBleedInsideOrLeftOffset: "3mm",
              documentBleedOutsideOrRightOffset: "3mm",
              documentBleedTopOffset: "3mm",

              facingPages: false,
              allowPageShuffle: false,

            }

          });
          console.log(doc.marginPreferences);
          // Set margin sizes
          


          // Set the page size for pages 1 and 6

          // Stick pages 1, 2 and 3 together

          // Stick pages 4, 5 and 6 together

          
        });
      }
    }
  }
});

 

Correct answer Eryk G

Hi there

 

I found the way to adjust the margins and the problem was that last time i tried to adjust 
Doc.marginPreferences. Eventhough in the documentation we have posibility to use it, it's a wrong way.
In fact there is no way to have margins in document. In normal wey we can adjust margins only on the pages or in master pages.

Application.marginPreferences

Document.marginPreferences

Page.marginPreferences
When we creating the document margins are in the Application side. so the right code will look like this.
First adjust the margins in the app side and then create the document.

  // Set margin sizes
  app.marginPreferences.bottom = "10mm";
  app.marginPreferences.left = "10mm";
  app.marginPreferences.right = "10mm";
  app.marginPreferences.top = "10mm";


  //add document
  const doc = app.documents.add();

 


Thanks!
Found out you can also set a document preset before creating the doc:

const docPreset = app.documentPresets.add();
docPreset.top = "0mm";
docPreset.bottom = "0mm";
docPreset.left = "0mm";
docPreset.right = "0mm";
const doc = app.documents.add(true, docPreset);
docPreset.remove(); //if you don't want to save it for later

1 reply

Robert at ID-Tasker
Legend
October 8, 2023

I'm not JS guy, but I think you should set it inside documentPreferences:

 

          const doc = app.documents.add({
            
            documentPreferences: {
              pageWidth:  "100mm",
              pageHeight: "210mm",

               marginPreferences: {
                 top: "5mm", 
                 left: "5mm", 
                 bottom: "5mm", 
                 right: "5mm"
               },
            
              pagesPerDocument: 6,

              documentBleedBottomOffset: "3mm",
              documentBleedInsideOrLeftOffset: "3mm",
              documentBleedOutsideOrRightOffset: "3mm",
              documentBleedTopOffset: "3mm",

              facingPages: false,
              allowPageShuffle: false,

            }

          });

 

or something like that.

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#MarginPreference.html

 

ZazaChugoAuthor
Participating Frequently
October 9, 2023

Hi Robert

 

The thing is that "marginPreferences" isn't part of the "documentPreferences" 😞
Application.marginPreferences

Document.marginPreferences

Page.marginPreferences

Anyway thank you very much for the replay and I'll continue dive in to find the solution.

Robert at ID-Tasker
Legend
October 9, 2023

Right, sorry. 

 

Margin Preferences is readonly of the Document. 

 

I'm on my phone, so you have to setup margins AFTER creating your document.