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

Can I remove template via javascript?

Engaged ,
Jul 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

Created a report with several hidden templates spawned from a dashboard page. When users begin or finish, they "save as," renaming the file. I'm trying to create a button that, among other things, would reduce file size by deleting the hidden templates but I can't find any info on something akin to a "removeTemplate" method or accessing by template name and unhiding (so I can delete via pageNum). Any ideas or solutions? Thanx in advance.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.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

correct answers 1 Correct answer

Community Expert , Jul 07, 2016 Jul 07, 2016

Yeah, wasn't sure about that... Unhiding them and then deleting is the last

option, then.

On Thu, Jul 7, 2016 at 10:20 PM, jotasprout <forums_noreply@adobe.com>

Votes

Translate

Translate
Community Expert ,
Jul 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

The Document object has a method with exactly that name, removeTemplate, which takes the template name as a parameter and then removes it.

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 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

For future reference: Doc methods

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
Engaged ,
Jul 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

RTFM, right? Honest, I have my API Reference, SDK, and Object Specification open pretty much all the time. I pinky promise I would never ever bother y'all in the forums without exhausting all other sources first.

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
Engaged ,
Jul 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

My apologies, I should be more specific. I want the user (who has Acrobat Pro) to execute the script via button-click. I saw the removeTemplate method in the JavaScript API, but, as it states, it only seems to work in the console. When I attach the script to a button, it doesn't do anything.

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 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

If you want to use it from a button then you must also install a trusted function in a folder-level script. However, I think your approach is wrong. Removing the template is not going to help you much with the file size. Instead, you're better off deleting the template page entirely. If the Template object still exist it doesn't really matter, and the deletePages method does not require a trusted context, so you can use it directly from a button (in Acrobat only, unless the pages you want to delete were spawned from a template, in which case you can also use it in Reader).

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
Engaged ,
Jul 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

Exactly--I want to delete the pages themselves (which, unless I'm mistaken, also deletes the associated template) but I don't know how to refer to the pages since they're hidden templates. Must I unhide them first or could I do something like ...

this.deletePages(this.getTemplate("mytemplate").pageNum);

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
Engaged ,
Jul 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

Nope, that didn't work.

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 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

Not 100% sure, but I believe it will work if you specify the page number as

-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
Engaged ,
Jul 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

I felt so stupid for not thinking of that myself that I'm actually glad it didn't work. I'm just going to try unhiding them and deleting the last few pages of the doc (since they'll manifest at the end ... if we can say "spawn," I can say "manifest").

Thanks for all your help today.

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 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

Yeah, wasn't sure about that... Unhiding them and then deleting is the last

option, then.

On Thu, Jul 7, 2016 at 10:20 PM, jotasprout <forums_noreply@adobe.com>

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
Engaged ,
Jul 08, 2016 Jul 08, 2016

Copy link to clipboard

Copied

LATEST

And that worked beautifully.

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 ,
Jul 07, 2016 Jul 07, 2016

Copy link to clipboard

Copied

Note that the doc.removeTemplate method isn't available with Reader, and with Acrobat it's restricted to privileged context. The hidden property of a template object isn't controllable with Reader either.

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 08, 2016 Jul 08, 2016

Copy link to clipboard

Copied

(in Acrobat only, unless the pages you want to delete were spawned from a template, in which case you can also use it in Reader).

Yes but… This is available for Adobe Reader XI (11) and Acrobat Reader DC only, not in older versions.

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
Engaged ,
Jul 08, 2016 Jul 08, 2016

Copy link to clipboard

Copied

No, I'm using Acrobat Pro DC and my client will be using Acrobat Pro XI so that wouldn't be an issue.

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