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

TIMELY needing a Script which, upon Attached Document close, opens a Sibling Attached Document

Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

 

I need execute precisely what the Subject states.

 

There is a document named Parent.pdf.  It contains two attachments – Son.pdf, and Daughter.pdf. [and Son.pdf is multi-page].  When Son.pdf is closed by user, Daughter.pdf is to open [in a new window, as set by its Initial View].

 

If Son.pdf is a single-page document, I can achieve the effect through its Page Properties, with Trigger: Page Close, Action: Go to a page view.  But this doesn't apply, as the user is to traverse multiple pages, prior to closing Son.pdf.

 

– – –

 

I have seen scripts to open an attachment by filename, but only as an Action of a Button Properties trigger [and while the parent document remains open].

 

I am aware of Document Actions, and Document JavaScripts [but only for setting a 'dirty file' state].

 

1.  Can this be achieved by a document-level script?

2.  Presumably nowhere else?

3.  Precisely what code is called for?  I have coded a modest amount, but have little intuitive guidance [beyond "don't be a sucker about case-sensitivity"].  My mastery of nomenclature, syntax, and punctation is limited.

 

Prompt replies shall be gratefully welcomed.

 

TOPICS
Create PDFs , Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF forms

Views

741

Translate

Translate

Report

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 , Jun 08, 2022 Jun 08, 2022

The openDoc command does not work when you try to place it in the Will Close event of a document (or as a doc-level script that executes when the document is opened), so no, this isn't possible to do automatically.

What you can do, though, is add a Close button to "Son.pdf", and have it execute this code:

 

var newPath = this.path.replace(this.documentFileName, "Daughter.pdf"); 
this.closeDoc(true);
app.openDoc(newPath);

 

When the user clicks it, the "Daughter.pdf" file will open, and "Son.pdf"

...

Votes

Translate

Translate
Community Expert ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

The openDoc command does not work when you try to place it in the Will Close event of a document (or as a doc-level script that executes when the document is opened), so no, this isn't possible to do automatically.

What you can do, though, is add a Close button to "Son.pdf", and have it execute this code:

 

var newPath = this.path.replace(this.documentFileName, "Daughter.pdf"); 
this.closeDoc(true);
app.openDoc(newPath);

 

When the user clicks it, the "Daughter.pdf" file will open, and "Son.pdf" will close (without saving -- remove the 'true' parameter from closeDoc to prompt the user to save the file, if needed).

Votes

Translate

Translate

Report

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
Explorer ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

 

Thank you Gilad.  I've tested your suggestion; it works just as advertised.  Still not quite ideal though, insofar as:

  1.  The documents contain no JavaScript, thus not impeding the user who, either deliberately, or inadvertently, does not Enable Acrobat JavaScript.  My target audience are expected to be OK with Enable, but that's why I aked about a "nowhere else" solution [non-script].  This is merely a minor preference.  Of greater concern is

  2.  The narrative intent, in the story being told.  Daughter.pdf is to involuntarily appear upon closure, by whatever means, of Son.pdf.  In fact, the user is not even aware that Daughter.pdf exists.  When they're done with Son.pdf, they close it in their normal fashion [viewer window Close button, ⌘W, Menu Item>File>Close File].  Only then do they become aware of Daughter.pdf, who opens 'by surprise'.  She is indispensable, since verily 'tis she who tells the end of the story, and overall

  3.  The fewer buttons, the better.

 

Were I to use a button, I guess I could non-scriptly have the button Go to a page view' [opening Daughter.pdf], and 'Execute a menu item' to close Son.pdf?

 

Really the chief remaining difficulty is this:  The button works.  But the narrative is dependent on the user utilizing a button to Close Document, in a non-buttony storytelling landscape.  Above all, you can see this problematic scenario – the user is finished reading Son's tale, and closes Son's document.  Alas, Daughter never gets her say.  Thus the narrative never reaches its intended conclusion (leaving children around the world, to weep).

 

Votes

Translate

Translate

Report

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 ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

If it's so essential the two files are read in sequence, why not combine them to a single file?

Votes

Translate

Translate

Report

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
Explorer ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

 

That defeats the effect of 'by surprise'.  Think in terms of dramatic, theatrical stage presentation.  A character is 'stationed somewhere on a military base', so far as the other characters know.  When that character does surprisingly 'burst upon the scene' of the living room, the effect is undermined, should stage hands leave the curtain pulled too far back in the wings, revealing the soldier's imminent presence.  So it is, that the user is 'tipped off' by the indication of a Page n+1 coming up next in the document.  In my case, the user is to think, "Well, that's all Son had to say.  I guess that's all there is to it.  âŒ˜W."  When suddenly thus, in steps Daughter, to reveal that, in fact, 'there's more to the story'.  It's a dramatic dynamic; a temporal dynamic, if you will.  Set that to the side.

 

