3

I'm customizing Emacs to print to PostScript with custom faces. I've found this reference, which explains how to add Helvetica. To emacs ps-print.

I'm trying to use Consolas, so I used the following code:

;; Add Consolas to supported printing fonts.
(require 'ps-print)
(setq ps-font-info-database
    (append
        '((Consolas
            (fonts  (normal      . "Consolas")
                    (bold        . "Consolas-Bold")
                    (italic      . "Consolas-Italic")
                    (bold-italic . "Consolas-BoldItalic"))
            (size . 10.0)
            (line-height . 10.48)
            (space-width . 5.51719)
            (avg-char-width . 5.51719)))
        ps-font-info-database))

The document prints without errors, but it uses default fonts instead of Consolas. When I the convert the PostScript document to PDF, and then copy text from the PDF file to OpenOffice, I do get Consolas, but in the PDF the text displays as something like Courier.

Which names should I use? Is Consolas-bold wrong? I couldn't find anything on the web about this problem.

Clément
  • 950

3 Answers3

2

4 years later, I think the best way to achieve this is to do the printing from outside Emacs.

Instead of generating a .ps from Emacs, generate an html copy of the buffer first (using htmlfontify-buffer), then print from your favourite web browser (M-x browse-url-of-file).

Clément
  • 950
2

This worked for me (Emacs 23.3.1 / Windows 7 64x) [still wrestling with color output]:

;; Printing
(require 'ps-print)
(setq printer-name '"USB001")
(setq ps-printer-name t)
(setq ps-lpr-command "g:/dev/bin/ghostscript/gs9.04/bin/gswin64c.exe")
(setq ps-lpr-switches '("-q" "-dNOPAUSE" "-dBATCH"
                        "-sDEVICE=mswinpr2"))
;; Add Consolas 
(setq ps-font-info-database
      (append
       '((Consolas
          (fonts (normal      . "Consolas")
                 (bold        . "Consolas-Bold")
                 (italic      . "Consolas-Italic")
                 (bold-italic . "Consolas-Bold-Italic"))
          (size           . 11.0)
          (line-height    . 13.0)
          (space-width    . 6.04688)
          (avg-char-width . 6.04688)))
       ps-font-info-database))
(setq ps-font-family 'Consolas)
(setq ps-font-size 11)

;; Print in color
(setq-default ps-print-color-p t)

;; Page layout: Header [file-name     2011-12-05]
;;              Footer [                     n/m]

;; Header
(setq ps-header-lines 1)
(setq ps-header-font-size 11)
(setq ps-header-title-font-size 11)
(setq ps-header-font-family 'Consolas)
(setq ps-right-header '(ps-time-stamp-yyyy-mm-dd))
(setq ps-print-header-frame nil)        ; no box top

;; Footer
(setq ps-footer-lines 1)
(setq ps-footer-font-size 11)
(setq ps-footer-font-family 'Consolas)
(setq ps-print-footer t)
(setq ps-left-footer nil)
(setq ps-right-footer (list "/pagenumberstring load"))
(setq ps-footer-offset .50)
(setq ps-footer-line-pad .50)
(setq ps-print-footer-frame nil)        ; no box bottom

;; Keystroke to print
(global-set-key (kbd "C-|")  'ps-print-buffer-with-faces)

Good luck!

23emacs
  • 21
0

The reason that the code above would work for Helvetica is that Helvetica is one of the standard fonts in PostScript. You usually have three fonts that are always available in PostScript - Times Roman, Helvetica and Courier.

Adding new fonts depends on the software. Some will download a PostScript Type 1 font to the target device (TTF fonts get converted before downloading usually), but that depends on having a target device that can accept fonts. The other way is for the software to draw the document as a series of vectors.

PDF uses a similar system to the first way in that it can embed the font (or a subset of it to save space) into the document.

I don't quite know how to do it in Emacs, but I would expect you would need to tell Emacs where the font is located and how to embed it - maybe even pre-convert it to Postscript Type 1.

TBH, you'd be best off investigating LaTeX for PostScript / PDF printing.

Majenko
  • 32,964