Skip to main content
Participating Frequently
July 17, 2023
Question

Cannot delete page using javascript with adobe acrobat

  • July 17, 2023
  • 2 replies
  • 395 views

Chào mọi người.

Tôi đang sử dụng Adobe Acrobat để tạo 1 tập PDF.

Hiện tại tôi có 3 trang (và 2 trang bị ẩn đi)
Khi tôi ấn vào 1 button ở cuối trang 3, nó sẽ hiển thị 1 trong 2 trang bị ẩn (tùy theo điều kiện kiểm tra của tôi)
Tôi sử dụng spawn để hiển thị trang ở cuối (trang 3 + 1 trang thì vị trí hiển thị là 4).

Nhưng có 1 vá đề là khi tôi ấn vào 1 button ở cuối trang 4, thì nó không bị xá di.

Tôi sử dụng lệnh this.deletePages(this.pageNum); thì nó không hoạt động.
*Tôi không sử dụng lệnh hidden vì khi tôi sử dụng, có vẻ các biến (variable) tôi đặt ở các trang nó sẽ bị mất (không hiển thị các dữ liệu tôi đã nhập ở trang 1 2 3).
Ai có thể giải đáp giúp tôi (hoặc gợi ý cho tôi) lý do tôi đang gă h lf gì không?
Tôi cảm ơn!

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
July 17, 2023

Hard to say without seeing the actual file, but it's generally a bad idea to use the pageNum property for such operations.

If you want to delete the current page use event.target.page (which will return the page number where the button field that triggered the action is located), or if that button has multiple duplicates then pass an input parameter to a function to delete the current page. The pageNum property is tricky, as one could press the delete button on another page (if it's in view), and it will delete the wrong one.

Participating Frequently
July 18, 2023

 Đây là file khi tôi mở PDF.

Đây là code javascript tôi để trong Action khi ấn vào button để hiển thị

var p4 = this.getTemplate("Page4"); // Tôi đã thay tên của template vào code gửi cho bạn để nó dễ hình dung hơn

p4.spawn({nPage: this.pageNum + 1, bRename: false, bOverlay: false});

 

Còn đây là khi tôi muốn Ẩn/Xoá trang tôi vừa spawn

this.deletePages(this.pageNum);

 

Cảm ơn bạn đã quan tâm

try67
Community Expert
Community Expert
July 18, 2023

Again, do not use this.pageNum for these operations. And if you're not renaming the fields then using event.target.page will not work, as there will be multiple copies of them, as I said. You will need to find some other way of identifying which page to delete.

Nesa Nurani
Community Expert
Community Expert
July 17, 2023

Do you get errors reported?

Can you share file?

Participating Frequently
July 18, 2023

Xin lỗi vì đã trả lời bạn muộn.
Đây là code javascript tôi để trong Action khi ấn vào button để hiển thị

var p4 = this.getTemplate("Page4");

p4.spawn({nPage: this.pageNum + 1, bRename: false, bOverlay: false});

 

Còn đây là khi tôi muốn Ẩn/Xoá trang tôi vừa spawn

this.deletePages(this.pageNum);

 

Cảm ơn bạn đã quan tâm