Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Flatten PDF + Preserve internal/external links script

Explorer ,
May 25, 2024 May 25, 2024

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-flatten...

 

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.

TOPICS
How to , JavaScript , PDF
8.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
May 25, 2024 May 25, 2024

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

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2024 May 26, 2024

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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2024 May 25, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 25, 2024 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/cust...
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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2024 May 25, 2024

What do you mean? Are the other pages not flattened?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 25, 2024 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 25, 2024 May 25, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2024 May 25, 2024

Look on the security tab on the document properties dialog.  This will list the allowed permissions for the document. It's likely changes are blocked. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 25, 2024 May 25, 2024

Thank you for your reply.
See attached screen capture of the permissions. Everything's allowed.
However, once again, only a single page (always the same) was sucessfully processed. The rest remains as is : unflattened with all the links intact.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 25, 2024 May 25, 2024

I should add that the initial PDF I ran the script on is secured, nothing's allowed on the permission page. It didn't make a difference though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2024 May 25, 2024

What are you trying to flatten, exactly?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 25, 2024 May 25, 2024

The entire PDF, which is mostly text -- there are no illustrations, but for its cover and some ornemental chapter heads.
My hope is to make it difficult to copy the text (by dragging the mouse over its text and copying it), while retaining its many links, which really help people navigate the book/PDF.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2024 May 25, 2024

I thought so. This is not what the flattenPages command does. You can protect the file using an encryption policy, but be aware there are plenty of ways around it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 25, 2024 May 25, 2024

Thank you for clarifying what "Flatten" does. And yes, although these techniques can't stop anyone from getting to the text, they may discorage some people.
Two comments:
+ There is still that single page at the beginning of the document that becomes "flattened", in the way that I hoped the whole text would. So, it's confusing. I guess there's no solution really.
+ I did "secure" the file with a password protected encryption, but the text could still be easily copy-pasted (as easily as without an encryption). And Acrobat doesn't seem to offer the possibility of encrypting the text in a way that would make the text un-copiable. So ... frustrating.
Thanks for your time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2024 May 25, 2024

- The command you used should not have any effect at all on the ability to copy the text, so there must be something else at play here. If you could share the file (both the original and the "flattened" version), even if only some pages from it, that would be helpful.

- You must make sure the check-box next to "Enable copying of text, images and other content" is NOT ticked when applying the policy:

 

try67_0-1716668208461.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2024 May 25, 2024

Edited -

**Never Mind** I see that it is not fields you are interested in flattening. 

 

odd behavior. Can you post the document, or at least a portion of the document?

Have you checked the "display" property on the fields on the other pages? 

This is the property that is controlling the flattening.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 26, 2024 May 26, 2024

Thanks for your help.
Here's a portion of the PDF: https://e.pcloud.link/publink/show?code=XZuuvMZFCCAnpfTqXbwKXq3UIaRXyzLCc87

The only links that work are external links, as they lead to external webpages -- of course, the internal links don't work because I've removed all the text that comes after the table of contents. You'll also note that the text is easily copyable by dragging one's mouse over it and copy-pasting it -- this behavior is easily noticeable on the last two pages of the PDF portion.

 

So, once again, I'd like the text to *not* be copyable by mouse (which is what I call "flattened"), while retaining functional links (external and internal).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2024 May 26, 2024

Here you go. I applied a security policy that prevents content extraction to your file. All the links still work.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 26, 2024 May 26, 2024

Thank you.
1) Could you descrive the method you used to produced your tests? Did you use the "Password Security setting" method you describe in one of your previous posts?

2) See attached GIF: this is the behavior (copy and paste text) I'm trying to stop from happening -- the GIF shows text from the file you just exported.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 26, 2024 May 26, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2024 May 26, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 26, 2024 May 26, 2024

Ah ! Yes. This is it. It works.
Thank you very much.  This is exactly what I was looking to achieve.
... and I'm not going to do it, because my readers wouldn't be able to search the document, which I had no idea would happen. It would also be inconsiderate, as you note yourself, and would defeat the purpose of the entire document to begin with. So ... not gonna happen.

Thank you very much for your generous time, and patience with my confusing questions. I'll keep this technique in mind for future PDF adventures.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 26, 2024 May 26, 2024
LATEST

I think that's the right call, and you're welcome!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines