Protect Your PostScript Files from Being Converted to PDF
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.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Designing Electronics with Linux
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Build a Skype Server for Your Home Phone System
- Validate an E-Mail Address with PHP, the Right Way
- Why Python?
- A Topic for Discussion - Open Source Feature-Richness?
- Tech Tip: Really Simple HTTP Server with Python
- Great
3 hours 28 min ago - Reply to comment | Linux Journal
3 hours 36 min ago - Understanding the Linux Kernel
5 hours 50 min ago - General
8 hours 20 min ago - Kernel Problem
18 hours 23 min ago - BASH script to log IPs on public web server
22 hours 50 min ago - DynDNS
1 day 2 hours ago - Reply to comment | Linux Journal
1 day 2 hours ago - All the articles you talked
1 day 5 hours ago - All the articles you talked
1 day 5 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
Beware of forms that are based on templates
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
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!!!!!
Thanks for the terrific joke. But maybe you're six weeks late?
nice info
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
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 is an Associate Editor for Linux Journal.
How to Save the PDF as a PDF
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
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?
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..png)
Mitch Frazier is an Associate Editor for Linux Journal.
"Digital Copyright
"Digital Copyright Act"...
Nausea... Gonna puke!
Vaya Afuera Perro Loco
No se vomite aquí.
Mitch Frazier is an Associate Editor for Linux Journal.
DRM? DMCA? Seriously?
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
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!!!
LOL!!!!!
Um... see comment below re: reverse engineering... gawd.
How you use this information is up to you, but I never said that
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..
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
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...
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...