Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple files in one print job not supported #29

Closed
michaelweghorn opened this issue Jul 3, 2015 · 7 comments
Closed

Multiple files in one print job not supported #29

michaelweghorn opened this issue Jul 3, 2015 · 7 comments

Comments

@michaelweghorn
Copy link

Currently, Boomaga does not support sending multiple files in one print job. Only the first file of the print job is taken into account by Boomaga.

Example command for printing multiple files in one print job on the command line:
lp -d Boomaga first.pdf second.pdf

Only "first.pdf" is taken into account by Boomaga (is added to the "Jobs"), not "second.pdf".

It would be great if Boomaga could support sending several files in one print job.

I have tested this with Debian Jessie and a current build of Boomaga's master branch (commit a3e0347).

In the real use case, the files are not sent to the printer on the command line but created by LibreOffice's mail merge (form letter) feature and sent to the printer by LibreOffice as one print job.

@SokoloffA
Copy link
Member

Sorry for silence. I am on vacation

пятница, 3 июля 2015 г. пользователь michaelweghorn написал:

Currently, Boomaga does not support sending multiple files in one print
job. Only the first file of the print job is taken into account by Boomaga.

Example command for printing multiple files in one print job on the
command line:
lp -d Boomaga first.pdf second.pdf

Only "first.pdf" is taken into account by Boomaga (is added to the
"Jobs"), not "second.pdf".

It would be great if Boomaga could support sending several files in one
print job.

I have tested this with Debian Jessie and a current build of Boomaga's
master branch (commit a3e0347
a3e0347
).

In the real use case, the files are not sent to the printer on the command
line but created by LibreOffice's mail merge (form letter) feature and sent
to the printer by LibreOffice as one print job.


Reply to this email directly or view it on GitHub
#29.

Best regards,
Alexander.

@SokoloffA
Copy link
Member

I use a (http://www.cups.org/documentation.php/doc-2.1/api-filter.html)[file backend] for CUPS (only this backend does not require a daemon). Unfortunately, the file backend does not support multiple files in a single job. So I can't do it just now.
I opened a bug, I hope they will add this feature https://www.cups.org/str.php?L4710

@michaelweghorn
Copy link
Author

I further examined this.
It seems like the backend actually does get all of the files, but as multiple PDF files simply concatenated each after the other (not as a real PDF file with two pages).
You can see that when directly using the "file" backend to save to a file that which would otherwise be passed to the backend.

To do so:

  • Create two input files: echo first > /tmp/first; echo second > /tmp/second
  • Set FileDevice Yes in /etc/cups/cups-files.conf
  • Set up a print queue that simply writes everything it gets into a file: sudo lpadmin -p tofile-printer -v file:/var/spool/cups/tofile-printer -E -P boomaga.ppd
  • Print both files in a single print job: lp -d tofile-printer /tmp/first /tmp/second

The file /var/spool/cups/tofile-printer is created. When opening it with a text editor (e.g. vim), one can see that it consists of two single PDF file, whose content is simply concatenated:

%PDF-1.3
[further content of first PDF file]
%%EOF
%PDF-1.3
[further content of second PDF file]
%%EOF

If the backend handles this appropriately, it should be possible to extract the single PDF files again.
I wrote small test CUPS backend in Python to demonstrate what I mean s. attachment). This backend first extracts the single PDF files and then uses pdftk to create a single PDF file out of them.
In order to run it, the tool pdftk needs to be installed. (On Debian jessie, it is contained in the package pdftk).

To use it:

  • replace the value of BASEPATH at the top of the script with a path to a directory that CUPS may write to; possibly create it beforehand
    (the value currently given should probably work; depending on the system, something in $HOME or /tmp may also work)
  • run the following commands:
sudo cp multipdf.py /usr/lib/cups/backend/multipdf # creates the CUPS backend
sudo chmod 700 /usr/lib/cups/backend/multipdf
echo first > /tmp/first; echo second > /tmp/second
sudo lpadmin -p test-multi-input -v multipdf:/ -E -P boomaga.ppd # set up print queue
lp -d test-multi-input /tmp/first /tmp/second # print files

This creates the file /var/spool/cups/result.pdf. When opening the file, one can see that it is a PDF file with two pages, namely the content of the two input files.

I think that by doing a more or less similar thing in boomaga, it might also be possible to handle multiple input files there (extract the single files, add them).

@michaelweghorn
Copy link
Author

Here is the test backend. I renamed the file to "multipdf.txt" because uploading Python scripts with the correct file suffix ".py" does not seem to be allowed/supported by GitHub.
multipdf.txt

@SokoloffA
Copy link
Member

You are right. I've long wanted to rewrite the backend to C++, it looks lake a good occasion.

SokoloffA added a commit that referenced this issue Mar 5, 2016
@SokoloffA
Copy link
Member

I wrote new CPP backend. Now command
for i in {1..9}; do echo "Document # $i" > $i.txt; done lp *.txt works fine
You can test it from cpp_backend branch (git clone https://github.com/Boomaga/boomaga.git --branch cpp_backend)

But pay attention that lp first.pdf second.pdf does not work, CUPS transfer only the first document. It seems that concatenating is a hack or bug, and it may stop working in the future.
Maybe will be better for you to write wrapper for lp command ?

@michaelweghorn
Copy link
Author

Thank you so much for the implementation!

I can reproduce the behaviour you described on Debian jessie.

The problem with the PDF files seems to be a bug in CUPS.
Further details are described in the following bug reports (which refer to each other):

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=793989
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=771259
https://www.cups.org/str.php?L4430

My comment in the first mentioned bug (Debian #793989) is also true for the problem with the PDF files you described:

"I just rebuilt the CUPS packages
currently in Jessie (version 1.7.5-11+deb8u1) with the patch attached to
#771259 and the problem does not occur with this modified version."

The upstream bug for CUPS (last hyperlink) has not yet been resolved.

Therefore, this needs to be resolved in CUPS and nothing is to be done on the side of Boomaga.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants