I have a Bash function to display man pages rendered as postscript, in a PDF:
function psman () {
man -t "$@" | ps2pdf - /tmp/manpage.pdf
evince /tmp/manpage.pdf
}
(Update: I stripped out peripheral complications like dynamically generating the temp file name, and using 'nohup')
This works fine. For a screenshot of it in use, see https://www.tartley.com/postscript-formatted-man-pages.
For my own edification, I tried to implement it without using tempfiles. For example, using process substitution:
$ evince <(man -t ls | ps2pdf - -)
This doesn't work. Evince displays an error in its GUI:
Unable to open document "file:///dev/fd/63".
PDF document is damaged
Why? How can I generate and view the PDF without generating any intermediate files?
The error message above is different than the messages evince shows for missing or empty files, so it's not simply that.
Update: To get more info, I tried replacing 'evince' with 'ls':
$ ls -l <(man -t ls | ps2pdf - -)
lr-x------. 1 jhartley jhartley 64 Aug 23 08:59 /dev/fd/63 -> pipe:[196475]
where dircolors is coloring:
/dev/fd/63
as 'ORPHAN' (a symbolic link that points to a nonexistent file), andpipe:[196475]
as 'MISSING' (a nonexistent file pointed to by a symbolic link)
So maybe evince is just being given a link pointing to a file that doesn't exist? To mimic this, I created a symbolic link that points to a nonexistent file, then opened it with 'evince'. But instead of the 'PDF is damaged' message above, this gives me "No such file or directory."
Update: I think the ORPHAN/MISSING filetypes are a red herring. I see the same ORPHAN/MISSING symlink when doing a very simple process substitution:
$ ls -l <( echo 123 )
and using the same man|ps2pdt
pipeline works fine when the process substitution is fed to diff
:
$ diff <(man -t ls | ps2pdf - - | tr "\0" "0") <(man -t ls | ps2pdf - - | tr "\0" "0")
248c248
< /ID [<95A81B38FAE8E6FE3C899586A1DEE861><95A81B38FAE8E6FE3C899586A1DEE861>]
---
> /ID [<2F9164BD9265C8540A4A8E7068076344><2F9164BD9265C8540A4A8E7068076344>]
(Here I added 'tr' to the pipelines to eliminate null/zero characters in the pdf output, so that diff would treat the files as textual instead of binary.)
So, in summary, I've no idea why I get the "PDF is damaged" error above. My goal, other than understanding, is to view the generated PDF without generating any files along the way.
evince <( cat man-ls.pdf )
opens without errors, displaying 4 pages (the correct number), but all the pages are blank. Like it's partly read the file successfully, but then failed at some point.evince <( cat test.pdf )
to work. It responds "Unable to open document file:///dev/fd/63"mupdf
is also failing.