HowTo: create PDF printer with save as dialog + small files

Questions about applications and software
Forum rules
Before you post please read how to get help
Post Reply
iaselle
Level 1
Level 1
Posts: 7
Joined: Mon Jun 30, 2014 5:34 pm
Location: Toulouse, France

HowTo: create PDF printer with save as dialog + small files

Post by iaselle » Thu Jul 10, 2014 11:49 am

Here is a method gathered from various forums in order to create a PDF printer like the famous PDFcreator that works on MS-Windows.
Unlike PDFCreator, CUPS-PDF produces very large PDF files and has no dialog in order to choose the PDF file name and directory.
Therefore, I developed a set of files in order to create a new printer called "pdf-optima" that will create 2 PDF files with different file sizes and quality.
Tested on Mint 17, this is a generic method that should work on many Linux distributions (at least Ubuntu, Debian, ...)

The printer driver is a shell script that dumps the print output in a postscript file, then runs ps2pdf to create 2 pdf files with "screen" and "prepress" quality.
One the PDF files are generated, a C binary program (owned by root with suid privileges) launches a post-processing python script with the privileges of the current logged user.
This python script launches a file chooser dialog in order to save the PDF files in the location and name given by the user and moves the PDF accordingly.

Sorry for the french comments that may be still stuffed in source files :D

Unzip the attached files in a temporary directory, then open a terminal and execute the following commands :

Code: Select all

sudo -i
(type your password)
cp /your/temp/dir/pdf-optima* /usr/lib/cups/backend/
cd /usr/lib/cups/backend
gcc pdf-optima-post.c -o pdf-optima-post
chmod 4755 pdf-optima-post
chmod a+x pdf-optima pdf-optima-post.py
After that, you must declare a new printer. Copy the code below ...

Code: Select all

<Printer pdf-optima>
Info pdf-optima
DeviceURI pdf-optima
PPDTimeStamp *
State Idle
Type 4
Accepting Yes
Shared Yes
ColorManaged Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy retry-job
</Printer>
... and paste it in the bottom of this file with this command

Code: Select all

sudo gedit /etc/cups/printers.conf
Then restart the printer daemon :

Code: Select all

sudo /etc/init.d/cups stop
sudo /etc/init.d/cups start
The new printer PDF-optima should be ready.

Do not hesitate to edit the pdf-optima shell script and pdf-optima-post.py if you want to change the french dialog title and get only one PDF quality.

Credits :
http://osdir.com/ml/printing.cups.devel ... 00007.html
http://forums.gentoo.org/viewtopic-p-5841020.html
Attachments
pdf-optima.zip
Source files for pdf-optima printer
(3.26 KiB) Downloaded 208 times
Last edited by iaselle on Thu Jul 10, 2014 12:03 pm, edited 2 times in total.

User avatar
PatH57
Level 13
Level 13
Posts: 4576
Joined: Tue Mar 25, 2014 12:11 pm
Location: here and there

Re: HowTo: create PDF printer with save as dialog + small fi

Post by PatH57 » Thu Jul 10, 2014 11:59 am

Hi iaselle,

an esay way is to follow tihs.
http://jonmifsud.com/blog/print-to-pdf- ... ntu-linux/
People disagree with me. I just ignore them.
(Linus Torvalds, regarding the use of C++ for the Linux kernel.)

Please Add [Solved] to the topic-title of your first post when appropriate so others know they might find a solution here.

iaselle
Level 1
Level 1
Posts: 7
Joined: Mon Jun 30, 2014 5:34 pm
Location: Toulouse, France

Re: HowTo: create PDF printer with save as dialog + small fi

Post by iaselle » Thu Jul 10, 2014 12:16 pm

Yes, but as I stated in this post, CUPS-PDF produces very large PDF files and has no dialog in order to choose the PDF file name and directory ... very annoying.

User avatar
PatH57
Level 13
Level 13
Posts: 4576
Joined: Tue Mar 25, 2014 12:11 pm
Location: here and there

Re: HowTo: create PDF printer with save as dialog + small fi

Post by PatH57 » Thu Jul 10, 2014 12:29 pm

Sorry,

jumped to conclusion
I checked again and by default print to file is there, so I select pdf and where I want to download plus the name.
Size is 99.7kb compared to 338.5kb using the pdf cups printer.
Is this was you are trying to do? It's installed as default on my Mint 13, 16 and 17.
Screenshot-Print.png
People disagree with me. I just ignore them.
(Linus Torvalds, regarding the use of C++ for the Linux kernel.)

Please Add [Solved] to the topic-title of your first post when appropriate so others know they might find a solution here.

altair4
Level 19
Level 19
Posts: 9186
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: create PDF printer with save as dialog + small fi

Post by altair4 » Thu Jul 10, 2014 12:51 pm

@iaselle, If I may make a modest suggestion.

If you want to post a HowTo it would be best to place it in the HowTo section: Tutorials / HowTo

Normal forum etiquette suggest that this will allow it's users to ask questions or tell you it doesn't work or thank you if it does but it should not encourage people to say there is a better way. The forum moderators don't enforce this rule as much as I would prefer but you have to start somewhere.

I have a HowTo that describes how to do XYZ in a particular way. I have another HowTo describing how to do XYZ in a completely different way. That's the nature of a HowTo.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.

iaselle
Level 1
Level 1
Posts: 7
Joined: Mon Jun 30, 2014 5:34 pm
Location: Toulouse, France

Re: HowTo: create PDF printer with save as dialog + small fi

Post by iaselle » Thu Jul 10, 2014 1:35 pm

The "print to file" is yet very efficient, but is not available with wine applications (such as Microsoft Office).


BTW : I tried to post in the "how to" forum, but the rules discourage it "Do not start a support topic here please. Before you post please read this"
Last edited by iaselle on Sun Jul 13, 2014 1:21 pm, edited 1 time in total.

altair4
Level 19
Level 19
Posts: 9186
Joined: Tue Feb 03, 2009 10:27 am

Re: HowTo: create PDF printer with save as dialog + small fi

Post by altair4 » Thu Jul 10, 2014 2:00 pm

iaselle wrote:I tried to post in the "how to" forum, but the rules discourage it "Do not start a support topic here please. Before you post please read this"
I think you misread the notice. You aren't asking for support. You're giving it. The notice is to make sure one doesn't start a new thread asking for help in the HowTo section of the forum.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.

Andy93585
Level 1
Level 1
Posts: 7
Joined: Mon Apr 20, 2015 6:11 pm

Re: HowTo: create PDF printer with save as dialog + small fi

Post by Andy93585 » Mon Apr 20, 2015 8:01 pm

@iaselle: Thank you very much for sharing this. Here is a slightly modified version, using a separate "printer" for each Ghostscript configuration. It outputs one document per print-out.

File changes compared to the original:
pdf-optima:
- created copies of this file (pdf-optima_default, pdf-optima_prepress, and other pdf-optima_*), one per used Ghostscript configuration (different image resolutions, grayscale, etc.)
- A more extensive document title sanitation, as such characters as e.g. "|<>" in a web page title prevent the GTK "Save as..." dialog starting up when printing from browser
- Temporary files will be removed after printing

pdf-optima-post.py
- Default directory changed to $USER/Documents
- Aligned output file selection dialog file types to what is used by the PDF viewer
- Made the output file name equal what was actually selected by user, to make the "file already exists" detection work always
Attachments
pdf-optima (Separate Printers).zip
Source files for pdf-optima printer
(20.19 KiB) Downloaded 161 times
Screenshot-Print.png

Andy93585
Level 1
Level 1
Posts: 7
Joined: Mon Apr 20, 2015 6:11 pm

Re: HowTo: create PDF printer with save as dialog + small files

Post by Andy93585 » Sun Aug 12, 2018 10:10 am

Updated:
- Replaced gksudo with sudo (the former has been removed from Ubuntu 18.04)
- Changed Python shebang to python3 (no impact currently, but as preparation for future deprecation of Python 2)
- Corrected access permissions of the resulting PDF file to be readable by all users
Attachments
pdf-optima (Separate Printers) v2.zip
(20.63 KiB) Downloaded 6 times

Post Reply

Return to “Software & Applications”