Apart from that, the characters, Son, and Daughter, are aesthetically contrasting, all the way down to aspect ratio.  Think of it this way [just so you know, my project has nothing to do with office supplies – this is simply a figurative, not literal, analogy].  Son is a collection of pencils, presented in an upright portrait layout, at Actual Size of 1 x 9 in.  Initial View: 'Resize window to initial page'.  Daughter is a collection of scissors tools, presented in a prone landscape layout, at Actual Size of 9 x 3 in.  Initial View: 'Resize window to initial page', 'Center window on screen'.  Each sibling.pdf is accorded their own appropriate, distinct and separate, aspect ratio, each in a separate viewer window.

 

Now, one does injustice to the characters, if all the pencils, and all the scissors, are simply displayed on a singular page size of 9 x 9 in.  In fact, this is the primary reason that I open Daughter as a separate file.  She supplants Son, by differentiation of not only content, but also aspect ratio.  In some instances this is particularly beneficial, since when both are visible, each is readily distinguishable from the other.  And, separately manipulable.  Think of an automobile dashboard, atop which sits a roadmap, a paperback tour guide book, and a pack of cigarettes.

 

It occurs to me that my approach, which I regularly employ, by way of Initial View, may be unnecessarily clumsy.  Leading to the question – "Does Acrobat allow script-control of the viewer window?"  Akin to Initial View.  It would be marvelous to be able to, for instance, toggle On and Off the 'Hide tool bars' setting.  My impression is "No".  I mean, it would be terrific to effectively be able to command the viewer window – 'Snap to Image', or 'Snap to ButtonXYZ'.  My current approach to this, in such as a 'sibling documents dance', is seen at time-point 0:36, in Carnegie-Stadia op het Podium.

 

The closest I've found on the subject is Thom Parker's enchanting, and thorough, tutorials on Page Geometry.

 

All of which is to say, I guess I could have simply answered your question with – "Because the two documents exhibit different aspect ratios."

 

Votes

Translate

Translate

Report

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
Explorer ,
Jun 23, 2022 Jun 23, 2022

Copy link to clipboard

Copied

 

I found a reason to add a Close button to "Son.pdf".  In this case, your script works splendidly.

 

If anyone coming across this post has thoughts on controlling relation of viewer window to document content, pease see the context of [and linked example for] my below query, "Does Acrobat allow script-control of the viewer window?"

 

Votes

Translate

Translate

Report

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
Explorer ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

Here's a variation, with respect to determining the manner in which Daughter.pdf is to be opened [Above, I originally specified "in a new window, as set by its Initial View".  With your script, Daughter.pdf correctly opens in a new window.

 

I now aim to open a different Daughter.pdf exactly in place of Son.pdf, as exactly similar as possible [e.g. identical Window dimensions,  Page layout, Zoom inheritance {else manually specified to match}]. 

 

I am familiar with the Acrobat settings pertaining to opening an attachment under 'Go to a page view', and there stipulate 'New window', 'Existing window', 'Target', 'Zoom', etc.  

 

But it is there a way to specify the equivalent in a script?  The most necessary is simply to be in the existing window.  Initial View built into Daughter.pdf can handle much of the remainder.

 

Votes

Translate

Translate

Report

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 ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

New window/Existing window can't be specified with a script, unless you change the global setting for it, called openInPlace, like this:

app.openInPlace = true; (or false)

Target: Assuming you mean a Named Destination in the target file, that can be done. See the cDest property of the openDoc method.

Zoom: This is only possible to set if the target document is disclosed. Then you can get a reference to it from openDoc and set its zoom settings using the zoom and zoomType properties.

Votes

Translate

Translate

Report

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
Explorer ,
Jul 09, 2022 Jul 09, 2022

Copy link to clipboard

Copied

LATEST

Ahhhk – the Forum Notifications Ghost is at work, again [just now saw this].  My account settings indicate 'Notify me'.  I experience lapse in notifications.  The only fix seems to be toggle to 'Don't notify me', then back to 'Notify me'.  Then it works, for ~72 hours, anyway.

 

Target: Yes, I meant Named Destination.

 

Where do I set app.openInPlace ?  I try it in that 6-8-22 script, either before or after, app.openDoc(newPath).  No effect.  app.openDoc(newPath) appears to open doc, in the same fashion just as if opening a new file from computer desktop.

Votes

Translate

Translate

Report

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