LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Printing PDF letterhead via CUPS (https://www.linuxquestions.org/questions/linux-software-2/printing-pdf-letterhead-via-cups-699960/)

jetblackstar 01-26-2009 10:52 AM

Printing PDF letterhead via CUPS
 
I'm not sure i'm going about this the right way.

Basic reqeirement:
To be able to print a PDF or PostScript letterhead/overlay onto any given document printed through cups.
I am trying to elimnate the need for pre printed stationary.

I know PCL has inbuilt functionality for "Overlays" that would do the job, but given that CUPS works in Postscript I was hoping to avoid locking myself into using only PCL printers.

It also means you can create letterheads or form overlays with one of hundreds of different applications like OpenOffice, Scribus, etc. Or take a PDF direct from a graphic artist and use that. And any application that can print to CUPS can use them.

Any pointers would be much apreciated. Including completly different Linux technologys or methods.

Thanks
-Jet

XavierP 01-26-2009 11:36 AM

Could you not create a template in, say OO.o, and use that (it would have the logo and so on already set up. Then convert the document to pdf and then print it?

jetblackstar 01-26-2009 12:41 PM

That would give me Letter heads from anything I made in OpenOffice, True.
But I was hoping to be able to get the letterheads printed on other applications too.
Like third party apps that print invoices, as well as for writing letters.

Thanks anyway.

I've just found the PSUtils programs. Might be able to get them to combine two Postscript documents on top of each other. Will post any solutions back here.

jetblackstar 01-27-2009 06:30 AM

Ok, have tried two toolkits with a little better success. But nothing that will actually work.
Both are just command line at the moment, they could later be built into a filter for CUPS (God knows exactly how i'll actually do that)

psutils (ps to ps, etc):
This one is messy, but almost works. pstops allows you to merge postscript pages in the same document onto one page. So:
- Merge header onto top of document (with ghostscript in pdf because doing it in postscript screws up, then convert back to postscript :s )
- Get pstops to merge page 0 onto page 1. Fine for the first page, but the pstops spec "2:0+1" (A short regex like language for instructing pstops what to do) I wrote means it will merge every other page together. Not only can I not get the header on anything but page 1, but it screws up pages 3-4, 4-5 etc.

Unless I blow the doc apart and stack a copy of the header inbetween each page, this wont work.

So failed.

pdftk:
This seemed to work much better, except in terms of getting it back to Postscript for Cups to use. Got closer to being a filter.
- Convert incoming stdinput into PDF
- Pipe into pdftk with the following
pdftk - background testBanner.pdf output -
(The -'s are for using stdin and stdout, check man if you want files)
- Pipe out to pdf2ps to get back to Postscript for CUPS.

The resulting PDF is great at stage 2, but the resulting Postscript file at the end of stage 3 is buggered. The data is messed up and the pages are teenyly short.


So, help =/
With what is meant to be a paperless office how is printing a header via CUPS so hard?!
-Jet

jetblackstar 01-27-2009 10:41 AM

Ok, ive got the second way working (pdftk). Turns out pdftops doesnt like pipes. So i've written up a script (That uses a temp file) that could potentially be used as a filter.

It sucks in PostScript and adds a parameterized PDF banner, adds that to each page, and spits out postscript (using stdin and stdout). Its a bit ugly that it has to make it into PDF first, work with it, then convert it back. But unless someone writes a util to merge a separate PS file to every page on an existing PS document, then i have to use pdftk.

Anyone know about CUPS filters? Ive vaguely read something about having to use/set mime types. Sounds scary.

chr00ted 02-19-2009 01:00 PM

Printing PDF letterhead via CUPS
 
Jetblackstar, would you mind posting your pdftk script please?

jetblackstar 02-20-2009 06:11 AM

2 Attachment(s)
Hah, sry completely forgot about finishing this thread.
I Am my own worst nightmare, forum problem unresolver person. :D

I'm in the middle of tax returns right now, so this is a rushed copy paste, slap GPL on job. But apparently i left the script in mildly acceptable condition; Script and GPL attached.
ps Forum software wouldn't let me upload .sh so it's a .txt. Just rename when you've downloaded.

If anyone can come up with a full cups integration please send me a copy back.

Hope this helps.
-Jet

ceekoe 03-29-2009 02:50 PM

Hello,
I would be interested in a cups integration as well.
Are the "-"'s only placeholders (so have I to change them) or the common way for using pipes in linux? And what is the "cat" command concretely doing?

Thank you
-ceekoe

jetblackstar 04-02-2009 12:55 PM

The "-"'s are the syntax of the various commands to represent stdin or stdout as the source or destination of the input/output where doing this isn't the default behavior. The "-" actually sits in place of the filename. In theory all of the commands should pipe in and out of each other like this, but i found one of the commands didn't like doing this. So i had to dump out to a temporary file and then cat it back into the next one.
Oh and the lonely cat command will be piping stdin into the first pdftk routine. IE its sucking up input for me and spewing it where i want.

No alteration of the commands is necessary, the only thing you need to alter in the script is the location of your header pdf. (Should have this as a command line param, but didn't get to do that).

It should be usable by just outputting your postscript to my script via stdin and the result will be spewed as output on stdout.

This can be done at command line with
Code:

  cat yourpostscript.ps | pdfheader.sh > destinationfile.ps
For the life of me i forget what i called the script so replace "pdfheader.sh" with the real name ;)

While this is ready programatically to be a CUPS filter, i never quite got into how the hell you configure CUPS to actually use a custom filter. Docs were a pita. So never got a resolution. Still its something I'd still find useful so will look into it again.
If anyone has created CUPS filters please post here or PM me.

Sorry the uploaded is suck a hack.
-Jet

ceekoe 04-05-2009 06:40 AM

Hello Jet,
thank you a lot for your concise explanation of the commands. Since I haven't much practise in writing shell scripts, your post took me far further.
I have read a lot on the cups-archtecture and have an idea how I might have to integrate it as a kind of own "mime-type" with the corresponding convertation. If I'm successful I'm will post a reply.

Kind Regards
ceekoe

ceekoe 04-05-2009 12:53 PM

Hello Jet,
good news. I was able to integrate the pdftk-toolkit into cups after several hour of trying and reading the CUPS Software Programmers Manual. If you are interested I can send the script to you. I developed and tried it on Debian Etch.

ceekoe

jetblackstar 04-06-2009 09:10 AM

Wahoo
 
Absolutely fantastic! :D
I'd already spent many hours reading the CUPS programmers documentation but obviously didn't have the same sticking power you did.
Well done!

I will PM you my email address.
Unless, for the benefit of others following this you would be willing to post it here as an attachment. Your call, its your work.

Well done again!
-Jet

EricPH 05-15-2009 09:31 AM

Quote:

Originally Posted by ceekoe (Post 3499252)
Hello Jet,
good news. I was able to integrate the pdftk-toolkit into cups after several hour of trying and reading the CUPS Software Programmers Manual. If you are interested I can send the script to you. I developed and tried it on Debian Etch.

ceekoe

Too bad that you haven't post your script...

jetblackstar 05-15-2009 11:05 AM

I havent had a chance to even try ceekoe's CUPS integration, or in fact help him with an other issue he was asking me about.
But I'm sure if you ask nicely he will email his scripts to you or post here if he is happy to.
Since it is not my code I'm not happy posting it. That is entirely up to Ceekoe.

-Jet

chr00ted 05-18-2009 02:17 PM

I found another solution thanks to my local linux user group: FLUX (flux.org). Member Kwan Lowe sent me the following:

I have done a similar thing to generate some automated PDFs. I used m4
and tex to do it...

--Example Report--
\documentclass[a4paper,10pt]{report}
\usepackage{graphicx}
\usepackage{eso-pic}

% Title Page
\title{TPS Report}
\author{Bob}

\begin{document}
\maketitle

\begin{abstract}
This is the TPS report to be submitted in triplicate to the three bosses.
\end{abstract}

\begin{center}
\includegraphics[width=120mm,bb=0 0 808 660]{Diagram1.png}
\end{center}

\begin{verbatim}
NEWS
The quick brown fox jumped over the lazy dogs.

\end{verbatim}
\end{document}

--End TPS Report--

You can create an m4 template from the above, then just use it as a
wrapper to your report. You may need to escape certain sequences in
the report text. If so, pipe it through sed to escape symbols like @,
for example.

Once complete you can run it through pdflatex to generate a PDF file.


All times are GMT -5. The time now is 08:08 AM.