Linux Piping ( Convert -> Pdf2Ps -> Lp)

Linux piping ( convert - pdf2ps - lp)

convert file1.pdf file2.pdf - | pdf2ps - - | lp -s
should do the job.

You send the output of the convert command to psf2ps, which in turn feeds its output to lp.

Merge / convert multiple PDF files into one PDF

I'm sorry, I managed to find the answer myself using google and a bit of luck : )

For those interested;

I installed the pdftk (pdf toolkit) on our debian server, and using the following command I achieved desired output:

pdftk file1.pdf file2.pdf cat output output.pdf

OR

gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf file3.pdf ...

This in turn can be piped directly into pdf2ps.

linux print directly to network printer that IS NOT installed

Try this:

cat you_file.prn | netcat -w 1 printer_ip 9100

How to print bold and sized text in Bash?

For starters, don't use the raw ANSI escape sequences directly since it makes it hard to read and maintain. Use tput to produce the escape sequences for you.

There's a tool called aha that can convert ANSI escape sequences into HTML. You can probably install it using sudo apt-get install aha or sudo dnf install aha. If it's not available on your platform, you can download and compile it using the link.

You can then convert HTML to PDF using a tool called wkhtmltopdf. Install (or download and compile) that too if you don't have it already.

With these tools, you can use your ANSI escape sequences to produce a PDF and your printer is likely going to print that just fine. The sequence becomes:

(tput <commands>; ...) | aha | wkhtmltopdf - - | lp

The - - arguments to wkhtmltopdf makes it read from stdin and write to stdout

Put into an example:

#!/bin/bash

# force tput to use the ansi terminal capabilities
export TERM=ansi

# Margin settings
top=18
bottom=18
left=1.6
right=1.6
pagesize=A4

fontsize=30px

# convenience functions

function bold {
tput bold
echo -n "$@"
# bold can't be turned off by itself so this
# turns off all attributes
tput sgr0
}

function ul {
tput smul
echo -n "$@"
tput rmul
}

function rev {
# standout mode really, but reverse mode for ansi
tput smso
echo -n "$@"
tput rmso
}

# start a subshell to be able to pipe the output to aha
(
echo "Lets try to make $(bold this) bold."
echo "and $(ul this) is underlined."
echo "Here we use $(bold $(ul both)) decorators."
echo "This will be in $(rev reverse)."

# using tput to produce a color map
for fg_color in {0..7}; do
set_foreground=$(tput setaf $fg_color)
for bg_color in {0..7}; do
set_background=$(tput setab $bg_color)
echo -n $set_background$set_foreground
printf ' F:%s B:%s ' $fg_color $bg_color
done
echo $(tput sgr0)
done
) | aha | \
sed -E "s,^<pre>$,<div style=\"font-size:${fontsize}\"><pre>," | \
sed -E 's,^</pre>$,</pre></div>,' | \
wkhtmltopdf --page-size $pagesize -T $top -B $bottom -L $left -R $right - - | lp

This should produce something like this on paper:

Sample Image

Edit:
I made a pull request in aha to add a --style option that has now been approved and is included in aha version 0.5.1. As of this version you can remove the sed lines and tell aha which font-size you want directly.

Example:

   ...
) | aha --style 'font-size:1.875em' | \
wkhtmltopdf --page-size $pagesize -T $top -B $bottom -L $left -R $right - - | lp

Can I print html files (with images, css) from the command-line?

You could give html2ps a try, it is written in Perl, so I guess it wil run on any operating system that runs Perl. It does support CSS and images. It does not render as good as you may perhaps want.

To use in Debian/Ubuntu sudo aptitude install html2ps and then pipe the output to lpr to print:

html2ps \
http://stackoverflow.com/questions/286583 \
|lpr

Or pipe the output to ps2pdf to convert to a pdf file:

html2ps \
http://stackoverflow.com/questions/286583 \
|ps2pdf - stackoverflow.pdf


Related Topics



Leave a reply



Submit