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

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
iaselle

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

Post by iaselle »

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
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
PatH57

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

Post by PatH57 »

Hi iaselle,

an esay way is to follow tihs.
http://jonmifsud.com/blog/print-to-pdf- ... ntu-linux/
iaselle

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

Post by iaselle »

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.
PatH57

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

Post by PatH57 »

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
altair4
Level 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

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

Post by altair4 »

@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

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

Post by iaselle »

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 20
Level 20
Posts: 11419
Joined: Tue Feb 03, 2009 10:27 am

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

Post by altair4 »

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: 8
Joined: Mon Apr 20, 2015 6:11 pm

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

Post by Andy93585 »

@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
Andy93585
Level 1
Level 1
Posts: 8
Joined: Mon Apr 20, 2015 6:11 pm

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

Post by Andy93585 »

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
Andy93585
Level 1
Level 1
Posts: 8
Joined: Mon Apr 20, 2015 6:11 pm

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

Post by Andy93585 »

Minor update due to a compatibility issue with Ubuntu 22.10:
The used Gtk version had to be specified as Gtk3 ("3.0") in "pdf-optima-post.py" on Ubuntu 22.10, as otherwise Gtk4 is assumed. The script currently does not work with the latter, as, e.g., the members of FileChooserDialog class have changed (e.g. from STOCK_CANCEL to "_Cancel", etc. - see https://docs.gtk.org/gtk4/class.FileChooserDialog.html . Since that class is deprecated in Gtk4 anyway, and the scrip will have to be updated to use the GtkFileDialog in the future, which would require additional changes, the script was not updated for Gtk4. And according to https://blog.gtk.org/2020/12/16/gtk-4-0/ , Gtk3 will continue to be maintained for the foreseeable future. (Gtk2 has been dropped with introduction of Gtk4.) So that the script update for Gtk4 was left for a future date, when Gtk4 stabilizes.
Attachments
pdf-optima (Separate Printers) v3.zip
(21.49 KiB) Downloaded 10 times
Locked

Return to “Software & Applications”