Skip to main content
ar59790884
Participant
February 3, 2016
Question

Strange issue with spawning additional pages from template

  • February 3, 2016
  • 3 replies
  • 2271 views

Hi everybody,

I hope I'll get or find a solution to my problem I came across and I can't figure out why it does happen.

For a client I created an Acrobat Form wich has a basic layout of 5 pages and 4 hidden page templates. These, if needed for that case, can be spawned by pushing a button which spawns the needed page before the last 3 pages (in the middle of the document). Does happen on Acrobat Pro and Reader on Mac and Windows

So I came up with the following script to do so which is the same for all for spawnable pages except the template name:

// pageSpawn

var pageCount = 0;

var pagePos = 0;

pageCount = this.numPages;

pagePos = pageCount-3;

var b = getTemplate("TemplateName");

b.spawn({nPage: pagePos, bRename: false, bOverlay: false});

This works like a charme for the first two templates to be spawned. They are in the correct position, all fields are there, the pages after the newly spawned are all fine.

But now things start to get strange. When the third page is spawned, four things can happen randomly:

1. the spawned page is in the wrong position, mostly it is spawned before the last two pages instead of three and after the former third to last page

2. the spawned page is ontop of the third to last page

3. it copies the third to last page, but the template does not show

4. the page is spawned before the last two page and the former page in this position is gone

This can even be replicated by using an pdf with no content on it except page indicators to see what happens. I put up an empty pdf with 4 pages wich just contain 1 headline wich sais "page 1, page 2" and so on.

I then create an empty page template with the headline "empty" to see where it spawns. Excecuting the script from JavaScript-Debugger and also a created button.

Same random behavior as in the pdf with content in it. As a note: this does not happen when spawning at the end of the document.

I've already spent hours searching the internet to find a soulution for this problem or am I missing here on something?

Hope someone came across this and has a solution or hint where to take a look for me.

Thanks in advanced.

If more info is needed, just let me know.

This topic has been closed for replies.

3 replies

ar59790884
Participant
April 12, 2016

Any news to this issue?

It still doesn't seem to work.

Karl Heinz  Kremer
Community Expert
Community Expert
April 12, 2016

I know that one template related bug I reported was fixed with the latest update to Acrobat DC. Are you sure you are running the latest version? If it's not working, have you reported it to Adobe via the bug report form (Feature Request/Bug Report Form)? Just posting in the forum will in most cases not get Adobe's attention (most of us here are users of Adobe's products, just like you).

Inspiring
February 3, 2016

The numPages property for the PDF file returns the number of pages in the PDF.

When specifying a specific page within the file using JavaScript  one needs to use the zero based page number. So the last page of the PDF has an internal page value of "this.numPages - 1"; not "this.numPages;". And that is why you are one off or were you want the pages inserted.

Also as new pages are added the number of pages changes so you may need to allow for this change with each new added page before adding the next page.

ar59790884
Participant
February 4, 2016

gkaiseril schrieb:

The numPages property for the PDF file returns the number of pages in the PDF.

When specifying a specific page within the file using JavaScript  one needs to use the zero based page number. So the last page of the PDF has an internal page value of "this.numPages - 1"; not "this.numPages;". And that is why you are one off or were you want the pages inserted.

Also as new pages are added the number of pages changes so you may need to allow for this change with each new added page before adding the next page.

I'm well aware of that. As I've written it does work just fine for the first two pages to be spawned!

When using console.println() to output the variables each time when excetuted, theses values are also correct (number of pages and the estimated position) and still it does one of the random actions mentioned in my opening post.

The function spawn() still randomly does copy, move, delete and empty out page which it is NOT supposed to do.

Bernd Alheit
Community Expert
Community Expert
February 4, 2016

The actual version of Adobe Acrobat and Acrobat Reader has bugs with spawning templates.

Bernd Alheit
Community Expert
Community Expert
February 3, 2016

What version of Adobe Acrobat do you use?

ar59790884
Participant
February 3, 2016

Oh, I forgot to mention the Acrobat versions.

Developing/Testing on Acrobat Pro DC 2015.010.20056 (Mac)

Testing on Acrobat Reader DC 2015.010.20056 (Win)

Happens on a friends and clients PC's too, not sure what Versions they have in use.