Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help with ghostscript command syntax to compress pdf without flattening .

24 views
Skip to first unread message

Chandrashekhar Thalkar

unread,
Nov 21, 2022, 9:46:21 AM11/21/22
to
I have PDF with form fields, I need to compress pdf but without flattening i.e. retain ability of fillable form fields after pdf compression.

Following command is use to compress PDF file it compresses PDF file by 35% but pdf is flatterend i.e. in generated compress PDF does not have editable form fields

gs -dSAFER -dBATCH -dNOPAUSE -dQUIET -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -sOutputFile=SAMPLE_compressed_via_gs.pdf SAMPLE.pdf

ken

unread,
Nov 22, 2022, 9:38:38 AM11/22/22
to
In article <3c149175-4095-43cd...@googlegroups.com>,
ctha...@nolo.com says...
>
> I have PDF with form fields, I need to compress pdf but without flattening i.e. retain ability of fillable form fields after pdf compression.
>
> Following command is use to compress PDF file it compresses PDF file by 35% but pdf is flatterend i.e. in generated compress PDF does not have editable form fields
>
> gs -dSAFER -dBATCH -dNOPAUSE -dQUIET -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -sOutputFile=SAMPLE_compressed_via_gs.pdf SAMPLE.pdf

Ghostscript (more proerly Ghostscript's pdfwrite device) doesn't
compress PDF files.

If you are prepared to sacrifice quality, then it can reduce the file
size, but the default settings do not do so (and you are using
/PDFSETTINGS=/default, which is quite pointless since those are the
defaults!)

It is possible that the output PDF file may be smaller than the input
file, but there is absolutely no guarantee that this is so, and it may
equally well be larger. It all depends on how the input file is
organised. For more details on the process see:

https://ghostscript.readthedocs.io/en/latest/VectorDevices.html

As to forms....

There are two types of Forms in PDF; AcroForms and XML forms (XFA), you
don't say which your PDF file is using, and you have not supplied an
example to look at.

Ghostscript and the pdfwrite device do not support XFA, at all. If your
file contains XFA forms then the output file may look correct (probably
won't) but it will no longer contain any XFA and will therefore no
longer be a form.

The PDF interpreter and pdfwrite device do not preserve the AcroForm and
do not preserve Widget annotations as annotations. The *content* of the
form is transferred, as marking objects on the page, so it will look the
same. But there is no AcroForm in the output file, and so you can no
longer edit the form fields.

You can't do what you want using Ghostscript currently. That may change
in the future, but I would not hold my breath waiting for it.


Ken
0 new messages