Highlighted

Deleting specific templates (not pages)

New Here ,
Jun 19, 2019

Copy link to clipboard

Copied

Is there a way to delete specific templates without any reference to pages?

Currently on my set up i have options to spawn templates with no preferred order (as intended) and this results in the templates possibly spawning on different pages, depending on the user. (current code is a simple a.spawn({nPage: this.numPages, bRename: true, bOverlay: false}); on all my checkboxes)

However, i also want to give the user an option to remove the template as well. My current knowledge of deleting templates only consists of this.deletePages(). To the best of my knowledge, this deletes specific pages, not templates, which is what i want. Is there a code snippet that target specific templates instead of pages?

Topics

Acrobat SDK and JavaScript

Views

661

Likes

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

Deleting specific templates (not pages)

New Here ,
Jun 19, 2019

Copy link to clipboard

Copied

Is there a way to delete specific templates without any reference to pages?

Currently on my set up i have options to spawn templates with no preferred order (as intended) and this results in the templates possibly spawning on different pages, depending on the user. (current code is a simple a.spawn({nPage: this.numPages, bRename: true, bOverlay: false}); on all my checkboxes)

However, i also want to give the user an option to remove the template as well. My current knowledge of deleting templates only consists of this.deletePages(). To the best of my knowledge, this deletes specific pages, not templates, which is what i want. Is there a code snippet that target specific templates instead of pages?

Topics

Acrobat SDK and JavaScript

Views

662

Likes

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
Adobe Community Professional ,
Jun 19, 2019

Copy link to clipboard

Copied

Acrobat Reader can only delete spawned pages.

Likes

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
Reply
Loading...
New Here ,
Jun 19, 2019

Copy link to clipboard

Copied

I'm using acrobat pro, if it helps.

Perhaps i could elaborate a little more. I created a few templates that i named it SectionB, C, etc. However, the order of which they are opened are not specified, which means that a user can click to open Section C before Section B (on page 1 where all the checkbox fields are), resulting in page 2 being Section C and page 3 being Section B.

However, i also want to have the option to delete the Sections that were spawned as well. Because of the unspecified order that the Sections are opened (Section B can be on page 2 or 3 or whatever order the user opened it), i can never accurately delete a specified Section. If the user opens Section B, and wants to delete it after, a command to delete the page will never work because the particular section may not spawn at the same page every time.

I hope i made sense, really need some advice on this..

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jun 19, 2019

Copy link to clipboard

Copied

In a hidden text field on the template page you can save the section name. When the user wants delete Section B you can find all spawned pages of Section B.

Likes

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
Reply
Loading...
New Here ,
Jun 19, 2019

Copy link to clipboard

Copied

Sorry, i don't really understand what you are trying to say here. How would the user delete section B from the template page? I want the page to be deleted from a checkbox on page 1, not from the template page.

Likes

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
Reply
Loading...
Advocate ,
Jun 20, 2019

Copy link to clipboard

Copied

Just hanging in here…

As you set the Rename flag, fields on your spawned Template do contain the name of the Template.

So, in order to find the page number of the spawned Template, loop through the field names, and if there is a match of the field name with the template name, you get the page(s) on which it exists. Then delete those pages.

A warning: Because the page number of the spawned page becomes part of the field name, there is a risk for unwanted duplicate field names. To prevent this, it may be better to save the spawned field's values, delete all spawned pages (after the page to be actually deleted), and to re-spawn the remaining pages, and finally restore the field values.

Likes

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
Reply
Loading...
New Here ,
Jun 20, 2019

Copy link to clipboard

Copied

Could you provide me with a code snippet of how i would go about doing this? I love to try this but i have no idea how..

Likes

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
Reply
Loading...
Most Valuable Participant ,
Jun 20, 2019

Copy link to clipboard

Copied

This is not a trivial scripting task. You would need to write a code that does something like this:

- Iterate over all the fields in the file.

- Test their name against a regular expression that contains that name of the Template which you want to delete.

- If there's a match, add that page number to an array of page numbers to delete (if it's not already there).

- Sort that array by ascending or descending order.

- Iterate over that array (from the start if it's descending, or from the end if it's ascending), deleting each page number that appears in it.

Likes

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
Reply
Loading...
New Here ,
Jun 23, 2019

Copy link to clipboard

Copied

Dang, that sounds non-trivial indeed. Is there a place where i can have a glimpse of how the code would look like? I have enough common sense to replace certain codes that is specific to my document, but unfortunately not programming-savvy enough to conjure scripts out of thin air.

Likes

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
Reply
Loading...
Most Valuable Participant ,
Jun 24, 2019

Copy link to clipboard

Copied

You can hire someone to write the code for you, and then learn from it.

I've developed similar things in the past and would be happy to do so for you as well, for a small fee.

You can contact me privately via try6767 at gmail.com to discuss it further.

Likes

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
Reply
Loading...
New Here ,
Jun 25, 2019

Copy link to clipboard

Copied

Thanks for the offer. I'll give it a few more shots, and see what i can come up with. Cheers.

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jun 19, 2019

Copy link to clipboard

Copied

If you want to do that, make the template page hidden, and generate what you now have as a visible page that is a template by spawning the hidden template.

Likes

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
Reply
Loading...
New Here ,
Jun 19, 2019

Copy link to clipboard

Copied

yes, this is exactly what i am doing now. I have 7 pages in total, 6 of which are templates and hidden. The first page is an introduction and is where the checkboxes are for them to spawn and delete the 6 different sections (in any order they want).

However i cannot find a method to delete the pages that is specific to the particular section. If user 1 spawns the Sections in the sequence A B C D E F (in order from page 2 - 7), compared to user 2 who spawns Sections in the sequence B F D A C E (in order from page 2-7), i need a method to accurately delete Section C, for example, when both users click "Remove Section C" on page 1.

My current code this.deletePages() cannot target Section C, for example. I can set it to delete page 4, but that'll only work for user 1, and not user 2.

Likes

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
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF
Add a group