🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
10 messages
10 total messages Started by John_Kallios Sun, 22 Mar 2009 23:50
JS: CS4 print active document
#474
Author: John_Kallios
Date: Sun, 22 Mar 2009 23:50
34 lines
1365 bytes
Hello

Scripting guide gives this line as an example to print the active document

app.activeDocument.print();

I also want to print using a print preset. The guide indicates this text:

To print a document using a printer preset, include the printer preset in the print command.

If my preset name is: Myoutput

How would I add the preset name? Would it be:

app.activeDocument.print(Myoutput);

or

app.activeDocument.print();
print = Myoutput

Trying to run this single line script is also giving me an error

app.activeDocument.print();

JavaScript error!
Error Number 8
Error String: "Syntax error"
Line: 1
Source "{\rtf1\mac\ansicpg1000\cocartf824
\cocoasubrtf410"
Offending Text: "\"

(Serious Newbie alert)
Re: JS: CS4 print active document
#475
Author: Dave_Saunders
Date: Mon, 23 Mar 2009 00:22
33 lines
2452 bytes
John,

First problem is that you are saving your script as rtf so it has no hope of working.

Look in the Adobe Utilities folder and fire up ExtendScript Toolkit CS4. Use File/New to make a new script document. Copy and paste your script from TextEdit (I assume that's what you're using) to your script document.

Now go to the Help menu and fire up the Object Model Viewer. Under Browser, choose the InDesign CS4 object model. Under Classes, choose Document. Under properties and methods, choose the method print(). That shows you the full syntax of the print method.

It shows you this:

Document.print (printDialog: Boolean , using:any)
Adobe InDesign CS4 (6.0) Object Model Object Model
Prints the Document(s).
printDialog: Data Type: Boolean
Whether to invoke the print dialog (Optional)
using: Data Type: any
Printer preset to use. Can accept: PrinterPresetTypes enumerator or PrinterPreset. (Optional)

This might be a bit hard to understand for the uninitiated. The call takes two arguments. The first is a boolean (true or false) indicating whether to show the dialog. The second indicates which PrinterPreset to use.

Since you want to use a specific one for which you know the name, you must first get a reference to it. PrinterPresets also are objects. Look under Classes again for PrinterPreset (singular). And now look under Properties and Methods again, this time look for the parent property. Notice that the parent is the application object.

This means that to get a reference to the preset you want you need to write:

myPreset = app.printerPresets.item("Myoutput");

and now you can write:

app.activeDocument.print(false, myPreset);

Hope this helps not just with the immediate problem but also with how to go about solving these kinds of issues.

Dave
Re: JS: CS4 print active document
#476
Author: John_Kallios
Date: Mon, 23 Mar 2009 02:54
16 lines
1158 bytes
Yes, it is a big help to the "uninitiated". :)

I am having another problem

My preset is named

ps

myPreset = app.printerPresets.item("ps");
app.activeDocument.print(false, myPreset);

If I turn it to true, it does launch the print window. If false, no print is created. When set to true and the print window opens, the preset is not set to "ps"

However, I have CS2 at home and CS4 out work. I will spend more time tomorrow trying to figure out my failing.

You have been a big help. Thank you!
Re: JS: CS4 print active document
#494
Author: Dave_Saunders
Date: Mon, 23 Mar 2009 15:56
7 lines
840 bytes
John,

It might be necessary to also set the page range value of the printPreferences. It's a long time since I did any printing by script.

I suspect that turning the first argument to true causes the second argument to be ignored.

Dave
Re: JS: CS4 print active document
#499
Author: John_Kallios
Date: Mon, 23 Mar 2009 18:08
49 lines
2111 bytes
Hey Dave, (and lurkers)

I got to admit to missing the obvious. The scripting guide also mentioned to check out the sample script "PrintDocumentWithPreset.jsx"

However, when run, it creates a new window, adds a small frame and stops. I named my preset to "ps". (it is printing to postscript)

Is this the line, var myDocument = app.documents.add();, that is creating the new document. Should it not be app.activeDocument? I will be trying to get my mind around this.

(note: just because you responded once does not mean I expect you to keep responding. I value everyone's time :))

//PrintDocumentWithPreset.jsx
//An InDesign CS4 JavaScript
//
//Prints the active document using the specified printer preset.
//Assumes you have a printer preset named "myPrintPreset" and that a document is open.

main();

function main(){
    mySetup();
    mySnippet();
    myTeardown();
}

//<setup>
function mySetup(){
	var myDocument = app.documents.add();
	myDocument.pages.item(0).rectangles.add();
	try{
		app.printerPresets.add({name:"ps"});
	}
	catch(myError){}
}
//</setup>

//<snippet>
function mySnippet(){
    //<fragment>
    //Prints the active document using the specified printer preset.
    var myDocument = app.documents.item(0);
    myDocument.print(false, app.printerPresets.item("ps"));
    //</fragment>
}
//</snippet>

//<teardown>
function myTeardown(){
}
//</teardown>
Re: JS: CS4 print active document
#402
Author: Dave_Saunders
Date: Mon, 23 Mar 2009 19:22
5 lines
959 bytes
You should delete the call to mySetup. myTeardown does nothing so you could delete that too.

That leaves you with the call to mySnippet which does exactly the same as the code you wrote because for the purposes of this script, app.activeDocument is the same as app.documents.item(0) which is the same as app.documents[0].

Dave
Re: JS: CS4 print active document
#403
Author: Dave_Saunders
Date: Mon, 23 Mar 2009 19:25
3 lines
807 bytes
Oh wait! If you're using a printer preset that "prints" to a file, you have to set up the file reference as well. It's the printFile property of app.printPreferences.

Dave
Re: JS: CS4 print active document
#404
Author: John_Kallios
Date: Mon, 23 Mar 2009 20:31
5 lines
824 bytes
Thank you Dave.

Since an open beer does not travel through the mail too well, I'll drink in it your honor. (actually, it will be a martini)

Of course I will be back. But, I'm will try figuring it out at my next stuck point.
Re: JS: CS4 print active document
#405
Author: John_Kallios
Date: Mon, 23 Mar 2009 21:05
3 lines
703 bytes
btw, I'm already stuck but I'm not going to ask yet.

I may have a few holes in the wall while I bang my head against it.
Re: JS: CS4 print active document
#406
Author: Dave_Saunders
Date: Mon, 23 Mar 2009 21:43
3 lines
748 bytes
To find out about Files and Folders, check the Core JavaScript object model and also read the JavaScript Tools Guide (under the ESTK Help menu).

Dave
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads