最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to showhide a page of a PDF Form by checking or unchecking a check box? - Stack Overflow

programmeradmin0浏览0评论

I have a form that I am trying to use page two as a continuation page that will only be shown when a user checks a box. I am using Adobe Acrobat DC cloud and I tried the following code.

if (this.rawValue == 0||this.rawValue ==""){
    xfa.resolveNode("Page2").presence = "hidden";
} 
else{
    xfa.resolveNode("Page2").presence = "visible";
}

However every time I try this or a variation of this code the debugger says:

ReferenceError: xfa is not defined 4:AcroForm:ExtensionYes:Annot1:MouseUp:Action1" is there a step I am missing or can someone remend a better way to acplish this?

I have a form that I am trying to use page two as a continuation page that will only be shown when a user checks a box. I am using Adobe Acrobat DC cloud and I tried the following code.

if (this.rawValue == 0||this.rawValue ==""){
    xfa.resolveNode("Page2").presence = "hidden";
} 
else{
    xfa.resolveNode("Page2").presence = "visible";
}

However every time I try this or a variation of this code the debugger says:

ReferenceError: xfa is not defined 4:AcroForm:ExtensionYes:Annot1:MouseUp:Action1" is there a step I am missing or can someone remend a better way to acplish this?

Share Improve this question edited Jul 20, 2017 at 0:59 Marc 4,8615 gold badges43 silver badges66 bronze badges asked May 26, 2015 at 14:02 JB11JB11 531 gold badge2 silver badges11 bronze badges 4
  • The code you just posted seems to be related to XFA-based PDF forms, meaning, forms created with Adobe Livecycle. If you are using AcroForms (forms created with Acrobat Professional) then this piece of code will not work. – yms Commented May 26, 2015 at 14:21
  • Is there a version of this code for AcroForms? – JB11 Commented May 26, 2015 at 14:27
  • Not that I know of, but I might be mistaken – yms Commented May 26, 2015 at 14:33
  • Normal PDF with AcroForms does know page templates. They might be what you are after. – mkl Commented May 26, 2015 at 20:46
Add a ment  | 

2 Answers 2

Reset to default 2

I ran across a very similar problem as this one.

The first step is that you need to define the page that you want to hide and show as a template. Make sure to uncheck that template to make it hidden by default.

  1. Go to Tools > Organize Pages
  2. Select the page that you want to convert to a template.
  3. Go to More > Page Templates
  4. Type a name for the template and click Add....
  5. Uncheck the checkbox next to the name to make it a hidden template.

Using Javascript you will add a new page to the document from the template like this. Use this when you test if the checkbox has been checked.

// This creates a new page from the template called "Template-Name"
this.getTemplate("Template-Name").spawn();

To hide the page that has been added you need to delete the page. In my case, I added a range of pages so had to delete a number of pages. Specify the page numbers to delete. (Note that the count starts at 0).

// This would delete pages 3-4
this.deletePages({nStart: 2, nEnd: 3});

I found this resource helpful in doing this even though it is a bit old and does not touch on deleting the pages at all. https://forums.adobe./docs/DOC-4061

You can also check out the Acrobat Developer center for documentation: http://www.adobe./devnet/acrobat.html.

@JB11 You can use page templates which can be spawned (ie visible), hidden and deleted. This will acheive what you want Acroforms (Acrobat).

The manual on it is here : http://help.adobe./livedocs/acrobat_sdk/10/Acrobat10_HTMLHelp/wwhelp/wwhimpl/mon/html/wwhelp.htm?context=Acrobat10_SDK_HTMLHelp&file=JS_API_AcroJS.88.1207.html

Start by defining the page you want to show hide as a template page from Tools > Organise Pages > Template Page in Acrobat.

发布评论

评论列表(0)

  1. 暂无评论