Skip to main content
daitranthanhoa
Inspiring
October 17, 2019
Answered

How can add a document A4?

  • October 17, 2019
  • 3 replies
  • 1049 views

i try this method:

var newDoc=app.documents.addDocument("A4", app.getPresetSettings("A4"));

But it occur error:

 an Illustrator error occurred: 1346458189 ('PARM')

 

How can add a document size A4?

 

This topic has been closed for replies.
Correct answer CarlosCanto

you can't just add your own arguments. Look at the documentation to find out what kind of arguments you need to pass to the addDocument function. The function is expecting Color Mode and a document Preset

 

// create A4 size document

var docPreset = new DocumentPreset;
docPreset.width = 595.28;
docPreset.height = 841.89;
docPreset.units = RulerUnits.Millimeters;
docPreset.colorMode = DocumentColorSpace.RGB;

var idoc = app.documents.addDocument(DocumentColorSpace.RGB, docPreset);

3 replies

CarlosCanto
Community Expert
Community Expert
January 5, 2021

Hi @femkeblanco, the documentation is wrong. The first argument should be a document preset string. Valid strings are the names of the document profiles saved in your system, default or created by you. These are the same document profiles you see when you create a New Document by hand.

this is the correct info

Documents.addDocument (startupPreset: string , presetSettings: DocumentPreset , showOptionsDialog: Boolean 😞 Document Adobe Illustrator 25 Type Library Create a new document from a preset. startupPreset: Data Type: string The name of a startup document preset. presetSettings (optional): Data Type: DocumentPreset Custom settings to apply to the preset. showOptionsDialog (optional): Data Type: Boolean If false, do not show Options dialog.

femkeblanco
Legend
January 5, 2021

Thank you @CarlosCanto .  That's very helpful. 

CarlosCanto
Community Expert
Community Expert
December 19, 2020

I recently noticed the documents.addDocument() function in the documentation is wrong. It's a miracle that it works as written above.

 

the addDocuments() first argument should be a document preset, not ColorSpace. ColorSpace is the first argument of the documents.add() function

 

so, technically, it is possible to add a default font to new documents created as long as your first create a New Document Profile.

 

then in your script

 

var docPreset = new DocumentPreset;

// ....add preset properties if you want to override the deafult "profile" document

var docProfile = 'myProfile'; // or default "Print" or "Web"

var idoc = app.documents.addDocument(docProfile, docPreset, false);

 

 

it doesn't work perfectly as it seems to always create CYMK documents, but at least that can be overwritten with docPresets properties.

 

Inspiring
December 20, 2020

Thank you,

I will go with your suggestion

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
October 22, 2019

you can't just add your own arguments. Look at the documentation to find out what kind of arguments you need to pass to the addDocument function. The function is expecting Color Mode and a document Preset

 

// create A4 size document

var docPreset = new DocumentPreset;
docPreset.width = 595.28;
docPreset.height = 841.89;
docPreset.units = RulerUnits.Millimeters;
docPreset.colorMode = DocumentColorSpace.RGB;

var idoc = app.documents.addDocument(DocumentColorSpace.RGB, docPreset);

Inspiring
December 19, 2020

Hello,

it is possible to define font size at docPreset?

femkeblanco
Legend
December 19, 2020

No.  Font size is not a DocumentPreset property.