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

Flatten PDF + Preserve internal/external links script

Explorer ,
May 25, 2024 May 25, 2024

Copy link to clipboard

Copied

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

Views

4.7K

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

What are you trying to flatten, exactly?

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

- 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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

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