How can I print from Vim to pdf?How can I enable fast printing from Firefox/CUPS using Dot-Matrix-Printerprinting pdf with lpr results in different output than printing GUIHow can I set 'Print to File' as my default printing option?Unable to print PDF correctlymessed up characters in PDF printed from Ubuntu 12.10Why won't .pdf files containing transparent elements print correctly?Print margins on Firefox (also with Print Edit)?Where is my PDF printer printing my documents?How to send a zip file containing bunch of pdf's directly to a printer?

Recommendation for a fixed-step ODE solver?

Prospective employer asking for my current pay slip during interview

What should be done if I suspect a player is using weighted dice?

Can two moons have intersecting orbits yet be guaranteed not to collide?

Why do airlines usually ask you how much purchase you have made?

When can "qui" mean "how"?

Pearson vs Spearman vs Kendall

Did the Windows 95 screensavers use hardware acceleration APIs?

Can I make leading exclamation points be ignored in the terminal? (I type them by instinct due to ipython)

Why did Sofia do this to John's bottle?

What movie or fandom is this jewelry from?

Why do Russian names transliterated into English have unpronounceable 'k's before 'h's (e.g. 'Mikhail' instead of just 'Mihail')?

What's the best way to keep cover of a pan slightly opened?

How can I get a ride in the jump seat as a non-professional pilot?

How do electric hot water heaters explode and what can be done to prevent that from happening?

How does an immortal vampire king hide his vampirism and immortality?

SQL Server chooses unselective index

Collection of open problems in Partial differential equations

Can socialism and capitalism coexist in the same country?

A single word for "not allowed to be changed" or "must be this way"

Is 人孔 from English?

Brake disc and pads corrosion, do they need replacement?

Find the used hard disk data and solve disk pressure

Why do cargo airlines frequently choose passenger aircraft rather than aircraft designed specifically for cargo?



How can I print from Vim to pdf?


How can I enable fast printing from Firefox/CUPS using Dot-Matrix-Printerprinting pdf with lpr results in different output than printing GUIHow can I set 'Print to File' as my default printing option?Unable to print PDF correctlymessed up characters in PDF printed from Ubuntu 12.10Why won't .pdf files containing transparent elements print correctly?Print margins on Firefox (also with Print Edit)?Where is my PDF printer printing my documents?How to send a zip file containing bunch of pdf's directly to a printer?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









10


















I would have thought this is rather simple, but I don't get it done: I use gVim and would like to get the text as a pdf-file. In other applications like Firefox the print-dialog shows me available printers and I can choose to print directly to a pdf-file. However in Vim there is no such dialog and the file is just sent to the standard printer of the system.



I tried the following:



  • I'm not able to make the "print-to-pdf"-thing to my standard way of printing via the printer window of Ubuntu.


  • :ha > file converts my file to a .ps-file. That's nice, but .pdf would be nicer...









share|improve this question

























  • Not an answer, but you can use ps2pdf command-line tool afterwards, with the poscript file as input.

    – kebs
    Dec 4 '15 at 18:05


















10


















I would have thought this is rather simple, but I don't get it done: I use gVim and would like to get the text as a pdf-file. In other applications like Firefox the print-dialog shows me available printers and I can choose to print directly to a pdf-file. However in Vim there is no such dialog and the file is just sent to the standard printer of the system.



I tried the following:



  • I'm not able to make the "print-to-pdf"-thing to my standard way of printing via the printer window of Ubuntu.


  • :ha > file converts my file to a .ps-file. That's nice, but .pdf would be nicer...









share|improve this question

























  • Not an answer, but you can use ps2pdf command-line tool afterwards, with the poscript file as input.

    – kebs
    Dec 4 '15 at 18:05














10













10









10


5






I would have thought this is rather simple, but I don't get it done: I use gVim and would like to get the text as a pdf-file. In other applications like Firefox the print-dialog shows me available printers and I can choose to print directly to a pdf-file. However in Vim there is no such dialog and the file is just sent to the standard printer of the system.



