Save web pages (screenshots of webs) in PDF with one command

Sometimes we want to save something from a website in PDF on our PC, for this there is the tool: wkhtmltopdf

That is, through a command we can save X page in .pdf, but first let's install the application:

In Debian, Ubuntu or derivatives, just install wkhtmltopdf:

sudo apt-get install wkhtmltopdf

It will install its dependencies such as webkit and some qt libraries, but they are libraries and nothing strange 😉

In other distros I imagine that the package must be named the same.

Once we have it installed, using it is really simple, for example we are going to save www.google.com:

wkhtmltopdf www.google.com google.pdf

That is, we pass the URL of what we want to save as the first parameter, and the name and .pdf of the final file we want as the second parameter.

I leave a screenshot of how the .pdf is shown to me:

 

And here is the .pdf:

Download file Google.pdf

If you want to know more options of this application, without a doubt you should read the help (man wkhtmltopdf) since the list is somewhat extensive, it includes options to use a proxy, use cookies, custom header, site encoding, etc.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

22 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Juan Ignacio said

    Very good tool! Thanks for the information!
    It hurts the difficult name to remember che ...

    1.    KZKG ^ Gaara said

      Thank you for your comment 🙂
      About the name ... well, we can always make an alias 😉 - » https://blog.desdelinux.net/tag/alias/

  2.   FernandoRJ said

    An easy way to get an offline website through printfriendly.com

  3.   dmacias said

    I used pdfmyurl a long time ago, but I have tried this one and on arch it doesn't work for me, it pretends to download it and then it's not there. When I have more time I see that surely I am missing any library or something since I have it just installed.
    Greetings and good job what you do 🙂

  4.   krel said

    Host, I like your post KG **** but this is a great way to waste time complicating life and the rest that someone else puts it….
    On the one hand, there are options like Fernando's and I propose a better CleanSave in Chrome.
    Then better than all that: Nixnote with Evernote's Clearly browser plugin.
    The only way I see more less this is valid when we are working without an interface, otherwise. … .Kk

    1.    KZKG ^ Gaara said

      In case you do not want to install a plugin in the browser, or simply do not want to open the browser, this alternative is the best I found.

      In Linux diversity is undoubtedly an advantage, there are those who like to use addons for applications and others simply like independent applications for different tasks.

      I limit myself to sharing all my knowledge, you (the users) choose the method that you like the most 😉

      Thanks for your comment.

      1.    krel said

        The tutorial seems totally valid to me but I don't know, lately I have become comfortable and I only touch the terminal for the essentials. I'm also going to put this post in my Nixnote, XD
        regards

        1.    m said

          If you need to use this tool in a script or automate conversions of web pages to PDF, you put Evernote, Chromium and all your paraphernalia where the Sun never shines.

          Besides, what is complicated about this? Damn, but it's as easy as copying the URI, pasting it on the command line (too handy for those of us who use Yakuake) and adding the filename.

          1.    krel said

            Sorry !!!!!!!!!!! Each one looks for the simplest but I already tell you, not even what you count is efficient in time or resources. With that I tell you everything, to do something that is done with a click, you need at least two operations.
            1 Call bash
            The command that as it was?
            If you remember, go to step 3, if not step 2.
            2 Look for the command in the notes (more time lostoooooooooo)
            3 Launch the program. (AHhhh, typing is slower than clicking)

            In my case, just one click, and I have a better organization, and when I want to see something I sync Nixnote. But if I don't want Nixnote, CleanSave by itself is better, in fact I can already send it directly to Dropbox, and so on. Also, in all cases I can have them synchronized on several computers. etc etc etc

            Then, that script makes a replica of the page, while with what I comment you only copy what interests you.
            Therefore, do not bite your tail. I move on because I would end up making fun of it.
            regards

          2.    m said

            “Even what you count is efficient in time or resources. With that I tell you everything, to do something that is done with a click, you need at least two operations.
            1 Call bash
            The command that as it was?
            If you remember, go to step 3, if not step 2.
            2 Look for the command in the notes (more time lostoooooooooo)
            3 Launch the program. (AHhhh, typing is slower than clicking »

            Ahhh look what I've come to find out, thank you!
            :p
            So typing is slower than using the mouse !? You should advise the NVidia engineers as they use Emacs and Vim:
            http://www.phoronix.com/scan.php?page=article&item=nvidia_qa_linux&num=1
            (But how silly are these guys, using Emacs or Vim for the thousands of lines of code they write, review and test per day, if they will be useless ... ah, no, stop ... they are engineers with Ph. D.! Mmm ... FUCK !)

            Or maybe you could explain to the thousands of system administrators who deal with Vim and Emacs every day from a console the benefits of using and abusing the mouse?

            «1 Call bash
            The command that as it was?
            If you remember, go to step 3, if not step 2. »
            You're trolling me, right? Or have you just never opened a console in your life?

            «2 Look for the command in the notes (more time lostoooooooooo)»
            More trolling?

            «3 Launch the program. (AHhhh, typing is slower than clicking »
            Even more trolling !!!! ??? Or is it that you just have no idea what you're talking about?

            So don't bite your tail. I move on because I would end up making fun of it. "
            You have just shown that you don't have that much fabric, calm down.

          3.    krel said

            Hahaha, I tell you, things must be known to carry them with dignity, I am totally opposed to: listen to music on the terminal, tweet on the terminal, torrent on the terminal, etc. etc. All that seems to me to be the stuff of children who have no other more useful way of wasting time.

            As for the clicks on this topic, you have released an idiocy that you do not believe it. Time this operation and you will see that what you say does not hold.

            But hey, since you have no identity and you see that Nvidia do one thing, and since they are what you want to be when you grow up (I wanted to be an astronaut), you will always be an imitator.

            The terminal is useful but it is not a panacea. In fact I prefer distros like opensuse that with YaST I hardly have to touch it for administrative tasks. It will be that I will already be getting older.

            Otherwise you just make it clear that you are a "follower" who tries to show what you are not and that you think that using the terminal for any nonsense makes you different. Well, different if it does but in a negative sense. Ahh, you only know how to say troll, there you are still a second-rate follower.

            Nothing kid, that was fun. Regards.

      2.    Edward said

        If you are very Lazy or you just like to automate things to the maximum, surely you are addicted to the terminal, it is not that it is more or less complicated, it depends on what you want to do. If you want and you have time, you can right-click, if not you make a script that looks for the websites that interest the subscribers of your page, converts those websites into pdf, compresses them and sends them by mail, or you can do what you can just imagine with the knowledge and the terminal.

        Greetings and thanks for the tip.

    2.    Max Steel said

      Well I think they all get more complicated ... As simple as a ctrl + p to print and select in PDF, and voila ..

      1.    Andrew said

        juapushhhh for everyone above 😛

  5.   Dragnell said

    Excellent tool together wget has helped me to bring the documentation of some sites to pdf. Cheers

  6.   Arriaga said

    on archlinux it doesn't work.
    first it gave me a gnome-keyring error then with sudo it doesn't give me an error but it doesn't create the pdf.

  7.   rainbow_fly said

    Someone help me? xD does not work well
    rain @ Ubuntu-12: ~ / Desktop $ wkhtmltopdf https://blog.desdelinux.net/guarda-paginas-webs-screenshots-de-webs-en-pdf-con-un-comando/ test.pdf
    Loading page (1/2)
    QFont :: setPixelSize: Pixel size] 88%
    WARNING: gnome-keyring :: couldn't connect to: / tmp / keyring-Uz7GwI / pkcs11: The file or directory does not exist
    Printing pages (2/2)
    QFont :: setPixelSize: Pixel size <= 0 (0)
    Done

    And there is a file that is impossible to open

  8.   Daniel Rojas said

    Very good for when we don't feel like opening the browser 😛

  9.   frame said

    In debian both with iceweasel / firefox and with chromium / chrome you can print any web page in pdf. just go to: print, then choose the option "print to file" pdf output format. The interesting thing about this option is that we can also make certain configurations of how the page will be printed in pdf

    1.    Baron ashler said

      The truth is that you are right, it is available in chromium 😀 even so I will consider this post. Thank you

  10.   Diego said

    Hey.

    CTRL + P is not better, and you are given the option to print to a file, you name the document you want and that's it.

  11.   Joan said

    You need to publish where to find the finished PDF to round off your article ...