Rook
Rook

Reputation: 62538

Central european characters in Vim and printing (PDFing) them out

I'm trying to persuade GVim 7.3 to correctly print (:hardcopy) central european characters (šđčćž ŠĐČĆŽ) to PDF. Settings which I believe to be relevant

set encoding=utf8
set fileencodings=ucs-bom,utf8,cp1250,latin1
set guifont=Consolas:h9:cEASTEUROPE
set printfont=Consolas:h9:cEASTEUROPE

After changing the encoding to cp1250 (and writing them again, since the change in encoding screws the up) they print out correctly.

Now, I thought utf-8 was a much bigger and more complete set than cp1250. Why after that change they correctly print out, or more importantly, why I can't use them in combination with enc=utf-8(which I normally use because of abundance of other characters, not normally accessible)?

enter image description here

enter image description here


:version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Oct 27 2010 17:59:02)
MS-Windows 32-bit GUI version with OLE support
Included patches: 1-46
Compiled by Bram@KIBAALE
Big version with GUI.  Features included (+) or not (-):
+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent +clientserver +clipboard +cmdline_compl
+cmdline_hist +cmdline_info +comments +conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con_gui +diff +digraphs -dnd
-ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +float +folding -footer +gettext/dyn
-hangul_input +iconv/dyn +insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent +listcmds +localmap -lua +menu
 +mksession +modify_fname +mouse +mouseshape +multi_byte_ime/dyn +multi_lang -mzscheme +netbeans_intg +ole -osfiletype
+path_extra +perl/dyn +persistent_undo -postscript +printer -profile +python/dyn +python3/dyn +quickfix +reltime +rightleft
+ruby/dyn +scrollbind +signs +smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary +tag_old_static
-tag_any_white +tcl/dyn -tgetent -termresponse +textobjects +title +toolbar +user_commands +vertsplit +virtualedit +visual
+visualextra +viminfo +vreplace +wildignore +wildmenu +windows +writebackup -xfontset -xim -xterm_save +xpm_w32
   system vimrc file: "$VIM\vimrc"
     user vimrc file: "$HOME\_vimrc"
 2nd user vimrc file: "$VIM\_vimrc"
      user exrc file: "$HOME\_exrc"
  2nd user exrc file: "$VIM\_exrc"
  system gvimrc file: "$VIM\gvimrc"
    user gvimrc file: "$HOME\_gvimrc"
2nd user gvimrc file: "$VIM\_gvimrc"
    system menu file: "$VIMRUNTIME\menu.vim"
Compilation: cl -c /W3 /nologo  -I. -Iproto -DHAVE_PATHDEF -DWIN32   -DFEAT_CSCOPE -DFEAT_NETBEANS_INTG   -DFEAT_XPM_W32   -DWINVE
R=0x0400 -D_WIN32_WINNT=0x0400  /Fo.\ObjGOLYHTR/ /Ox /GL -DNDEBUG  /Zl /MT -DFEAT_OLE -DFEAT_MBYTE_IME -DDYNAMIC_IME -DFEAT_GUI_W3
2 -DDYNAMIC_ICONV -DDYNAMIC_GETTEXT -DFEAT_TCL -DDYNAMIC_TCL -DDYNAMIC_TCL_DLL=\"tcl83.dll\" -DDYNAMIC_TCL_VER=\"8.3\" -DFEAT_PYTH
ON -DDYNAMIC_PYTHON -DDYNAMIC_PYTHON_DLL=\"python27.dll\" -DFEAT_PYTHON3 -DDYNAMIC_PYTHON3 -DDYNAMIC_PYTHON3_DLL=\"python31.dll\"
-DFEAT_PERL -DDYNAMIC_PERL -DDYNAMIC_PERL_DLL=\"perl512.dll\" -DFEAT_RUBY -DDYNAMIC_RUBY -DDYNAMIC_RUBY_VER=191 -DDYNAMIC_RUBY_DLL
=\"msvcrt-ruby191.dll\" -DFEAT_BIG /Fd.\ObjGOLYHTR/ /Zi
Linking: link /RELEASE /nologo /subsystem:windows /LTCG:STATUS oldnames.lib kernel32.lib advapi32.lib shell32.lib gdi32.lib  comdl
g32.lib ole32.lib uuid.lib /machine:i386 /nodefaultlib gdi32.lib version.lib   winspool.lib comctl32.lib advapi32.lib shell32.lib
 /machine:i386 /nodefaultlib libcmt.lib oleaut32.lib  user32.lib      /nodefaultlib:python27.lib /nodefaultlib:python31.lib   e:\t
cl\lib\tclstub83.lib WSock32.lib e:\xpm\lib\libXpm.lib /PDB:gvim.pdb -debug
Press ENTER or type command to continue

When typed and saved with enc=utf8:

0000000: c5a1 2020 2020 c5a0 0d0a c491 2020 2020  ..    ......    
0000010: c490 0d0a c48d 2020 2020 c48c 0d0a c487  ......    ......
0000020: 2020 2020 c486 0d0a c5be 2020 2020 c5bd      ......    ..
0000030: 0d0a 0d0a 0d0a                           ......

... with enc=cp1250

0000000: 9a20 2020 208a 0d0a f020 2020 20d0 0d0a  .    ....    ...
0000010: e820 2020 20c8 0d0a e620 2020 20c6 0d0a  .    ....    ...
0000020: 9e20 2020 208e 0d0a 0d0a                 .    .....

Upvotes: 8

Views: 1314

Answers (3)

anonymous8725
anonymous8725

Reputation: 1

I'm using the very same version of Vim as the OP. My magic incantation for printing that stuff is:

:se fenc=cp1252
:w
:e ++enc=cp1252
:se enc=cp1252
:se fenc=cp1252
:se penc=cp1252
:hardcopy

Use a codepage that's applicable for you. The first three lines (i.e. the saving and reloading) may not be needed, but it should ensure the text is actually converted (instead of the buffer just being reinterpreted). AFAICT enc and penc need to be set, fenc is just CYA. Then use :hardcopy whichever way you want.

Remember to change the relevant encodings (enc, fenc) back and re-save if you prefer to store the file in some other codepage (latin1, utf-8, etc). The procedure there being :se fenc and :w. You may then possibly continue with :e (possibly with added ++enc=xxx) and :se enc=xxx to check it out and to make sure you're working on a copy using your preferred codepage, plus another round of :se fenc=xxx and :w when you're done just to be on the safe side.

It's all a bit redundant, but that's a way to be certain Vim is on the same page with you. As you've noticed there's something funny about the codepage handling on Windows (at least WRT printing), so I don't necessarily trust it to do all the right things purely internally. I just force it to change the actual byte representation and then make sure it's using that.

Upvotes: 0

user1749757
user1749757

Reputation: 1

Install paps, it works fine through the command in vim "!paps < % > out.ps", then you can convert using ps2pdf to pdf.

If on a mac, use 'brew install paps'

Upvotes: 0

David Pope
David Pope

Reputation: 6587

Here's a very nice thread discussing something very close to this. The conclusion at the end is, "it doesn't work, don't do that" -- just save the file in UTF-8 and print it with something else, e.g. notepad.

This works on my system:

:silent !notepad /pt "%" "PDFLite"

where PDFLite is the name of my print-to-PDF printer.

Edit: I'm using the "utf-8" encoding in vim.

Upvotes: 1

Related Questions