Skip to main content
Known Participant
May 25, 2024
Answered

Flatten PDF + Preserve internal/external links script

  • May 25, 2024
  • 1 reply
  • 9346 views

Hello

 

I'm trying to flatten a PDF document and preserve its many internal and external hyperlinks.
Reading through this forum, it looks like it's possible to do with Acrobat, in this discussion, for instance :

https://community.adobe.com/t5/acrobat-discussions/how-do-i-preserve-urls-hyperlinks-if-i-am-flattening-a-pdf-form/m-p/9158574#M57203

 

The method seems to be:

"You need to use this code:

this.flattenPages({nNonPrint: 1});"

 

However, I have no idea where to insert this code in Acrobat?

Would love to get some help with this. Thank you.

This topic has been closed for replies.
Correct answer try67

And here's the behavior I'm looking for and that I somehow achieved yesterday, but on only one page (see GIF below):
Although I attempt to drag my mouth over the text to select it, I get nothing. The text is unselectable. My cursor turns into a hand icon and I can only move the page up and down. And all the while, the hyperlink is still valid and active.
This is what I'd like to achieve for the entire document.


Your video can't be from an Adobe application. You probably used a third-party application that does not respect the security policy.

The way to achieve what you described is to outline the text, which basically converts it into an image. There's a built-in command in the Preflight tool that allows you to do that. Attached is the result.

This is considered very inconsiderate for the user, though, as it completely disables the option to search the file, for example.

1 reply

try67
Community Expert
Community Expert
May 25, 2024

You don't insert it anywhere. You can run it from the JS Console, or via a Custom Command, for example.

JK5C2AAuthor
Known Participant
May 25, 2024

Thank you. This worked: the key word was "Custom Command", which I didn't know I needed to use.
I've done that now, setting a script command to run. I found out how to do it here: https://experienceleague.adobe.com/en/docs/document-cloud-learn/acrobat-learning/advanced-tasks/custom
However, the script only does its magic for the first page or so, and not the other 677 pages. But that's for another question.

JK5C2AAuthor
Known Participant
May 25, 2024

Sadly no. I thought that was due to the number 1 in the code : nNonPrint: 1
Maybe the script doesn't run, althought it says it does.


This is the report I get, with a screen capture of my script:

 

Action Name: Flatten w Links

[-]ESB_secured.pdf(Succeeded)

Execute JavaScript

Command Name: Execute JavaScript
Command Start Time: 2024-05-25 18:08:18
Command Status: Succeeded
Command Finish Time: 2024-05-25 18:08:25