One liner to convert small text string to PDF
I've been trying to find a way to create a simple PDF page from the terminal that contains only one string, for example, "Prelude".
Some background: I use pdfunite to join music charts together into a single PDF. Here's an example:
pdfunite Welcome.pdf Rooftops.pdf Announcements.pdf ChildrensPrayer.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
What I am trying to find is a way to create custom sheets in the final PDF all in one single command, similar to this:
pdfunite Welcome.pdf (enscript "Have a seat" - | ps2pdf - output.pdf) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
In essence, creating a PDF that contains text "Have a seat" on the fly and inserting it into the correct spot of the final document.
Is this possible?
command-line bash software-recommendation pdf text
add a comment |
I've been trying to find a way to create a simple PDF page from the terminal that contains only one string, for example, "Prelude".
Some background: I use pdfunite to join music charts together into a single PDF. Here's an example:
pdfunite Welcome.pdf Rooftops.pdf Announcements.pdf ChildrensPrayer.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
What I am trying to find is a way to create custom sheets in the final PDF all in one single command, similar to this:
pdfunite Welcome.pdf (enscript "Have a seat" - | ps2pdf - output.pdf) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
In essence, creating a PDF that contains text "Have a seat" on the fly and inserting it into the correct spot of the final document.
Is this possible?
command-line bash software-recommendation pdf text
add a comment |
I've been trying to find a way to create a simple PDF page from the terminal that contains only one string, for example, "Prelude".
Some background: I use pdfunite to join music charts together into a single PDF. Here's an example:
pdfunite Welcome.pdf Rooftops.pdf Announcements.pdf ChildrensPrayer.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
What I am trying to find is a way to create custom sheets in the final PDF all in one single command, similar to this:
pdfunite Welcome.pdf (enscript "Have a seat" - | ps2pdf - output.pdf) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
In essence, creating a PDF that contains text "Have a seat" on the fly and inserting it into the correct spot of the final document.
Is this possible?
command-line bash software-recommendation pdf text
I've been trying to find a way to create a simple PDF page from the terminal that contains only one string, for example, "Prelude".
Some background: I use pdfunite to join music charts together into a single PDF. Here's an example:
pdfunite Welcome.pdf Rooftops.pdf Announcements.pdf ChildrensPrayer.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
What I am trying to find is a way to create custom sheets in the final PDF all in one single command, similar to this:
pdfunite Welcome.pdf (enscript "Have a seat" - | ps2pdf - output.pdf) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
In essence, creating a PDF that contains text "Have a seat" on the fly and inserting it into the correct spot of the final document.
Is this possible?
command-line bash software-recommendation pdf text
command-line bash software-recommendation pdf text
edited Mar 21 '16 at 15:38
kos
25.8k871121
25.8k871121
asked Mar 21 '16 at 15:22
Jason SilverJason Silver
15810
15810
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Tl;dr
pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
If I understood correctly you were pretty close:
pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
The <<<"Have a seat" token in the enscript command will redirect enscript's standard input to the string and the -p - token will make the enscript command print to standard output;
Using <() instead of () will make the whole <() token be replaced with the file descriptor containing the standard output of the command running inside <() (AKA process substitution), using - instead of output.pdf will make ps2pdf print the PDF to standard output instead of to a file.
But the problem with this approach is that pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
% enscript <<<"foo" -p - | ps2pdf - foo.pdf
[ 1 page * 1 copy ] left in -
% gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -)
[ 1 page * 1 copy ] left in -
GPL Ghostscript 9.16 (2015-03-30)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Loading NimbusMon-Bol font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Bol... 4726404 3142423 2470576 1091522 3 done.
Loading NimbusMon-Reg font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Reg... 4759732 3269347 2490768 1100127 3 done.
%
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -) correctly chains foo.pdf and a document containing the word "bar" generated via the PostScript script generated by enscript <<<"bar" -p -.
Thanks! But no luck-- I think the issue may be in how I'm using enscript-- it gives some errors, like can't open input file 'have a seat', etc. Any thoughts?
– Jason Silver
Mar 21 '16 at 16:07
@JasonSilver Yes, there were problems also in your call toenscript, see the edit for clarifications:pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf.
– kos
Mar 21 '16 at 16:13
Still receiving an error:[ 1 page * 1 copy ] left in - Syntax Warning: May not be a PDF file (continuing anyway) Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't read xref table Syntax Error: Could not merge damaged documents ('/dev/fd/63')
– Jason Silver
Mar 21 '16 at 16:18
1
@JasonSilver I see, the problem is thatpdfunitetries to read from the file descriptor before it contains the document. Perhaps this can be solved with some Bash hackery, but since you haveghostscriptinstalled you could use a totally different approach, :gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf.
– kos
Mar 21 '16 at 16:44
1
@JasonSilver No problem. Anyway I suppose that'd be a matter of opinions, but I find to usegsto be more elegant than to usepdfunitein this case:gsprocesses the PostScript script directly (and hence it takes out the need of passing it tops2pdfbeforehand), so technically usinggsis one step less to achieve the same thing.
– kos
Mar 21 '16 at 18:39
|
show 10 more comments
I feel badly not accepting the answer suggested by @kos but I could not get it to work, and I preferred to continue with the simplicity of pdfunite. @kos helped me to understand enscript (THANKS!)
My final solution was to write a bash script to create the temporary PDF files, then string them together using pdfunite.
The command is issued as follows:
./charts.bash -o=output-filename.pdf ./AlmostThere.pdf ./Breathe.pdf -c="The Gospel According to Matthew" ./Doxology.pdf -c="Closing Prayer"
Here's the bash script (I'm a novice, go easy)
#!/bin/bash
CHARTS=()
DELETEAFTER=()
for i in "$@"
do
case $i in
-o=*|--output=*)
OUTPUT="${i#*=}"
;;
-c=*|--create=*)
NEWFILENAME="${i#*=}"
NEWFILENAME=${HOME}/Desktop/${NEWFILENAME//[[:space:]]/}.pdf
enscript <<<"${i#*=}" -p - --no-header --font=Courier25 --margins=20:20:200:0 | ps2pdf - $NEWFILENAME
CHARTS+=("$NEWFILENAME")
;;
*)
# unknown option
CHARTS+=("${i#*=}")
DELETEAFTER+=("$NEWFILENAME");
;;
esac
done
pdfuniteString=$(printf " %s" "${CHARTS[@]}")
pdfuniteString=${pdfuniteString:1}
wait
pdfunite $pdfuniteString ${HOME}/Desktop/${OUTPUT}
wait
for i in "${DELETEAFTER[@]}"
do
if [ -n "$i" ]; then
rm "$i"
fi
done
echo Complete
add a comment |
I am trying to create a small PDF file with page size just matching the text, ie a little label-sized PDF. I think that objective matches this question as stated. In one line, this can be done as follows:
echo "foobar" | enscript --no-header -p out.ps && ps2pdf out.ps && pdfcrop out.pdf out.pdf
This results in a little file that looks like this:

add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f748590%2fone-liner-to-convert-small-text-string-to-pdf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Tl;dr
pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
If I understood correctly you were pretty close:
pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
The <<<"Have a seat" token in the enscript command will redirect enscript's standard input to the string and the -p - token will make the enscript command print to standard output;
Using <() instead of () will make the whole <() token be replaced with the file descriptor containing the standard output of the command running inside <() (AKA process substitution), using - instead of output.pdf will make ps2pdf print the PDF to standard output instead of to a file.
But the problem with this approach is that pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
% enscript <<<"foo" -p - | ps2pdf - foo.pdf
[ 1 page * 1 copy ] left in -
% gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -)
[ 1 page * 1 copy ] left in -
GPL Ghostscript 9.16 (2015-03-30)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Loading NimbusMon-Bol font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Bol... 4726404 3142423 2470576 1091522 3 done.
Loading NimbusMon-Reg font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Reg... 4759732 3269347 2490768 1100127 3 done.
%
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -) correctly chains foo.pdf and a document containing the word "bar" generated via the PostScript script generated by enscript <<<"bar" -p -.
Thanks! But no luck-- I think the issue may be in how I'm using enscript-- it gives some errors, like can't open input file 'have a seat', etc. Any thoughts?
– Jason Silver
Mar 21 '16 at 16:07
@JasonSilver Yes, there were problems also in your call toenscript, see the edit for clarifications:pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf.
– kos
Mar 21 '16 at 16:13
Still receiving an error:[ 1 page * 1 copy ] left in - Syntax Warning: May not be a PDF file (continuing anyway) Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't read xref table Syntax Error: Could not merge damaged documents ('/dev/fd/63')
– Jason Silver
Mar 21 '16 at 16:18
1
@JasonSilver I see, the problem is thatpdfunitetries to read from the file descriptor before it contains the document. Perhaps this can be solved with some Bash hackery, but since you haveghostscriptinstalled you could use a totally different approach, :gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf.
– kos
Mar 21 '16 at 16:44
1
@JasonSilver No problem. Anyway I suppose that'd be a matter of opinions, but I find to usegsto be more elegant than to usepdfunitein this case:gsprocesses the PostScript script directly (and hence it takes out the need of passing it tops2pdfbeforehand), so technically usinggsis one step less to achieve the same thing.
– kos
Mar 21 '16 at 18:39
|
show 10 more comments
Tl;dr
pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
If I understood correctly you were pretty close:
pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
The <<<"Have a seat" token in the enscript command will redirect enscript's standard input to the string and the -p - token will make the enscript command print to standard output;
Using <() instead of () will make the whole <() token be replaced with the file descriptor containing the standard output of the command running inside <() (AKA process substitution), using - instead of output.pdf will make ps2pdf print the PDF to standard output instead of to a file.
But the problem with this approach is that pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
% enscript <<<"foo" -p - | ps2pdf - foo.pdf
[ 1 page * 1 copy ] left in -
% gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -)
[ 1 page * 1 copy ] left in -
GPL Ghostscript 9.16 (2015-03-30)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Loading NimbusMon-Bol font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Bol... 4726404 3142423 2470576 1091522 3 done.
Loading NimbusMon-Reg font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Reg... 4759732 3269347 2490768 1100127 3 done.
%
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -) correctly chains foo.pdf and a document containing the word "bar" generated via the PostScript script generated by enscript <<<"bar" -p -.
Thanks! But no luck-- I think the issue may be in how I'm using enscript-- it gives some errors, like can't open input file 'have a seat', etc. Any thoughts?
– Jason Silver
Mar 21 '16 at 16:07
@JasonSilver Yes, there were problems also in your call toenscript, see the edit for clarifications:pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf.
– kos
Mar 21 '16 at 16:13
Still receiving an error:[ 1 page * 1 copy ] left in - Syntax Warning: May not be a PDF file (continuing anyway) Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't read xref table Syntax Error: Could not merge damaged documents ('/dev/fd/63')
– Jason Silver
Mar 21 '16 at 16:18
1
@JasonSilver I see, the problem is thatpdfunitetries to read from the file descriptor before it contains the document. Perhaps this can be solved with some Bash hackery, but since you haveghostscriptinstalled you could use a totally different approach, :gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf.
– kos
Mar 21 '16 at 16:44
1
@JasonSilver No problem. Anyway I suppose that'd be a matter of opinions, but I find to usegsto be more elegant than to usepdfunitein this case:gsprocesses the PostScript script directly (and hence it takes out the need of passing it tops2pdfbeforehand), so technically usinggsis one step less to achieve the same thing.
– kos
Mar 21 '16 at 18:39
|
show 10 more comments
Tl;dr
pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
If I understood correctly you were pretty close:
pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
The <<<"Have a seat" token in the enscript command will redirect enscript's standard input to the string and the -p - token will make the enscript command print to standard output;
Using <() instead of () will make the whole <() token be replaced with the file descriptor containing the standard output of the command running inside <() (AKA process substitution), using - instead of output.pdf will make ps2pdf print the PDF to standard output instead of to a file.
But the problem with this approach is that pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
% enscript <<<"foo" -p - | ps2pdf - foo.pdf
[ 1 page * 1 copy ] left in -
% gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -)
[ 1 page * 1 copy ] left in -
GPL Ghostscript 9.16 (2015-03-30)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Loading NimbusMon-Bol font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Bol... 4726404 3142423 2470576 1091522 3 done.
Loading NimbusMon-Reg font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Reg... 4759732 3269347 2490768 1100127 3 done.
%
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -) correctly chains foo.pdf and a document containing the word "bar" generated via the PostScript script generated by enscript <<<"bar" -p -.
Tl;dr
pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
If I understood correctly you were pretty close:
pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf
The <<<"Have a seat" token in the enscript command will redirect enscript's standard input to the string and the -p - token will make the enscript command print to standard output;
Using <() instead of () will make the whole <() token be replaced with the file descriptor containing the standard output of the command running inside <() (AKA process substitution), using - instead of output.pdf will make ps2pdf print the PDF to standard output instead of to a file.
But the problem with this approach is that pdfunite may error out in case the file descriptor containing the standard output of the command running inside the command substitution is empty by the time it's read.
So you're better off using an alternative to pdfunite; since you have ghostscript installed you could use gs:
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf
% enscript <<<"foo" -p - | ps2pdf - foo.pdf
[ 1 page * 1 copy ] left in -
% gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -)
[ 1 page * 1 copy ] left in -
GPL Ghostscript 9.16 (2015-03-30)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
Loading NimbusMon-Bol font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Bol... 4726404 3142423 2470576 1091522 3 done.
Loading NimbusMon-Reg font from /usr/share/ghostscript/9.16/Resource/Font/NimbusMon-Reg... 4759732 3269347 2490768 1100127 3 done.
%
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=foobar.pdf foo.pdf <(enscript <<<"bar" -p -) correctly chains foo.pdf and a document containing the word "bar" generated via the PostScript script generated by enscript <<<"bar" -p -.
edited Mar 23 '16 at 7:07
answered Mar 21 '16 at 15:46
koskos
25.8k871121
25.8k871121
Thanks! But no luck-- I think the issue may be in how I'm using enscript-- it gives some errors, like can't open input file 'have a seat', etc. Any thoughts?
– Jason Silver
Mar 21 '16 at 16:07
@JasonSilver Yes, there were problems also in your call toenscript, see the edit for clarifications:pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf.
– kos
Mar 21 '16 at 16:13
Still receiving an error:[ 1 page * 1 copy ] left in - Syntax Warning: May not be a PDF file (continuing anyway) Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't read xref table Syntax Error: Could not merge damaged documents ('/dev/fd/63')
– Jason Silver
Mar 21 '16 at 16:18
1
@JasonSilver I see, the problem is thatpdfunitetries to read from the file descriptor before it contains the document. Perhaps this can be solved with some Bash hackery, but since you haveghostscriptinstalled you could use a totally different approach, :gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf.
– kos
Mar 21 '16 at 16:44
1
@JasonSilver No problem. Anyway I suppose that'd be a matter of opinions, but I find to usegsto be more elegant than to usepdfunitein this case:gsprocesses the PostScript script directly (and hence it takes out the need of passing it tops2pdfbeforehand), so technically usinggsis one step less to achieve the same thing.
– kos
Mar 21 '16 at 18:39
|
show 10 more comments
Thanks! But no luck-- I think the issue may be in how I'm using enscript-- it gives some errors, like can't open input file 'have a seat', etc. Any thoughts?
– Jason Silver
Mar 21 '16 at 16:07
@JasonSilver Yes, there were problems also in your call toenscript, see the edit for clarifications:pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf.
– kos
Mar 21 '16 at 16:13
Still receiving an error:[ 1 page * 1 copy ] left in - Syntax Warning: May not be a PDF file (continuing anyway) Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't read xref table Syntax Error: Could not merge damaged documents ('/dev/fd/63')
– Jason Silver
Mar 21 '16 at 16:18
1
@JasonSilver I see, the problem is thatpdfunitetries to read from the file descriptor before it contains the document. Perhaps this can be solved with some Bash hackery, but since you haveghostscriptinstalled you could use a totally different approach, :gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf.
– kos
Mar 21 '16 at 16:44
1
@JasonSilver No problem. Anyway I suppose that'd be a matter of opinions, but I find to usegsto be more elegant than to usepdfunitein this case:gsprocesses the PostScript script directly (and hence it takes out the need of passing it tops2pdfbeforehand), so technically usinggsis one step less to achieve the same thing.
– kos
Mar 21 '16 at 18:39
Thanks! But no luck-- I think the issue may be in how I'm using enscript-- it gives some errors, like can't open input file 'have a seat', etc. Any thoughts?
– Jason Silver
Mar 21 '16 at 16:07
Thanks! But no luck-- I think the issue may be in how I'm using enscript-- it gives some errors, like can't open input file 'have a seat', etc. Any thoughts?
– Jason Silver
Mar 21 '16 at 16:07
@JasonSilver Yes, there were problems also in your call to
enscript, see the edit for clarifications: pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf.– kos
Mar 21 '16 at 16:13
@JasonSilver Yes, there were problems also in your call to
enscript, see the edit for clarifications: pdfunite Welcome.pdf <(enscript <<<"Have a seat" -p - | ps2pdf - -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf ~/Desktop/2016-03-12.pdf.– kos
Mar 21 '16 at 16:13
Still receiving an error:
[ 1 page * 1 copy ] left in - Syntax Warning: May not be a PDF file (continuing anyway) Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't read xref table Syntax Error: Could not merge damaged documents ('/dev/fd/63')– Jason Silver
Mar 21 '16 at 16:18
Still receiving an error:
[ 1 page * 1 copy ] left in - Syntax Warning: May not be a PDF file (continuing anyway) Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't read xref table Syntax Error: Could not merge damaged documents ('/dev/fd/63')– Jason Silver
Mar 21 '16 at 16:18
1
1
@JasonSilver I see, the problem is that
pdfunite tries to read from the file descriptor before it contains the document. Perhaps this can be solved with some Bash hackery, but since you have ghostscript installed you could use a totally different approach, : gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf.– kos
Mar 21 '16 at 16:44
@JasonSilver I see, the problem is that
pdfunite tries to read from the file descriptor before it contains the document. Perhaps this can be solved with some Bash hackery, but since you have ghostscript installed you could use a totally different approach, : gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=~/Desktop/2016-03-12.pdf Welcome.pdf <(enscript <<<"echo foo" -p -) Rooftops.pdf Announcements.pdf ComeAliveDryBones.pdf Benediction.pdf Dismissal.pdf.– kos
Mar 21 '16 at 16:44
1
1
@JasonSilver No problem. Anyway I suppose that'd be a matter of opinions, but I find to use
gs to be more elegant than to use pdfunite in this case: gs processes the PostScript script directly (and hence it takes out the need of passing it to ps2pdf beforehand), so technically using gs is one step less to achieve the same thing.– kos
Mar 21 '16 at 18:39
@JasonSilver No problem. Anyway I suppose that'd be a matter of opinions, but I find to use
gs to be more elegant than to use pdfunite in this case: gs processes the PostScript script directly (and hence it takes out the need of passing it to ps2pdf beforehand), so technically using gs is one step less to achieve the same thing.– kos
Mar 21 '16 at 18:39
|
show 10 more comments
I feel badly not accepting the answer suggested by @kos but I could not get it to work, and I preferred to continue with the simplicity of pdfunite. @kos helped me to understand enscript (THANKS!)
My final solution was to write a bash script to create the temporary PDF files, then string them together using pdfunite.
The command is issued as follows:
./charts.bash -o=output-filename.pdf ./AlmostThere.pdf ./Breathe.pdf -c="The Gospel According to Matthew" ./Doxology.pdf -c="Closing Prayer"
Here's the bash script (I'm a novice, go easy)
#!/bin/bash
CHARTS=()
DELETEAFTER=()
for i in "$@"
do
case $i in
-o=*|--output=*)
OUTPUT="${i#*=}"
;;
-c=*|--create=*)
NEWFILENAME="${i#*=}"
NEWFILENAME=${HOME}/Desktop/${NEWFILENAME//[[:space:]]/}.pdf
enscript <<<"${i#*=}" -p - --no-header --font=Courier25 --margins=20:20:200:0 | ps2pdf - $NEWFILENAME
CHARTS+=("$NEWFILENAME")
;;
*)
# unknown option
CHARTS+=("${i#*=}")
DELETEAFTER+=("$NEWFILENAME");
;;
esac
done
pdfuniteString=$(printf " %s" "${CHARTS[@]}")
pdfuniteString=${pdfuniteString:1}
wait
pdfunite $pdfuniteString ${HOME}/Desktop/${OUTPUT}
wait
for i in "${DELETEAFTER[@]}"
do
if [ -n "$i" ]; then
rm "$i"
fi
done
echo Complete
add a comment |
I feel badly not accepting the answer suggested by @kos but I could not get it to work, and I preferred to continue with the simplicity of pdfunite. @kos helped me to understand enscript (THANKS!)
My final solution was to write a bash script to create the temporary PDF files, then string them together using pdfunite.
The command is issued as follows:
./charts.bash -o=output-filename.pdf ./AlmostThere.pdf ./Breathe.pdf -c="The Gospel According to Matthew" ./Doxology.pdf -c="Closing Prayer"
Here's the bash script (I'm a novice, go easy)
#!/bin/bash
CHARTS=()
DELETEAFTER=()
for i in "$@"
do
case $i in
-o=*|--output=*)
OUTPUT="${i#*=}"
;;
-c=*|--create=*)
NEWFILENAME="${i#*=}"
NEWFILENAME=${HOME}/Desktop/${NEWFILENAME//[[:space:]]/}.pdf
enscript <<<"${i#*=}" -p - --no-header --font=Courier25 --margins=20:20:200:0 | ps2pdf - $NEWFILENAME
CHARTS+=("$NEWFILENAME")
;;
*)
# unknown option
CHARTS+=("${i#*=}")
DELETEAFTER+=("$NEWFILENAME");
;;
esac
done
pdfuniteString=$(printf " %s" "${CHARTS[@]}")
pdfuniteString=${pdfuniteString:1}
wait
pdfunite $pdfuniteString ${HOME}/Desktop/${OUTPUT}
wait
for i in "${DELETEAFTER[@]}"
do
if [ -n "$i" ]; then
rm "$i"
fi
done
echo Complete
add a comment |
I feel badly not accepting the answer suggested by @kos but I could not get it to work, and I preferred to continue with the simplicity of pdfunite. @kos helped me to understand enscript (THANKS!)
My final solution was to write a bash script to create the temporary PDF files, then string them together using pdfunite.
The command is issued as follows:
./charts.bash -o=output-filename.pdf ./AlmostThere.pdf ./Breathe.pdf -c="The Gospel According to Matthew" ./Doxology.pdf -c="Closing Prayer"
Here's the bash script (I'm a novice, go easy)
#!/bin/bash
CHARTS=()
DELETEAFTER=()
for i in "$@"
do
case $i in
-o=*|--output=*)
OUTPUT="${i#*=}"
;;
-c=*|--create=*)
NEWFILENAME="${i#*=}"
NEWFILENAME=${HOME}/Desktop/${NEWFILENAME//[[:space:]]/}.pdf
enscript <<<"${i#*=}" -p - --no-header --font=Courier25 --margins=20:20:200:0 | ps2pdf - $NEWFILENAME
CHARTS+=("$NEWFILENAME")
;;
*)
# unknown option
CHARTS+=("${i#*=}")
DELETEAFTER+=("$NEWFILENAME");
;;
esac
done
pdfuniteString=$(printf " %s" "${CHARTS[@]}")
pdfuniteString=${pdfuniteString:1}
wait
pdfunite $pdfuniteString ${HOME}/Desktop/${OUTPUT}
wait
for i in "${DELETEAFTER[@]}"
do
if [ -n "$i" ]; then
rm "$i"
fi
done
echo Complete
I feel badly not accepting the answer suggested by @kos but I could not get it to work, and I preferred to continue with the simplicity of pdfunite. @kos helped me to understand enscript (THANKS!)
My final solution was to write a bash script to create the temporary PDF files, then string them together using pdfunite.
The command is issued as follows:
./charts.bash -o=output-filename.pdf ./AlmostThere.pdf ./Breathe.pdf -c="The Gospel According to Matthew" ./Doxology.pdf -c="Closing Prayer"
Here's the bash script (I'm a novice, go easy)
#!/bin/bash
CHARTS=()
DELETEAFTER=()
for i in "$@"
do
case $i in
-o=*|--output=*)
OUTPUT="${i#*=}"
;;
-c=*|--create=*)
NEWFILENAME="${i#*=}"
NEWFILENAME=${HOME}/Desktop/${NEWFILENAME//[[:space:]]/}.pdf
enscript <<<"${i#*=}" -p - --no-header --font=Courier25 --margins=20:20:200:0 | ps2pdf - $NEWFILENAME
CHARTS+=("$NEWFILENAME")
;;
*)
# unknown option
CHARTS+=("${i#*=}")
DELETEAFTER+=("$NEWFILENAME");
;;
esac
done
pdfuniteString=$(printf " %s" "${CHARTS[@]}")
pdfuniteString=${pdfuniteString:1}
wait
pdfunite $pdfuniteString ${HOME}/Desktop/${OUTPUT}
wait
for i in "${DELETEAFTER[@]}"
do
if [ -n "$i" ]; then
rm "$i"
fi
done
echo Complete
answered Mar 21 '16 at 19:18
Jason SilverJason Silver
15810
15810
add a comment |
add a comment |
I am trying to create a small PDF file with page size just matching the text, ie a little label-sized PDF. I think that objective matches this question as stated. In one line, this can be done as follows:
echo "foobar" | enscript --no-header -p out.ps && ps2pdf out.ps && pdfcrop out.pdf out.pdf
This results in a little file that looks like this:

add a comment |
I am trying to create a small PDF file with page size just matching the text, ie a little label-sized PDF. I think that objective matches this question as stated. In one line, this can be done as follows:
echo "foobar" | enscript --no-header -p out.ps && ps2pdf out.ps && pdfcrop out.pdf out.pdf
This results in a little file that looks like this:

add a comment |
I am trying to create a small PDF file with page size just matching the text, ie a little label-sized PDF. I think that objective matches this question as stated. In one line, this can be done as follows:
echo "foobar" | enscript --no-header -p out.ps && ps2pdf out.ps && pdfcrop out.pdf out.pdf
This results in a little file that looks like this:

I am trying to create a small PDF file with page size just matching the text, ie a little label-sized PDF. I think that objective matches this question as stated. In one line, this can be done as follows:
echo "foobar" | enscript --no-header -p out.ps && ps2pdf out.ps && pdfcrop out.pdf out.pdf
This results in a little file that looks like this:

answered Feb 6 at 14:34
CPBLCPBL
298510
298510
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f748590%2fone-liner-to-convert-small-text-string-to-pdf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown