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

How can add a document A4?

Enthusiast ,
Oct 17, 2019 Oct 17, 2019

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?

 

TOPICS
Scripting
821
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 , Oct 21, 2019 Oct 21, 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);

Translate
Adobe
Community Expert ,
Oct 21, 2019 Oct 21, 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);

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 ,
Dec 19, 2020 Dec 19, 2020

Hello,

it is possible to define font size at docPreset?

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 ,
Dec 19, 2020 Dec 19, 2020

No.  Font size is not a DocumentPreset property. 

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
Community Expert ,
Dec 19, 2020 Dec 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.

 

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 ,
Dec 20, 2020 Dec 20, 2020

Thank you,

I will go with your suggestion

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 ,
Jan 04, 2021 Jan 04, 2021

Hi @CarlosCanto 

 

The documentation states that addDocument's arguments are

 

addDocument(startupPreset, presetSettings)

 

with the second, presetSettings, being a DocumentPreset object.

 

The first, the startupPreset, is said to be a string.  Where does one get this string from and what is it related to?

 

Thanks in advance.

 

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
Community Expert ,
Jan 04, 2021 Jan 04, 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.

new document profiles.JPGexpand image

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.

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 ,
Jan 04, 2021 Jan 04, 2021
LATEST

Thank you @CarlosCanto .  That's very helpful. 

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