I tried the following:



  • I'm not able to make the "print-to-pdf"-thing to my standard way of printing via the printer window of Ubuntu.


  • :ha > file converts my file to a .ps-file. That's nice, but .pdf would be nicer...









share|improve this question














I would have thought this is rather simple, but I don't get it done: I use gVim and would like to get the text as a pdf-file. In other applications like Firefox the print-dialog shows me available printers and I can choose to print directly to a pdf-file. However in Vim there is no such dialog and the file is just sent to the standard printer of the system.



I tried the following:



  • I'm not able to make the "print-to-pdf"-thing to my standard way of printing via the printer window of Ubuntu.


  • :ha > file converts my file to a .ps-file. That's nice, but .pdf would be nicer...






printing pdf vim






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 4 '15 at 17:58









caligulacaligula

1011 gold badge1 silver badge4 bronze badges




1011 gold badge1 silver badge4 bronze badges















  • Not an answer, but you can use ps2pdf command-line tool afterwards, with the poscript file as input.

    – kebs
    Dec 4 '15 at 18:05


















  • Not an answer, but you can use ps2pdf command-line tool afterwards, with the poscript file as input.

    – kebs
    Dec 4 '15 at 18:05

















Not an answer, but you can use ps2pdf command-line tool afterwards, with the poscript file as input.

– kebs
Dec 4 '15 at 18:05






Not an answer, but you can use ps2pdf command-line tool afterwards, with the poscript file as input.

– kebs
Dec 4 '15 at 18:05











2 Answers
2






active

oldest

votes


















17



















Vim will not show you the print dialog box. Instead, you can print to a PS file, open it in a PS viewer and print from there.



To print to a PS file from Vim:



:hardcopy > myfile.ps


You can also convert ps to pdf using ps2pdf:



ps2pdf myfile.ps





share|improve this answer






















  • 1





    The first proposal means just changing the file extension... The second one might work in a mapping or something like that, I will have to do some more research to get that done... Thanks so far...

    – caligula
    Dec 4 '15 at 18:13






  • 1





    It is as easy as changing an extension ;)

    – Ron
    Dec 4 '15 at 18:15






  • 1





    This is awesome, definitely didn't know this was a thing! Can you get multiple files into a single document?

    – Ben Kushigian
    Mar 30 '17 at 17:20






  • 2





    (cygwin user) :ha > file.pdf did not create a valid pdf file. Combining it with ps2dpf did work but gives me white background. I'm happiest with :TOhtml file.html and then printing this html file to pdf

    – lucidbrot
    May 10 '17 at 6:35











  • I used a variation of this command today: :1,50 hardcopy, it didn't create a file, just printed from lines 1 to 50.

    – Dr Beco
    Mar 8 at 21:39



















6



















Building on what others have already stated...



You can use the following single-line vim command to create a .pdf file:



:hardcopy > %.ps | !ps2pdf %.ps && rm %.ps


Note:



  • The % is shorthand for the current filename, so HelloWorld.C will print to HelloWorld.C.pdf

  • If you want to also retain the intermediate .ps file, simply omit the && rm %.ps, obtaining:
    :hardcopy > %.ps | !ps2pdf %.ps

Additionally, to change the rendered font, set the printerfont before executing the hardcopy command. For example, to select Courier 8:



:set printerfont=Courier:h8


Putting it all together, I opted to put the following in my .vimrc file so that I can simply execute the :HardcopyPdf command (which can also operate on a selected range within a file):



set printfont=Courier:h8 "select the font to use when printing
command! -range=% HardcopyPdf <line1>,<line2> hardcopy > %.ps | !ps2pdf %.ps && rm %.ps && echo 'Created: %.pdf'





share|improve this answer




























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f705973%2fhow-can-i-print-from-vim-to-pdf%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown


























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    17



















    Vim will not show you the print dialog box. Instead, you can print to a PS file, open it in a PS viewer and print from there.



    To print to a PS file from Vim:



    :hardcopy > myfile.ps


    You can also convert ps to pdf using ps2pdf:



    ps2pdf myfile.ps





    share|improve this answer






















    • 1





      The first proposal means just changing the file extension... The second one might work in a mapping or something like that, I will have to do some more research to get that done... Thanks so far...

      – caligula
      Dec 4 '15 at 18:13






    • 1





      It is as easy as changing an extension ;)

      – Ron
      Dec 4 '15 at 18:15






    • 1





      This is awesome, definitely didn't know this was a thing! Can you get multiple files into a single document?

      – Ben Kushigian
      Mar 30 '17 at 17:20






    • 2





      (cygwin user) :ha > file.pdf did not create a valid pdf file. Combining it with ps2dpf did work but gives me white background. I'm happiest with :TOhtml file.html and then printing this html file to pdf

      – lucidbrot
      May 10 '17 at 6:35











    • I used a variation of this command today: :1,50 hardcopy, it didn't create a file, just printed from lines 1 to 50.

      – Dr Beco
      Mar 8 at 21:39
















    17



















    Vim will not show you the print dialog box. Instead, you can print to a PS file, open it in a PS viewer and print from there.



    To print to a PS file from Vim:



    :hardcopy > myfile.ps


    You can also convert ps to pdf using ps2pdf:



    ps2pdf myfile.ps





    share|improve this answer






















    • 1





      The first proposal means just changing the file extension... The second one might work in a mapping or something like that, I will have to do some more research to get that done... Thanks so far...

      – caligula
      Dec 4 '15 at 18:13






    • 1





      It is as easy as changing an extension ;)

      – Ron
      Dec 4 '15 at 18:15






    • 1





      This is awesome, definitely didn't know this was a thing! Can you get multiple files into a single document?

      – Ben Kushigian
      Mar 30 '17 at 17:20






    • 2





      (cygwin user) :ha > file.pdf did not create a valid pdf file. Combining it with ps2dpf did work but gives me white background. I'm happiest with :TOhtml file.html and then printing this html file to pdf

      – lucidbrot
      May 10 '17 at 6:35











    • I used a variation of this command today: :1,50 hardcopy, it didn't create a file, just printed from lines 1 to 50.

      – Dr Beco
      Mar 8 at 21:39














    17















    17











    17









    Vim will not show you the print dialog box. Instead, you can print to a PS file, open it in a PS viewer and print from there.



    To print to a PS file from Vim:



    :hardcopy > myfile.ps


    You can also convert ps to pdf using ps2pdf:



    ps2pdf myfile.ps





    share|improve this answer
















    Vim will not show you the print dialog box. Instead, you can print to a PS file, open it in a PS viewer and print from there.



    To print to a PS file from Vim:



    :hardcopy > myfile.ps


    You can also convert ps to pdf using ps2pdf:



    ps2pdf myfile.ps






    share|improve this answer















    share|improve this answer




    share|improve this answer








    edited Oct 8 '18 at 19:36









    Lasall

    2,9434 gold badges21 silver badges32 bronze badges




    2,9434 gold badges21 silver badges32 bronze badges










    answered Dec 4 '15 at 18:06









    RonRon

    16.3k4 gold badges46 silver badges60 bronze badges




    16.3k4 gold badges46 silver badges60 bronze badges










    • 1





      The first proposal means just changing the file extension... The second one might work in a mapping or something like that, I will have to do some more research to get that done... Thanks so far...

      – caligula
      Dec 4 '15 at 18:13






    • 1





      It is as easy as changing an extension ;)

      – Ron
      Dec 4 '15 at 18:15






    • 1





      This is awesome, definitely didn't know this was a thing! Can you get multiple files into a single document?

      – Ben Kushigian
      Mar 30 '17 at 17:20






    • 2





      (cygwin user) :ha > file.pdf did not create a valid pdf file. Combining it with ps2dpf did work but gives me white background. I'm happiest with :TOhtml file.html and then printing this html file to pdf

      – lucidbrot
      May 10 '17 at 6:35











    • I used a variation of this command today: :1,50 hardcopy, it didn't create a file, just printed from lines 1 to 50.

      – Dr Beco
      Mar 8 at 21:39













    • 1





      The first proposal means just changing the file extension... The second one might work in a mapping or something like that, I will have to do some more research to get that done... Thanks so far...

      – caligula
      Dec 4 '15 at 18:13






    • 1





      It is as easy as changing an extension ;)

      – Ron
      Dec 4 '15 at 18:15






    • 1





      This is awesome, definitely didn't know this was a thing! Can you get multiple files into a single document?

      – Ben Kushigian
      Mar 30 '17 at 17:20






    • 2





      (cygwin user) :ha > file.pdf did not create a valid pdf file. Combining it with ps2dpf did work but gives me white background. I'm happiest with :TOhtml file.html and then printing this html file to pdf

      – lucidbrot
      May 10 '17 at 6:35











    • I used a variation of this command today: :1,50 hardcopy, it didn't create a file, just printed from lines 1 to 50.

      – Dr Beco
      Mar 8 at 21:39








    1




    1





    The first proposal means just changing the file extension... The second one might work in a mapping or something like that, I will have to do some more research to get that done... Thanks so far...

    – caligula
    Dec 4 '15 at 18:13





    The first proposal means just changing the file extension... The second one might work in a mapping or something like that, I will have to do some more research to get that done... Thanks so far...

    – caligula
    Dec 4 '15 at 18:13




    1




    1





    It is as easy as changing an extension ;)

    – Ron
    Dec 4 '15 at 18:15





    It is as easy as changing an extension ;)

    – Ron
    Dec 4 '15 at 18:15




    1




    1





    This is awesome, definitely didn't know this was a thing! Can you get multiple files into a single document?

    – Ben Kushigian
    Mar 30 '17 at 17:20





    This is awesome, definitely didn't know this was a thing! Can you get multiple files into a single document?

    – Ben Kushigian
    Mar 30 '17 at 17:20




    2




    2





    (cygwin user) :ha > file.pdf did not create a valid pdf file. Combining it with ps2dpf did work but gives me white background. I'm happiest with :TOhtml file.html and then printing this html file to pdf

    – lucidbrot
    May 10 '17 at 6:35





    (cygwin user) :ha > file.pdf did not create a valid pdf file. Combining it with ps2dpf did work but gives me white background. I'm happiest with :TOhtml file.html and then printing this html file to pdf

    – lucidbrot
    May 10 '17 at 6:35













    I used a variation of this command today: :1,50 hardcopy, it didn't create a file, just printed from lines 1 to 50.

    – Dr Beco
    Mar 8 at 21:39






    I used a variation of this command today: :1,50 hardcopy, it didn't create a file, just printed from lines 1 to 50.

    – Dr Beco
    Mar 8 at 21:39














    6



















    Building on what others have already stated...



    You can use the following single-line vim command to create a .pdf file:



    :hardcopy > %.ps | !ps2pdf %.ps && rm %.ps


    Note:



    • The % is shorthand for the current filename, so HelloWorld.C will print to HelloWorld.C.pdf

    • If you want to also retain the intermediate .ps file, simply omit the && rm %.ps, obtaining:
      :hardcopy > %.ps | !ps2pdf %.ps

    Additionally, to change the rendered font, set the printerfont before executing the hardcopy command. For example, to select Courier 8:



    :set printerfont=Courier:h8


    Putting it all together, I opted to put the following in my .vimrc file so that I can simply execute the :HardcopyPdf command (which can also operate on a selected range within a file):



    set printfont=Courier:h8 "select the font to use when printing
    command! -range=% HardcopyPdf <line1>,<line2> hardcopy > %.ps | !ps2pdf %.ps && rm %.ps && echo 'Created: %.pdf'





    share|improve this answer































      6



















      Building on what others have already stated...



      You can use the following single-line vim command to create a .pdf file:



      :hardcopy > %.ps | !ps2pdf %.ps && rm %.ps


      Note:



      • The % is shorthand for the current filename, so HelloWorld.C will print to HelloWorld.C.pdf

      • If you want to also retain the intermediate .ps file, simply omit the && rm %.ps, obtaining:
        :hardcopy > %.ps | !ps2pdf %.ps

      Additionally, to change the rendered font, set the printerfont before executing the hardcopy command. For example, to select Courier 8:



      :set printerfont=Courier:h8


      Putting it all together, I opted to put the following in my .vimrc file so that I can simply execute the :HardcopyPdf command (which can also operate on a selected range within a file):



      set printfont=Courier:h8 "select the font to use when printing
      command! -range=% HardcopyPdf <line1>,<line2> hardcopy > %.ps | !ps2pdf %.ps && rm %.ps && echo 'Created: %.pdf'





      share|improve this answer





























        6















        6











        6









        Building on what others have already stated...



        You can use the following single-line vim command to create a .pdf file:



        :hardcopy > %.ps | !ps2pdf %.ps && rm %.ps


        Note:



        • The % is shorthand for the current filename, so HelloWorld.C will print to HelloWorld.C.pdf

        • If you want to also retain the intermediate .ps file, simply omit the && rm %.ps, obtaining:
          :hardcopy > %.ps | !ps2pdf %.ps

        Additionally, to change the rendered font, set the printerfont before executing the hardcopy command. For example, to select Courier 8:



        :set printerfont=Courier:h8


        Putting it all together, I opted to put the following in my .vimrc file so that I can simply execute the :HardcopyPdf command (which can also operate on a selected range within a file):



        set printfont=Courier:h8 "select the font to use when printing
        command! -range=% HardcopyPdf <line1>,<line2> hardcopy > %.ps | !ps2pdf %.ps && rm %.ps && echo 'Created: %.pdf'





        share|improve this answer
















        Building on what others have already stated...



        You can use the following single-line vim command to create a .pdf file:



        :hardcopy > %.ps | !ps2pdf %.ps && rm %.ps


        Note:



        • The % is shorthand for the current filename, so HelloWorld.C will print to HelloWorld.C.pdf

        • If you want to also retain the intermediate .ps file, simply omit the && rm %.ps, obtaining:
          :hardcopy > %.ps | !ps2pdf %.ps

        Additionally, to change the rendered font, set the printerfont before executing the hardcopy command. For example, to select Courier 8:



        :set printerfont=Courier:h8


        Putting it all together, I opted to put the following in my .vimrc file so that I can simply execute the :HardcopyPdf command (which can also operate on a selected range within a file):



        set printfont=Courier:h8 "select the font to use when printing
        command! -range=% HardcopyPdf <line1>,<line2> hardcopy > %.ps | !ps2pdf %.ps && rm %.ps && echo 'Created: %.pdf'






        share|improve this answer















        share|improve this answer




        share|improve this answer








        edited Sep 27 at 18:21

























        answered Sep 27 at 17:54









        arr_seaarr_sea

        1611 silver badge3 bronze badges




        1611 silver badge3 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f705973%2fhow-can-i-print-from-vim-to-pdf%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown









            Popular posts from this blog

            Distance measures on a map of a game The 2019 Stack Overflow Developer Survey Results Are Inmin distance in a graphShortest distance path on contour plotHow to plot a tilted map?Finding points outside of a diskDelaunay link distanceAnnulus from GeoDisks: drawing a ring on a mapNegative Correlation DistanceFind distance along a path (GPS coordinates)Finding position at given distance in a GeoPathMathematics behind distance estimation using camera

            How to get a smooth, uniform ParametricPlot of a 2D Region?How to plot a complicated Region?How to exclude a region from ParametricPlotHow discretize a region placing vertices on a specific non-uniform gridHow to transform a Plot or a ParametricPlot into a RegionHow can I get a smooth plot of a bounded region?Smooth ParametricPlot3D with RegionFunction?Smooth border of a region ParametricPlotSmooth region boundarySmooth region plot from list of pointsGet minimum y of a certain x in a region

            Genealogie vun de Merowenger Vum Merowech bis zum Chilperich I. | Navigatiounsmenü