Protect Your PostScript Files from Being Converted to PDF

 in

If you've ever used fillable PDF forms, you've probably noticed that you can't save a copy of the form once it has been filled in. Being sneaky, you probably might try to print the form to a file (PostScript) and then use ps2pdf to convert it to a PDF. But, this doesn't work either, because ghostscript gives you an error saying the file can't be redistilled. This article shows you how to protect your own PostScript using the same technique.

The PostScript code that protects these PostScript files follows:

%ADOBeginClientInjection: DocumentSetup Start "No Re-Distill"
%% Removing the following eleven lines is illegal, subject to the Digital Copyright Act of 1998.
mark currentfile eexec
54dc5232e897cbaaa7584b7da7c23a6c59e7451851159cdbf40334cc2600
30036a856fabb196b3ddab71514d79106c969797b119ae4379c5ac9b7318
33471fc81a8e4b87bac59f7003cddaebea2a741c4e80818b4b136660994b
18a85d6b60e3c6b57cc0815fe834bc82704ac2caf0b6e228ce1b2218c8c7
67e87aef6db14cd38dda844c855b4e9c46d510cab8fdaa521d67cbb83ee1
af966cc79653b9aca2a5f91f908bbd3f06ecc0c940097ec77e210e6184dc
2f5777aacfc6907d43f1edb490a2a89c9af5b90ff126c0c3c5da9ae99f59
d47040be1c0336205bf3c6169b1b01cd78f922ec384cd0fcab955c0c20de
000000000000000000000000000000000000000000000000000000000000
cleartomark
%ADOEndClientInjection: DocumentSetup Start "No Re-Distill"

So, all you have to do to protect your own PostScript files from being converted into PDFs is to insert this code into the PostScript after the %BeginSetup or the %EndProlog lines of the PostScript. The following script does just that for the PostScript file passed to it on the command line:

#!/bin/bash

if [[ $# -ne 1 ]]; then
	echo "Usage: $0 PSFILE"
	exit 1
fi
psfile=$1

nl='
'
protect='
\%ADOBeginClientInjection: DocumentSetup Start "No Re-Distill"
\%\% Removing the following eleven lines is illegal, subject to the Digital Copyright Act of 1998.
mark currentfile eexec
54dc5232e897cbaaa7584b7da7c23a6c59e7451851159cdbf40334cc2600
30036a856fabb196b3ddab71514d79106c969797b119ae4379c5ac9b7318
33471fc81a8e4b87bac59f7003cddaebea2a741c4e80818b4b136660994b
18a85d6b60e3c6b57cc0815fe834bc82704ac2caf0b6e228ce1b2218c8c7
67e87aef6db14cd38dda844c855b4e9c46d510cab8fdaa521d67cbb83ee1
af966cc79653b9aca2a5f91f908bbd3f06ecc0c940097ec77e210e6184dc
2f5777aacfc6907d43f1edb490a2a89c9af5b90ff126c0c3c5da9ae99f59
d47040be1c0336205bf3c6169b1b01cd78f922ec384cd0fcab955c0c20de
000000000000000000000000000000000000000000000000000000000000
cleartomark
\%ADOEndClientInjection: DocumentSetup Start "No Re-Distill"
'
protect="${protect//$nl/\\n}"

if grep --silent '^%%BeginSetup' $psfile; then
	sed -e "/\%\%BeginSetup/a\\$protect" $1 
else
	sed -e "/\%\%EndProlog/a\\$protect" $1 
fi

To test it, take an unprotected PostScript file and convert it to a protected PostScript file, and then try to convert it to a PDF:

$ ps2pdf unprotected.ps
$ sh prps.sh unprotected.ps >protected.ps
$ ps2pdf protected.ps
This PostScript file was created from an encrypted PDF file.
Redistilling encrypted PDF is not permitted.
Error: /undefined in --eexec--
Operand stack:
   --nostringval--   --dict:98/200(L)--   quit
Execution stack:
   %interp_exit   .runexec2   --nostringval--   ...
Dictionary stack:
   --dict:1169/3371(ro)(G)--   --dict:0/20(G)--  ...
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 8.62: Unrecoverable error, exit code 1

As you can see, you can convert unprotected.ps to PDF without a problem, but once you add the super-secret protection code to it and create protected.ps, you're no longer able to convert to PDF.

______________________

Mitch Frazier is an Associate Editor for Linux Journal.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Beware of forms that are based on templates

Arjan's picture

Not related to the tip above, but sometimes pre-filled forms (such as order confirmations or even badly coded invoices) do allow for saving, but in fact have a reference to some template which is then still only available online. If that template is not available in the future, then the saved form is useless too. To prevent that, one might want to print to PDF yet another time.

I'm just wondering

Anonymous's picture

I'm just wondering, the cynic in me is thinking this article is a subtle way of providing the means to go in the opposite direction (ie. Remove those lines and now you can save your forms) without actually stating such which would be much more useful to most people.

LoL!!!!!

DSkoll's picture

Thanks for the terrific joke. But maybe you're six weeks late?

nice info

uniquegeek's picture

Too cute. Thanks.

So does that mean if LJ deleted a very important part of this web page, they could be subjected to penalties?

//tongue-in-cheek

uniquegeek.blogspot.com

You could always comment

Anonymous's picture

You could always comment them out without removing the eleven lines.

It isn't clear the code is sufficient to qualify as copyright management information, either, subject to sanction on removal.

http://www4.law.cornell.edu/uscode/html/uscode17/usc_sec_17_00001202----...

(c) Definition.— As used in this section, the term “copyright management information” means any of the following information conveyed in connection with copies or phonorecords of a work or performances or displays of a work, including in digital form, except that such term does not include any personally identifying information about a user of a work or of a copy, phonorecord, performance, or display of a work:
(1) The title and other information identifying the work, including the information set forth on a notice of copyright.
(2) The name of, and other identifying information about, the author of a work.
(3) The name of, and other identifying information about, the copyright owner of the work, including the information set forth in a notice of copyright.
(4) With the exception of public performances of works by radio and television broadcast stations, the name of, and other identifying information about, a performer whose performance is fixed in a work other than an audiovisual work.
(5) With the exception of public performances of works by radio and television broadcast stations, in the case of an audiovisual work, the name of, and other identifying information about, a writer, performer, or director who is credited in the audiovisual work.
(6) Terms and conditions for use of the work.
(7) Identifying numbers or symbols referring to such information or links to such information.
(8) Such other information as the Register of Copyrights may prescribe by regulation, except that the Register of Copyrights may not require the provision of any information concerning the user of a copyrighted work.

No-Redistill doesn't appear to be a recognized term or condition for use of the work, and there is no elaboration.

Ahh, if you say so

Mitch Frazier's picture
Too much for me!

Mitch Frazier is an Associate Editor for Linux Journal.

How to Save the PDF as a PDF

James H's picture

Ignoring the irritation we can create with the above article...

You can save your filled-out PDF form by using a PDF printer driver, such as the free, open source PDF Creator, available from pdfforge.

To Windows (and Adobe), PDF Creator just looks like any other Windows printer. Your output, however, is a nice, clean PDF file, saved with your choice of attributes wherever you'd like on disk.

CUPS-PDF

Tweenk's picture

The Linux counterpart, a PDF printer driver for CUPS, is called CUPS-PDF. It's in the cups-pdf package in Debian. I haven't checked whether it circumvents the above protection though.

Windows?

Mitch Frazier's picture

I guess that's a thought, maybe I could just install Windoze and we could just change the name of this site to windowsjournal.com.

Mitch Frazier is an Associate Editor for Linux Journal.

"Digital Copyright

El Perro Loco's picture

"Digital Copyright Act"...

Nausea... Gonna puke!

Vaya Afuera Perro Loco

Mitch Frazier's picture

No se vomite aquí.

Mitch Frazier is an Associate Editor for Linux Journal.

DRM? DMCA? Seriously?

Josh Surber's picture

Considering that the code from this article invokes the DMCA, I highly doubt that any readers of this site would be willing to use it. In fact, I never thought I would read an article on any Linux site that advocated any kind of DRM. It is a sad, sad day.

homework

Norbert's picture

Josh, try to find out what a 'bijection' is. Once you've done that, as an exercise, try to find a possible application to this novel concept in the article above....

READ BETWEEN THE LINES!!!

Anonymous's picture

LOL!!!!!

Um... see comment below re: reverse engineering... gawd.

How you use this information is up to you, but I never said that

Mitch Frazier's picture

Next you'll be trying to say that I said Guns Kill People and not People Kill People.

Mitch Frazier is an Associate Editor for Linux Journal.

Why not just..

Weboide's picture

Mitch,
Why not just 'Print into a file' and choose PDF? This saves the information you filled in into the created PDF..but you cannot edit the information from that file; that's the only bad point.
Does your technique permit editing?

Doesn't always work

Mitch Frazier's picture

Some fillable PDFs won't let you print to a PDF (at least with Acrobat Reader), they will only print to Postscript output files.

What I describe here is a way to prevent the creation of PDFs from a "protected" postscript file. If you're using it in reverse to create a PDF from a protected postscript file (something I don't and wouldn't advocate since it would violate copyright law), then no it doesn't allow you to fill in more data.

Mitch Frazier is an Associate Editor for Linux Journal.

Good Thing...

Anonymous's picture

Boy it's a good thing no one can reverse engineer protection like that. Just think of all the forms that a person could save to PDF after stripping the complex protection method...

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState