Differences between revisions 9 and 14 (spanning 5 versions)
Revision 9 as of 2017-11-18 14:03:51
Size: 11724
Editor: Brian Potkin
Comment: Jessie-->jessie. Stretch-->stretch. Hoffman-->Hoffmann. Added "See Also". Punctuation. Syntax. Spelling. Layout. Links added. Basically, a general cleanup.
Revision 14 as of 2022-02-15 22:06:15
Size: 8393
Editor: Brian Potkin
Comment: rjessie is unsupported. Removing references to it also simplifies the page. Some revision and rewriting. Testing.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from ThetexttopdfFilter
Line 5: Line 6:
Getting the most out of the texttopdf filter used with CUPS on jessie and stretch. Getting the most out of the texttopdf filter used with CUPS on Debian 9 (stretch) and later.
Line 16: Line 17:
Font selection is taken care of within the [[DebianPkg:fontconfig|fontconfig]] framework (documented in [[DebianMan:fonts-conf|fonts-conf]]) in conjunction with ''pdf.utf-8'', which is found in ''/usr/share/cups/charsets'' and installed by the [[DebianPkg:cups-filters|cups-filters]] package. By default ''pdf.utf-8'' is symlinked to ''pdf.utf-8.simple'', whose essential content on Debian 8.x (jessie) is

{{{
charset utf8
0000 04FF ltor single FreeMono FreeMono:bold FreeMono:oblique FreeMono:bold:oblique
0500 05FF rtol single FreeMono
}}}

Note that the font names are not file names but selectors which enable fontconfig to choose a monopaced font. The font used for printing will ''always'' be [[DebianPkg:fonts-freefont|FreeMono]] if fontconfig finds it on the system, but otherwise it will conduct a search based on the generic font group which Freemono belongs to. !FreeMono belongs to the monospace group of fonts so fontconfig will search for other fonts that are registered in this group and use the first match it finds.

On Debian 9.x (stretch) ''pdf.utf-8.simple'' [[DebianBug:788048|has been changed]] to contain
Font selection is taken care of within the [[DebianPkg:fontconfig|fontconfig]] framework, documented in [[DebianMan:fonts-conf|fonts-conf]], in conjunction with ''pdf.utf-8'', which is found in ''/usr/share/cups/charsets'' and installed by the [[DebianPkg:cups-filters|cups-filters]] package. By default, ''pdf.utf-8'' is symlinked to ''pdf.utf-8.simple'', whose essential content is
Line 34: Line 25:
''monospace'' is still a selector for fontconfig but the hard-coded request for !FreeMono is changed to the generic monospace alias. fontconfig returns what it considers to be the best suitable monospaced font that is available on the system. This might be !FreeMono or [[DebianPkg:fonts-dejavu-core|DejaVuSansMono]] or any other monospaced font. A preference for a particular font can be configured on a [[#system|per-system]] basis by altering which file ''pdf.utf-8'' links to (jessie and stretch) or by means of a fontconfig configuration file (stretch only). A user with a font preference is [[#user|also catered for]]. Note that ''monospace'' is a selector that enables fontconfig to choose a monopaced font. fontconfig will search for fonts that are registered in the ''monospace'' group and return what it considers to be the best suitable candidate that is available on the system. This could be [[DebianPkg:fonts-freefont-ttf|FreeMono]] or [[DebianPkg:fonts-dejavu-core|DejaVuSansMono]] or any other monospaced font.

A preference for a particular font can be configured on a [[#system|per-system]] basis by means of a fontconfig configuration file. A user with a font preference is [[#user|also catered for]].
Line 39: Line 32:
The cups-filters package has [[DebianBug:735223|no dependency on a specific font package]] but it pulls in [[DebianPkg:fontconfig-config|fontconfig-config]] (via [[DebianPkg:libfontconfig1|libfontconfig1]]) because it depends on it. In its turn fontconfig-config has the dependency The cups-filters package hasn't [[DebianBug:735223|any dependency on a specific font package]] but it pulls in [[DebianPkg:fontconfig-config|fontconfig-config]] (via [[DebianPkg:libfontconfig1|libfontconfig1]]) because it depends on it. In its turn fontconfig-config has a dependency beginning
Line 42: Line 35:
fonts-dejavu-core | ttf-bitstream-vera | fonts-liberation | fonts-freefont fonts-dejavu-core | ttf-bitstream-vera | fonts-liberation | fonts-freefont...
Line 45: Line 38:
All these four packages have a monospaced font. Consequently, there will always be one monospaced font on the system This will normally lead to the first in the list being installed. fonts-dejavu-core has a monospaced font. Consequently, there will always be one monospaced font on the system.
Line 47: Line 40:

 * '''jessie.'''
As ''pdf.utf-8.simple'' is written on jessie, fontconfig will always select [[DebianPkg:fonts-freefont-ttf|FreeMono]] if this font is installed. It will only fall back to one of [[DebianPkg:fonts-dejavu-core|DejaVuSansMono]] or [[DebianPkg:fonts-liberation|LiberationMono]] or [[DebianPkg:ttf-bitstream-vera|VeraMono]] if !FreeMono is not available. To specify exactly what font to use, the file ''pdf.utf-8.defaultfont'' can be created to replace ''pdf.utf-8.simple'' and linked to ''pdf.utf-8''. With the [[DebianPkg:fonts-linuxlibertine|fonts-linuxlibertine]] package it would be sufficient to have ''pdf.utf-8.defaultfont'' as

{{{
charset utf8
0000 04FF ltor single /usr/share/fonts/opentype/linux-libertine/LinLibertine_M.otf
}}}

This bypasses fontconfig and also works on stretch.

Substituting the stretch ''pdf.utf-8.simple'' for the jessie version is also something to consider.

 * '''stretch.'''
The preferred way of using a chosen ''textttopdf_font'' on stretch would be to create ''/etc/fonts/local.conf'' with the contents
The preferred way of using a chosen ''textttopdf_font'' would be to create ''/etc/fonts/local.conf'' with the contents
Line 77: Line 56:
Possibilities for ''textttopdf_font'' are ''Liberation Mono'', ''!FreeMono'', ''Moto Mono'' or ''Inconsolata''.
Line 80: Line 61:
Filters are always run as a non-privileged user, typically ''lp'', with no connection to the user's desktop. On jessie and stretch a user would have to pre-process the text file to produce a PDF which is then sent to the printing system. The PDF would have the chosen font embedded in it. Filters such as texttopdf are always run by the printing system as a non-privileged user, typically ''lp'', with no connection to the user's desktop. This implies that printing via cups-filters is not an option and that a user would have to execute texttopdf under user privileges to gain control of font selection.
Line 82: Line 63:
 * '''jessie.'''
Create the directory ''$HOME/charsets'' and the file ''pdf.utf-8'' (examples below). Put ''pdf.utf-8'' into ''$HOME/charsets''. Convert the text file to a PDF with
The conversion of a text file to a PDF is done with with
Line 86: Line 66:
CUPS_DATADIR=$HOME CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 < text_file> > out.pdf CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 < <text_file> > out.pdf
Line 89: Line 69:
''$CUPS_DATADIR'' would normally be ''/usr/share/cups/'' but texttopdf will now look for the character set in a charsets directory in the home directory. Here are two example ''$HOME/charsets/pdf.utf-8'' files which will override the hard-coded !FreeMono font selection: ''CHARSET=utf-8'' tells the filter to consult [[#selection|/usr/share/cups/charsets/pdf.utf-8]], where it will find the request for a ''monospace'' font.
Line 91: Line 71:
{{{
charset utf8
0000 04FF ltor single /usr/share/fonts/truetype/noto/NotoMono-Regular.ttf
fontconfig will now be capable of using what a user wants from the ''monospace'' selector when the xml snippet [[#snippet|above]] is put into ''$HOME/.config/fontconfig/fonts.conf''. The user's ''fonts.conf'' will take precedence over the system's ''/etc/fonts/local.conf'' because texttopdf is being run by an ordinary user.
Line 95: Line 73:
charset utf8
0000 04FF ltor single LiberationMono LiberationMono:bold LiberationMono:oblique LiberationMono:bold:oblique
}}}
The two-step production of a PDF and sending it to the printing system can be automated with [[CUPSTea4CUPS#Text to PDF with a Selected Font|Tea4CUPS]]
Line 99: Line 75:
 * '''stretch.'''
Use the xml snippet [[#snippet|above]] in ''$HOME/.config/fontconfig/fonts.conf''. The user's ''fonts.conf'' will take precedence over the system's ''/etc/fonts/local.conf'' because texttopdf is being run by an ordinary user. Produce a PDF with

{{{
CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 < text_file> > out.pdf
}}}

The two-step production of a PDF and sending it to the printing system can be automated with [[Tea4CUPS#Text to PDF with a Selected Font|Tea4CUPS]]

<<Anchor(case)>>
<<Anchor(freemono)>>
Line 113: Line 80:
[[http://www.gnu.org/software/freefont/|GNU FreeMono]] has very good coverage of glyphs and caters for characters from many [[WikiPedia:Unicode_blocks|Unicode blocks]]. It can be compared with other monospaced fonts by [[#system|altering the system font]] and producing and viewing a PDF of
[[http://www.cl.cam.ac.uk/~mgk25/ucs/examples/|UTF-8-demo.txt]] using [[ThecupsfilterUtility|cupsfilter:]]
[[http://www.gnu.org/software/freefont/|GNU FreeMono]] has veryfont good coverage of glyphs and caters for characters from many [[WikiPedia:Unicode_blocks|Unicode blocks]]. It can be compared with other monospaced fonts by altering the [[#system| the system]] or [[#user|user-chosen]] font and producing and viewing a PDF of
[[http://www.cl.cam.ac.uk/~mgk25/ucs/examples/|UTF-8-demo.txt]] using (respectively) [[ThecupsfilterUtility|cupsfilter]] or texttopdf:
Line 119: Line 86:
CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 UTF-8-demo.txt > out.pdf
Line 131: Line 99:
<<Anchor(difference)>>
=== A Difference Between TrueType and OpenType Fonts When Printing ===

Install [[DebianPkg:fonts-freefont-ttf|fonts-freefont-ttf]] and convert a text file to a PDF with [[DebianMan:cupsfilter|cupsfilter.]] The outputs below were obtained from a jessie machine with a default installation.

{{{
/usr/sbin/cupsfilter /etc/services > services.pdf
}}}

Find the size of services.pdf and run [[DebianMan:pdffonts|pdffonts]] to analyse the fonts it uses:

{{{
brian@jessie:~$ ls -l services.pdf
-rw-r--r-- 1 brian brian 239047 Jun 9 16:35 services.pdf

brian@jessie:~$ pdffonts services.pdf
name type encoding emb sub uni object ID
--------------- ------------ ---------- ---------------------
SHXZNP+FreeMono CID TrueType Identity-H yes yes no 41 0
}}}

Remove fonts-freefont-ttf, replace it with [[DebianPkg:fonts-freefont-otf|fonts-freefont-otf]] and repeat.

{{{
brian@jessie:~$ ls -l services.pdf
-rw-r--r-- 1 brian brian 755004 Jun 9 16:23 services.pdf

brian@jessie:~$ pdffonts services.pdf
name type encoding emb sub uni object ID
----------------------- ----------- ---------- ---------------------
FreeMonoBold-Identity-H CID Type 0C Identity-H yes no no 40 0
FreeMono-Identity-H CID Type 0C Identity-H yes no no 45 0
}}}

The second file has the fonts embedded but not subset. In other words, the complete font has been included in the file produced by texttopdf. This results in a much larger file to be sent to the printer and might result in a longer printing time. This is not necessarily a problem but it is as well to be aware that using OTF is not yet equivalent to using TTF for the monospaced font.
Line 170: Line 102:
The primary purpose of cups-filters is to process files (in conjunction with CUPS) to produce an end product of toner or ink being put on a medium such as paper. However, it didn't take long for people to realise the CUPS+cupsfilters combination gave a way of capturing a PDF file without sending it to a printer. This opens up a way of archiving text files and scripting batch production of PDFs from them using something which is probably on the system already. The primary purpose of [[PrintingGlossaryandIndex#cupsfilters|cups-filters]] is to process files (in conjunction with [[PrintingGlossaryandIndex#cups|CUPS]]) to produce an end product of toner or ink being put on a medium such as paper. However, it didn't take long for people to realise the CUPS+cupsfilters combination gave a way of capturing a PDF file without sending it to a printer. This opens up a way of archiving text files and scripting batch production of PDFs from them using something that is probably on the system already.
Line 172: Line 104:
The command to use has been [[#difference|given earlier]]. Please look again at
both pdffonts outputs in that section and note that ''uni'' is ''no''. This means there is no !ToUnicode map in the PDF file and this in turn implies the text in the PDF is not searchable or capable of being copied. Should this does not matter to you then you have a decent method to produce a PDF from a text file with
Either of the two commands [[#freemono|given previously]] may be used to produce a PDF. An issue that may arise is that the PDFs do not have searchable or extractable test. This is a consequence of the design of the texttopdf filter. If it matters, the situation may be rectified with some post-processing.

 * With the [[#system|system]] text font:
Line 176: Line 109:
/usr/sbin/cupsfilter input.txt > out.pdf /usr/sbin/cupsfilter <input.txt> | pdftocairo -pdf - out.pdf
Line 179: Line 112:
Should a searchable PDF matter  * With a [[#user|user's]] text font:
Line 182: Line 115:
/usr/lib/cups/filter/texttopdf 1 1 1 1 1 input.txt > out.pdf CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 <input.txt> | pdftocairo -pdf - out.pdf
Line 185: Line 118:
can be resorted to; out.pdf is searchable and copiable. However, pdffonts shows there are no fonts embedded in the PDF, so printing it would have to rely on whatever fonts the printer provides. The PDF should be viewable on any machine because the font is courier. You may want to look at the [[CUPSTea4CUPS|Tea4CUPS page]] for ideas on creating a searchable PDF with chosen embedded fonts as part of the printing system workflow.
Line 187: Line 120:
Alternatively, the PDF produced by cupsfilter or texttopdf can be post-processed with [[DebianMan:pdftocairo|pdftocairo]] to obtain a searchable PDF with a chosen embedded font: === Text Orientation ===
Line 189: Line 122:
 * '''With the [[#system|system]] text font.'''
{{{
/usr/sbin/cupsfilter input.txt | pdftocairo -pdf - out.pdf
}}}

 * '''With a [[#user|user's]] text font on stretch.'''
texttopdf handles a text file such as ''/etc/services'' by producing a [[pdftopdfandPageRotation#portrait|PDF portrait page]] with the text parallel to the short edge. If either ''landscape'' or ''orientation-requested=4'' is given as an option to texttopdf, the PDF is a [[pdftopdfandPageRotation#portrait|landscape page]] and the text is placed parallel to the long edge. The second PDF is [[pdftopdfandPageRotation#autorotate|processed by pdftopdf]] to print correctly.
Line 197: Line 125:
CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 input.txt | pdftocairo -pdf - out.pdf
lp -d <queue> /etc/services lp -d <queue> -o landscape /etc/services
     +------------+ +----------------------+
     |AAAAAAAAAAAA| |BBBBBBBBBBBBBBBBBBBBBB|
     | | | |
     | | | |
     | | +----------------------+
     | |
     | |
     +------------+
Line 199: Line 136:

You might want to look at the [[Tea4CUPS|Tea4cups page]] for ideas on creating a searchable PDF with chosen embedded fonts as part of the printing system workflow.
Line 228: Line 163:
## If this page belongs to an existing Category, add it below.
## CategorySomething | CategoryAnother

CategoryPrinter

Translation(s): none


Getting the most out of the texttopdf filter used with CUPS on Debian 9 (stretch) and later.

Font Selection and fontconfig

Printing a text file requires at least one suitable font to be available on the system. Supported font formats are TrueType (TTF), OpenType (OTF) and TrueType Collection (TTC). The font should be monospaced.

Font selection is taken care of within the fontconfig framework, documented in fonts-conf, in conjunction with pdf.utf-8, which is found in /usr/share/cups/charsets and installed by the cups-filters package. By default, pdf.utf-8 is symlinked to pdf.utf-8.simple, whose essential content is

charset utf8
0000 04FF ltor single monospace monospace:bold monospace:oblique monospace:bold:oblique
0500 05FF rtol single monospace

Note that monospace is a selector that enables fontconfig to choose a monopaced font. fontconfig will search for fonts that are registered in the monospace group and return what it considers to be the best suitable candidate that is available on the system. This could be FreeMono or DejaVuSansMono or any other monospaced font.

A preference for a particular font can be configured on a per-system basis by means of a fontconfig configuration file. A user with a font preference is also catered for.

Altering the System-wide Default Font for Printing

The cups-filters package hasn't any dependency on a specific font package but it pulls in fontconfig-config (via libfontconfig1) because it depends on it. In its turn fontconfig-config has a dependency beginning

fonts-dejavu-core | ttf-bitstream-vera | fonts-liberation | fonts-freefont...

This will normally lead to the first in the list being installed. fonts-dejavu-core has a monospaced font. Consequently, there will always be one monospaced font on the system.

The preferred way of using a chosen textttopdf_font would be to create /etc/fonts/local.conf with the contents

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
 <alias>
   <family>monospace</family>
   <prefer>
     <family>textttopdf_font</family>
   </prefer>
 </alias>
</fontconfig>

Possibilities for textttopdf_font are Liberation Mono, FreeMono, Moto Mono or Inconsolata.

User Control of the Default Printing Font

Filters such as texttopdf are always run by the printing system as a non-privileged user, typically lp, with no connection to the user's desktop. This implies that printing via cups-filters is not an option and that a user would have to execute texttopdf under user privileges to gain control of font selection.

The conversion of a text file to a PDF is done with with

CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 < <text_file> > out.pdf

CHARSET=utf-8 tells the filter to consult /usr/share/cups/charsets/pdf.utf-8, where it will find the request for a monospace font.

fontconfig will now be capable of using what a user wants from the monospace selector when the xml snippet above is put into $HOME/.config/fontconfig/fonts.conf. The user's fonts.conf will take precedence over the system's /etc/fonts/local.conf because texttopdf is being run by an ordinary user.

The two-step production of a PDF and sending it to the printing system can be automated with Tea4CUPS

The Case for FreeMono

The choice of a font for printing text files may very well be based on the look of the font. This is a reasonable criterion. However, there are other factors such as the range of glyphs in the font and, by implication, the language(s) used in the text.

GNU FreeMono has veryfont good coverage of glyphs and caters for characters from many Unicode blocks. It can be compared with other monospaced fonts by altering the the system or user-chosen font and producing and viewing a PDF of UTF-8-demo.txt using (respectively) cupsfilter or texttopdf:

  • Produce a PDF with

/usr/sbin/cupsfilter UTF-8-demo.txt > out.pdf
CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 UTF-8-demo.txt > out.pdf
  • Check the font used with

pdffonts out.pdf
  • View the PDF with

your_favourite_pdf_viewer out.pdf

Using texttpdf to Produce PDFs

The primary purpose of cups-filters is to process files (in conjunction with CUPS) to produce an end product of toner or ink being put on a medium such as paper. However, it didn't take long for people to realise the CUPS+cupsfilters combination gave a way of capturing a PDF file without sending it to a printer. This opens up a way of archiving text files and scripting batch production of PDFs from them using something that is probably on the system already.

Either of the two commands given previously may be used to produce a PDF. An issue that may arise is that the PDFs do not have searchable or extractable test. This is a consequence of the design of the texttopdf filter. If it matters, the situation may be rectified with some post-processing.

/usr/sbin/cupsfilter <input.txt> | pdftocairo -pdf - out.pdf

CHARSET=utf-8 /usr/lib/cups/filter/texttopdf 1 1 1 1 1 <input.txt> | pdftocairo -pdf - out.pdf

You may want to look at the Tea4CUPS page for ideas on creating a searchable PDF with chosen embedded fonts as part of the printing system workflow.

Text Orientation

texttopdf handles a text file such as /etc/services by producing a PDF portrait page with the text parallel to the short edge. If either landscape or orientation-requested=4 is given as an option to texttopdf, the PDF is a landscape page and the text is placed parallel to the long edge. The second PDF is processed by pdftopdf to print correctly.

lp -d <queue> /etc/services      lp -d <queue> -o landscape /etc/services
     +------------+                      +----------------------+
     |AAAAAAAAAAAA|                      |BBBBBBBBBBBBBBBBBBBBBB|
     |            |                      |                      |
     |            |                      |                      |
     |            |                      +----------------------+  
     |            |
     |            |
     +------------+ 

Credits

The texttopdf filter is based on CUPS' texttops filter and written by Tobias Hoffmann <smilingthax SPAMFREE AT googlemail DOT com> under the auspices of the OpenPrinting group. Significant work has been done in bug #662660 and bug #663070 by Fabian Greffrath <fabian SPAMFREE AT debian DOT org> to integrate the use of fontconfig into the filter.

See Also


CategoryPrinter