ArtifexSoftware / Ghostscript.NET

Ghostscript.NET - managed wrapper around the Ghostscript library (32-bit & 64-bit)
https://ghostscript.com
GNU Affero General Public License v3.0
391 stars 152 forks source link

Ghostscript command to FLATTEN ANNOTATIONS but keep HYPERLINKS alive #113

Closed Geo-Van closed 11 months ago

Geo-Van commented 11 months ago

Please let me ask regarding the wonderful feature -dPreserveAnnots :

Applying { -dPreserveAnnots=false } on a PDF file, it flattens ANNOTATIONS, but also it flattens all the HYPERLINKS contained in the initial pdf file. Is there a way to flatten annotations but keep HYPERLINKS alive, please?

jhabjan commented 11 months ago

You can use -dPreserveAnnotTypes

Take a look under the PreserveAnnots switch here: https://ghostscript.readthedocs.io/en/latest/VectorDevices.html#pdf-file-output-pdfwrite

If you preserve Link annotations then hyperlinks should continue to work.

Geo-Van commented 11 months ago

Thank you very much! This gives me the correct explanation. Thank you! Please note that before Ghostscript version 9.27 (included), the following Ghostscript command assumes separate "thing" annotations AND Hyperlinks : -dPreserveAnnots=true So, when applied to a pdf file, it gives ----> Annotations Flatten & Hyperlinks not Flatten

But as your answer, Ghostscript after version 9.27, "CHANGE POLICY" and correctly assumes annotations AND hyperlinks "same thing".

But is there an extra COMMAND to can use in order to "separate" annotations from hyperlinks as versions 9.27 and before do?

jhabjan commented 11 months ago

You can use -dPreserveAnnotTypes

Take a look under the PreserveAnnots switch here: https://ghostscript.readthedocs.io/en/latest/VectorDevices.html#pdf-file-output-pdfwrite

If you preserve Link annotations then hyperlinks should continue to work.

Geo-Van commented 11 months ago

Thank you very much! Very interesting info. Please help me to do it work with an example - Lets say i have the following command: gs.exe -o output.pdf -dPreserveAnnots=false -sDEVICE=pdfwrite input.pdf

According to your answer, now, i must add the follow to the command line in order to flatten annotations but keep hyperlinks alive: -c "/PreserveAnnotTypes [/Link] def" -f

I try to "marry" the above two in the correct command format, but with no success: gs.exe -o output.pdf -dPreserveAnnots=false -c "/PreserveAnnotTypes [/Link] def" -f -sDEVICE=pdfwrite input.pdf

Can you please show us how to do it correct, please?

jhabjan commented 11 months ago

It should look something like this:

gs -dNOPAUSE -dQUIET -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf -c "/PreserveAnnotTypes [/Link] def" -f basic_link_1.pdf

there should not be any more switches after -f, only input filenames

Geo-Van commented 11 months ago

Thanks for your reply, I try: gs -dNOPAUSE -dQUIET -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf -c "/PreserveAnnotTypes [/Link] def" -f basic_link_1.pdf BUT, please note that this is NOT working, unfortunately..... it flatten NOTHING, all annotations are NOT flatten, and hyperlinks are also NOT flatten.
Where is the error regarding the above command SYNTAX, please?

jhabjan commented 11 months ago

I've tried this and it doesn't work for me either.

gs -dNOPAUSE -dQUIET -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf -dPreserveAnnots=false -c "/PreserveAnnotTypes [/Link] def" -f basic-link-1.pdf

You can report core Ghostscript bugs here: bugs.ghostscript.com

Geo-Van commented 11 months ago

Thank you, Report is done at:

https://github.com/ArtifexSoftware/Ghostscript.NET/issues/116 https://bugs.ghostscript.com/show_bug.cgi?id=707198

Geo-Van commented 11 months ago

Hello, The latest version 10.02 works: gs -sDEVICE=pdfwrite -o output.pdf -c "/PreserveAnnotTypes [/Link] def" -f input.pdf

Thank you!