Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
I know nothing about emacs, but have you tried it without the dashes, eg "Consolas Bold"? –  Jared Harley Apr 13 '11 at 8:52
    
@Jared Yes. Huge bug =) –  Clément Apr 13 '11 at 9:22
add comment

2 Answers

up vote 0 down vote accepted

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.

share|improve this answer
    
Thanks for your answer! However, Emacs is currently the only program to implement syntax-highlighting for my language, hence my desire to print to pdf from it. I've try installing font in ghostscript, but I couldn't figure how to do so. Could you give me a few details? All that Emacs do is generate postscript, and then call ps2pdf from the ghostscipt package. –  Clément Apr 13 '11 at 10:19
add comment

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!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.