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

I would like to automatically flatten document when dynamic stamp is applied.

New Here ,
Mar 23, 2016 Mar 23, 2016

Copy link to clipboard

Copied

Good afternoon,

I am looking to automatically flatten my document when I place a dynamic stamp. I am pretty new to Java and have cobbled together code to make my stamp, learning on the way.

I have tried adding this.flattenPages() to the script, but when I do Acrobat crashes when I place the stamp.

I cannot install the menu bar script to add a flatten document button, because I don't have admin permissions.

Thank you in advance for any help.

Patrick

TOPICS
Acrobat SDK and JavaScript , Windows

Views

115.9K

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
Engaged ,
Mar 23, 2016 Mar 23, 2016

Copy link to clipboard

Copied

The Stamp script runs between the time that you click on the page and the stamp gets added to the page. If you try to flatten the page in that time... well... you see what happens.

However, if you put this.flattenPages() as the cExpr parameter in a setTimeOut method with (maybe) a 250 millisecond delay, it should work since the code won't execute until 250 milliseconds elapses.

J-

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
New Here ,
Mar 24, 2016 Mar 24, 2016

Copy link to clipboard

Copied

Thanks, I figured it was something like that. I will see if I can put in setTimeOut.


Thanks!

Patrick

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
New Here ,
Mar 24, 2016 Mar 24, 2016

Copy link to clipboard

Copied

Good morning again,

So, the delay worked, but only within the stamp file itself. If I place the stamp either in the stamp pdf or in another pdf while the stamp pdf is open, the stamp pdf gets flattened. Am I missing an argument to specify the current file?

This is what I added to the end of my stamp script:

function delayClose()

{

this.flattenPages()

}

app.setTimeOut("delayClose()",500)

Thanks,

Patrick

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
New Here ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

Hi,

Did you finally found any solution on the above?

Thanks in advance!

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 ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

Use...

app.setTimeOut("this.flattenPages()",500)

When you define the function, it loses it's context when the stamp is applied.

Also, review the articles here Free Video Content & Full Listing of Available Videos to be sure you're executing the code when the stamp is being placed and lnot when it's being loaded into the Acrobat UI.

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 ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

This is dangerous. What if the user changes files just after applying the stamp? It will flatten a different 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
Community Expert ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

Only if the other files had their disclosed property set to true.

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 ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

I don't think so. The file doesn't have to be disclosed for the flattenPages command.

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 ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

No... but in order to execute the JavaScript in a document other than the one it originated from, that document would need to be disclosed.  

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 ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

I just tested it and the original file was flattened, even if I moved to another one, so I guess the original scope is used when the code is executed. In that case, it should be OK. Anyway, half a second is not much time to change files, really...

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
New Here ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

Thank you for the tip! My question is how to make this line of code to work in the document where the stamp is placed. I inserted

the app.setTimeOut("this.flattenPages()",500); in the stamp's code and works fine but only in the dynamic stamps document itself (as mentioned and by a another member above). Any help is appreciated! 

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 ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

The parent document where the stamp is being applied to can be accessed like this:

event.source.source

I tried adding the flattenPages command to the stamp directly and it works, but it didn't flatten the stamp itself. Maybe with the time-out it will work, though.

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
New Here ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

I have also tried event.source.source.flatenpages() written in the stamp's code. Placing the stamp in a document flattens the whole document except the stamp. I have also tried the following (i.e. for the revised stamp) but with no success:

if(event.source.forReal &&

   (event.source.stampName == "#DRevised"))

{

app.setTimeOut("this.flattenPages()",500)

}

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 ,
Mar 04, 2018 Mar 04, 2018

Copy link to clipboard

Copied

Why didn't you use event.source.source in that last one?

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
New Here ,
Mar 04, 2018 Mar 04, 2018

Copy link to clipboard

Copied

You mean app.setTimeOut("event.source.source.flattenPages()",500)? This won't work. I think my mistake is on how I use the app.setTimeOut...

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 ,
Mar 04, 2018 Mar 04, 2018

Copy link to clipboard

Copied

Yeah, that's what I meant. I didn't test it, though... Why do you think there's a problem with your use of setTimeOut?

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
New Here ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

Sorry for my too late reply,

I have tried several options, the closest on what I am trying to do is the following (i.e. for the Revised stamp):

if(event.source.forReal &&

   (event.source.stampName == "#DRevised"))

{

event.source.source.app.setTimeOut("this.flattenPages()",500)

}

The time delay works but the flattening is applied to the stamps pdf, therefore I replaced 'this' with 'event.source.source' but now it does not work at all, neither at the stamps nor at the destination pdf where I place the stamp.. Any suggestion is welcome!

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 ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

Close... try this.

if(event.source.forReal && event.source.stampName == "#DRevised") {

     app.setTimeOut("this.flattenPages()",500)

}

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
New Here ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

Unfortunatelly nope. The result is the same as:

if(event.source.forReal && event.source.stampName == "#DRevised")

{

event.source.source.app.setTimeOut("this.flattenPages()",500)

}

.. the delay works but still the stamp pdf gets flattened instead of the destination pdf. I guess the problem is the 'this' which always reffers to the stamps pdf.

In case inside { } I do not use the app.setTimeOut and I put only 'event.source.source.flattenPages()' it works correctly and the destination pdf becomes flattened (BUT of course the stamp which just placed is not included in the flattening - and this is why I need the app.setTimeOut).

Where I am now.. I understand that my mistake is on how I use the app.setTimeOut. It works with ("this.flattenPages()",500) but flattens the stamps pdf file. It does NOT work at all with ("event.source.source.flattenPages()",500). Something (but not 'event.source.source') must replace 'this', in order the problem to be solved.

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 ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

That seems odd... but try this...

Hopefully, the global object won't be specific to the stamp file.

if(event.source.forReal && event.source.stampName == "#DRevised") {

    global.docToFlatten = event.source.source;

    app.setTimeOut("global.docToFlatten.flattenPages()",500)

}

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
New Here ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

This is it, It worked!! Thank you very much for your help and for your time! My next project is to to exclude only the sticky notes from the flattening. I'll try myself to prepare a script, in case I need help I will revert in a new topic. Thanks again!

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 ,
Mar 13, 2018 Mar 13, 2018

Copy link to clipboard

Copied

LATEST

Just set the notes to be non-printing (annot print property set to false) then use flattenPages(1).

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
LEGEND ,
Mar 23, 2016 Mar 23, 2016

Copy link to clipboard

Copied

What version of Acrobat are you using?

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
New Here ,
Mar 24, 2016 Mar 24, 2016

Copy link to clipboard

Copied

Morning,

Acrobat 11.0.15

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