-
Notifications
You must be signed in to change notification settings - Fork 2
Generate PDF using Chrome web browser
Maxim Kim edited this page Aug 12, 2022
·
1 revision
- HTML is generated using
:make
; - then headless chrome web browser is used to generate PDF out of HTML.
Add to ~/.vim/after/ftplugin/rst.vim
:
" Silently execute OS command
func! s:OSexe(cmd) abort
if exists("$WSLENV")
lcd /mnt/c
let runner = ":silent !cmd.exe /C start"
elseif has("win32") || has("win32unix")
let runner = ':silent !start'
elseif executable('xdg-open')
let runner = ":silent !xdg-open"
elseif executable('open')
let runner = ":silent !open"
else
echohl Error
echomsg "Can't find an executor for a command!"
echohl None
return
endif
try
exe runner . ' ' . a:cmd
catch
echohl Error
echomsg v:exception
echohl None
finally
if exists("$WSLENV") | lcd - | endif
redraw!
endtry
endfunc
" NOTE: change chrome executable to what you have in your system.
command -buffer Rst2Pdf make | exe s:OSexe(printf('"%s" %s %s "%s"',
\ 'C:/Program Files/Google/Chrome/Application/chrome.exe',
\ '--headless --disable-gpu --print-to-pdf-no-header',
\ '--print-to-pdf="' . expand("%:p:r") . '.pdf"',
\ expand("%:p:r") . '.html'
\ ))
Note
The PDF would be similar to HTML version, so your CSS matters.